I/O extender


Closed Thread
Results 1 to 18 of 18

Thread: I/O extender

Hybrid View

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

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

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

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

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

  6. #6


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

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

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

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

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

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