I/O extender


Closed Thread
Results 1 to 18 of 18

Thread: I/O extender

Hybrid View

  1. #1
    Join Date
    Oct 2004
    Location
    Italy
    Posts
    695


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mychangl View Post
    Thx Luciano for the suggestion. It really a new thing for me.
    But why both MCP23008 and MCP23016 have 3 addresses ?
    Can MCP23016 work with 16f84a ?
    Hi,

    Code:
    With three address lines you can set the address of up to eight devices.
    
    Binary / Decimal 
    ============
    000   =   0
    001   =   1
    010   =   2
    011   =   3
    100   =   4
    101   =   5
    110   =   6
    111   =   7
    The MCP23016 will work with the 16f84a.
    Use the software I2C commands of PicBasic Pro. (I2CIN and I2COUT).

    * * *

    See also this: (Basic Stamp + MCP23016).
    http://www.parallax.com/dl/docs/cols.../col/nv109.pdf

    Best regards,

    Luciano
    Last edited by Luciano; - 1st January 2008 at 15:43.

  2. #2
    Join Date
    Jun 2006
    Posts
    40


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Luciano View Post

    Use the software I2C commands of PicBasic Pro. (I2CIN and I2COUT).
    Do you mean I2Read and I2Write ?
    Sorry i am not familiar with it. However i would like to try.

    Correct me if i am wrong.
    From datasheet,
    control 0h and 1h is to read or write to the ports
    control 6h and 7h is to set port as input or output

    Given scenario 1 :
    Connect 23016 address as $01
    Assign GP0.0 to GP0.7 as input (control address is 6h)
    Assign GP1.0 to GP1.7 as output (control address is 7h)

    the code will be :
    addr var byte
    addr=01
    I2CWRITE DataPin,ClockPin,06,addr,[FF]
    I2CWRITE DataPin,ClockPin,07,addr,[00]

    Scenario 2 :
    Read the data on GP0.0 to GP0.7 and put inside Sample1

    the code will be :
    I2CREAD DataPin,ClockPin,00,addr,[Sample1]

    Scenario 3 :
    Write data 44h on GP1.0 to GP1.7

    the code will be :
    I2CWRITE DataPin,ClockPin,00,addr,[44]
    Cheers,

    mychangl
    "The Dream Is Everything"

  3. #3
    Join Date
    Oct 2004
    Location
    Italy
    Posts
    695


    Did you find this post helpful? Yes | No

    Default

    Hi,

    Yes, with PicBasic Pro use I2CREAD and I2CWRITE.
    (I2CIN and I2COUT are for the PicBasic compiler).

    Best regards,

    Luciano

  4. #4
    Join Date
    Jun 2006
    Posts
    40


    Did you find this post helpful? Yes | No

    Default

    I took longer time to try out with MCP23016 because i am still using shift register to expand the I/O. Last week i decided to try out MCP23016. However it doesn't work, after few days trial & error and change the address, i almost give up. Not sure what happen. either the code or the IC faulty because i only have one piece.

    Can someone advice ?
    Appreciate that.


    'MASTER CODE
    'This test is to check output functionality ( LED ) - Running LED
    'MCP23016 connected to address 0

    INCLUDE "modedefs.bas"


    '*****PORT Setup********************************************* *****************
    GreenLED VAR PORTA.0'O Indicator Green
    SDA VAR PORTA.1 'O Serial Data
    SCL VAR PORTA.2 'O Serial Clock
    RedLED VAR PORTA.3 'O Indicator Red

    '*****Constant************************************ ****************************
    CtrlRW1 CON 00 'Access to Set1 GP0
    CtrlRW2 CON 01 'Access to Set2 GP1
    CtrlDir1 CON 06 'Access to Set1 IODIR/0
    CtrlDir2 CON 07 'Access to Set2 IODIR/1


    '**VARIABLES************************************** ****************************
    Address VAR BYTE 'Address size
    Set1 VAR BYTE 'Place to put Data Set1
    Set2 VAR BYTE 'Place to put Data Set2

    Address=0 'Select MCP23016 address as 0

    Set1=0 'Clear Set1
    Set2=0 'Clear Set2


    '*****INITIALIZING MCP23016 All as Output**************************************
    I2CWrite SDA,SCL,CtrlDir1,Address,[00] 'Set as Output
    Pause 10 'Delay 10ms
    I2CWrite SDA,SCL,CtrlDir2,Address,[00] 'Set as Output
    Pause 10 'Delay 10ms


    Start :
    Set1=$FF 'To turn on all LEDs connected to Set1
    Set2=$FF 'TO turn ON all LEDs connected TO Set2

    I2CWrite SDA,SCL,CtrlRW1,Address,[Set1] 'Turn on the LEDs
    Pause 10 'Wait 10ms

    I2CWrite SDA,SCL,CtrlRW2,Address,[Set2] 'Turn on the LEDs
    Pause 10 'Wait 10ms


    GoTo Start
    Attached Images Attached Images
    Cheers,

    mychangl
    "The Dream Is Everything"

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mychangl View Post
    ......
    '*****INITIALIZING MCP23016 All as Output**************************************
    I2CWrite SDA,SCL,CtrlDir1,Address,[00] 'Set as Output
    Pause 10 'Delay 10ms
    I2CWrite SDA,SCL,CtrlDir2,Address,[00] 'Set as Output
    Pause 10 'Delay 10ms


    Start :
    Set1=$FF 'To turn on all LEDs connected to Set1
    Set2=$FF 'TO turn ON all LEDs connected TO Set2

    I2CWrite SDA,SCL,CtrlRW1,Address,[Set1] 'Turn on the LEDs
    Pause 10 'Wait 10ms

    I2CWrite SDA,SCL,CtrlRW2,Address,[Set2] 'Turn on the LEDs
    Pause 10 'Wait 10ms

    GoTo Start
    You could have a label after the line where to jump if an error occurs with I2C, like this:
    I2CWrite SDA,SCL,CtrlRW1,Address,[Set1], errorLabel
    ...
    errorLabel:
    LCDOUT "Error....

  6. #6
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    The MCP23008 works reliably using I2C without any additional external components, but is quite intollerant of noise on the Supply Lines, and has a habit of 'locking-up' pulling down the supply rail when this happens.

  7. #7
    Join Date
    Oct 2007
    Location
    The Netherlands
    Posts
    45


    Did you find this post helpful? Yes | No

    Default

    There is a newer version from microchip: MCP23017
    It has an internal oscillator, no external C and R needed, also the pin layout is a bit nicer. I also had problems getting a MCP23016 to work reliably, finally it worked best without any timing C connected.

  8. #8
    Join Date
    Jun 2006
    Posts
    40


    Did you find this post helpful? Yes | No

    Exclamation Please clarify...

    Thanks, i'll try MCP23017.

    I know what going on wrong with the code...

    3 things been observed :
    1. I do not put "$" to determine the address in HEX
    2. Before initializing MCP23016, it need to have short delay ( i use 50ms ) otherwise the whole program will not work.
    3. The code should be I2CWrite SDA,SCL,Address,CtrlDir1,[00] not I2CWrite SDA,SCL,CtrlDir1,Address,[00]. This is confusing because the manual shows the address come after Control, but it does not work.

    It works fine after the correction.



    I need help to evaluate my second code.
    I use GP1 as input and GP0 as output.

    However this is what happened :

    Input Triggered | Output Respond
    ----------------+-----------------
    GP1.0 | No Respond
    GP1.1 | GP0.0
    GP1.2 | GP0.1
    GP1.3 | GP0.2
    GP1.4 | GP0.3
    GP1.5 | GP0.4
    GP1.6 | GP0.5
    GP1.7 | GP0.6

    GP0.7 never respond at all.

    Anyone can help ?



    Code:
     INCLUDE "modedefs.bas"
    
    '*****STARTUP*****************************************************************
    TRISA=%00000
    TRISB=%00000000
    
    '*****PORT Setup**************************************************************
    SDA VAR PORTA.1		'O Serial Data
    SCL VAR PORTA.2		'O Serial Clock
    
    '*****Constant****************************************************************
    CtrlRW1 CON 00	'Set1
    CtrlRW2 CON 01	'Set2
    CtrlDir1 CON 06	'Set1
    CtrlDir2 CON 07	'Set2
    
    	
    '**VARIABLES******************************************************************
    Address VAR BYTE	'Address size 
    Set VAR BYTE		'Temporary place to put Data
    
    Address=$40			'Set MCP23016 address as 01
    Set=$00				'Clear Temporary Storage
    
    
    '*****INITIALIZING MCP23016 **************************************************
    	Pause 50
    	I2CWrite SDA,SCL,Address,CtrlDir1,[00]	'Set as Output
    	Pause 10								'Delay 10ms
    	I2CWrite SDA,SCL,Address,CtrlDir2,[$FF]	'Set as Input
    	Pause 10								'Delay 10ms
    
    Start :
    	I2CRead SDA,SCL,Address,CtrlRW2,[Set]	'Read from input, put in Set
    	Pause 10								'Delay 10ms
    	
    	I2CWrite SDA,SCL,Address,CtrlRW1,[Set]	'Write data into Set
    	Pause 10 								'Delay 10ms	
    	
    	GoTo Start
    Attached Images Attached Images  
    Cheers,

    mychangl
    "The Dream Is Everything"

Similar Threads

  1. PORTA Logic - Be the processor
    By Darrel Taylor in forum FAQ - Frequently Asked Questions
    Replies: 29
    Last Post: - 9th March 2009, 18:18
  2. I/O dilemma
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 6th January 2008, 16:45
  3. MCP23016 I2C serial I/O expander chip
    By GeoJoe in forum Serial
    Replies: 7
    Last Post: - 31st October 2007, 15:39
  4. 16F877 universal PCB with I/O module
    By cupajoe in forum Schematics
    Replies: 12
    Last Post: - 3rd September 2005, 13:39
  5. managing the I/O ports of the 16F84A
    By skyler_91600 in forum mel PIC BASIC
    Replies: 7
    Last Post: - 28th April 2005, 03:52

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts