I/O extender


Closed Thread
Results 1 to 18 of 18

Thread: I/O extender

  1. #1
    Join Date
    Jun 2006
    Posts
    40

    Default I/O extender

    Happy New Year to all....

    Currently, i am still using pic16f84a for my project due to smaller size and no special task require. However the only problem is limited I/O. I also plan to migrate to pic16f628 soon. I/O still a problem for me. I have gone through some article to expand I/O however it is very limited. Is there any way to increase it to 32 or 64 ? How ?

    Thx..

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    It depends on what you want to do with the I/Os.

    An RC network using the ADC or POT or RCTIME for inputs.

    Outputs could be a "matrix" http://www.mackrackit.com/mac/www/dave/LED/LEDs.html

    But shift registers are I think the best, they can be used for both in and out. Three pins from the PIC can be turned into eight outputs. Four pins can be turned into 16 outputs by sharing the clock an load pins on the registers.

    Example for reading one register.
    Code:
    Clock   var PORTB.7
    
    Load    var PORTB.6
    
    Data_1  var PORTB.5
    
    pulsout Load,1
    
    shiftin Data_1,Clock,MSBPre,[keys]
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Hi,

    See the Microchip MCP23016. (16-bit bidirectional I/O port expander).

    You can address up to eight MCP23016 in your system so this
    will give you up to 128 I/O pins.

    Microchip MCP23016 16-Bit I2C™ I/O Expander
    http://ww1.microchip.com/downloads/e...Doc/20090b.pdf

    Interfacing The MCP23016 I/O Expander with the PIC16F877A:
    http://ww1.microchip.com/downloads/e...tes/00245a.pdf


    * * *

    There is also a version with an 8-bit bidirectional I/O port.

    Microchip MCP23008 8-Bit I/O Expander with I2C Interface
    http://ww1.microchip.com/downloads/e...Doc/21919e.pdf

    Best regards,

    Luciano
    Last edited by Luciano; - 1st January 2008 at 08:52.

  4. #4
    Join Date
    Jun 2006
    Posts
    40


    Did you find this post helpful? Yes | No

    Default

    Thx Mackrackit.
    It only High and Low I/O. i think shift register would be a good idea. 4 to 8 lines. Bringing total of 128 bit of I/O. Meaning total pin require is 7 ( 4 for address, Clock, Load and Serial Data ). Am i right ?

    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 ?

  5. #5
    Join Date
    Dec 2003
    Location
    Storrs, Ct.
    Posts
    91


    Did you find this post helpful? Yes | No

    Default max6957

    I use 3 of the Maxim Max6957's for a total of 60 additional I/O's with only 3 PIC pins thru SPI interface. They also have a I2C version. In my app. 52 are used for LED's and 8 will be used for relays. TFM is a bit intimidating at first. I could post some code if interested.

    Hope this helps.

    !!!!!!!!!!!! Happy New Year to All !!!!!!!!!!!!!!
    "It will never happen here!" just happened here.
    My thoughts and prayers for Sandy Hook victims and families.

  6. #6
    Join Date
    Jun 2006
    Posts
    40


    Did you find this post helpful? Yes | No

    Default

    Interesting. If it is feasible, why not. However I just checked with our local distributor and they do not have max6957. Perhaps i should keep looking for the availability. I keep that in mind. Thx Ronjodu
    Cheers,

    mychangl
    "The Dream Is Everything"

  7. #7
    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.

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mychangl View Post
    Thx Mackrackit.
    It only High and Low I/O. i think shift register would be a good idea. 4 to 8 lines. Bringing total of 128 bit of I/O. Meaning total pin require is 7 ( 4 for address, Clock, Load and Serial Data ). Am i right ?

    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 ?
    If you go with shift registers you will need a clock/load set for inputs and one for outputs.
    Look at a HC595 for output and HC165 for inputs (I think, been awhile)

    The solution that Luciano gave looks nice. I did not know about these chips. Learned something new and it is the fisrt day of the year Off to a good start.
    Dave
    Always wear safety glasses while programming.

  9. #9
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Those microchip I/O extender are really nice. In the past i also used PCF8574A, maybe easier to find it locally 'cause it's a very old one.. still popular i guess.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  10. #10
    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"

  11. #11
    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

  12. #12
    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"

  13. #13


    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....

  14. #14
    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.

  15. #15
    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.

  16. #16
    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"

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


    Did you find this post helpful? Yes | No

    Default

    What values do you use for the timing R and C? I also had problems with some of the bits not reading well, finally I used 3900 Ohms for the resistor and no C at all. Also you could try to add this line: DEFINE I2C_HOLD 1 (see pbp manual), it worked for me when I increased the clock speed of my pic to 20MHz.

  18. #18
    Join Date
    Jun 2006
    Posts
    40


    Did you find this post helpful? Yes | No

    Default Thx

    Surprisingly, it works when i removed the capacitor. Resistor remains 3.9K.
    The code also works fine with or without the capacitor.

    Thanks again..
    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 : 1

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