Shop OBEX P1 Docs P2 Docs Learn Events
MCP23017 I2C Communications — Parallax Forums

MCP23017 I2C Communications

Roger PiersonRoger Pierson Posts: 62
edited 2007-02-19 13:33 in BASIC Stamp
Hey gang,

This MCP23017 port expander has got me whipped - and it seemed like such a simple device! I've removed the device from my circuit and put it on it's very own PDB and simplified the code as much as possible to attempt to issolate my problem, but with no luck.

I have the proper pull-ups on the IC2 lines and I've tried a spare chip to ensure I wasn't working with a broken one. I have the bare minimum of connections - VDD,VSS,SDA, and SCL. I've checked-rechecked, and double rechecked these. I have the three address lines tied to VSS.

The issue I have is that when trying to read data back from the MCP I always get a byte-full of 1's - even if I remove power from the device. This would seem to indicate a communications problem, but I'll be darned if I can see what it is. Even if I attempt to simply read the control byte, which defaults to 0 on power up, it still comes back as 1's. I hope somebody has some advice, because I sure can't find much on the 'net regarding the MCP23017.

Here is a link to the datasheet: ww1.microchip.com/downloads/en/DeviceDoc/21952b.pdf

And here is my code, as slim-lined as I can make it for clarity:
' {$STAMP BS2p}
' {$PBASIC 2.5}

' -----[noparse][[/noparse] Consants ]-------------------------------------------------------

SDA             PIN     0

w_MCP           CON     %01000000       ' Write MCP23017
r_MCP           CON     %01000001       ' Read MCP23017

GPIO_A          CON     $12             ' GPIO A
GPIO_B          CON     $13             ' GPIO B

IODIRA          CON     $00             ' I/O Direction Register A
IODIRB          CON     $01             ' I/O Direction Register B

IOCONA          CON     $0A             ' Control Register A
IOCONB          CON     $0B             ' Control Register B


' -----[noparse][[/noparse] Variables ]-------------------------------------------------------

MCP_Data        VAR     Word
MCP_Con         VAR     Word

' -----[noparse][[/noparse] Initialization ]--------------------------------------------------

SETUP:
  PAUSE 200                                   ' Time to power up

  I2COUT SDA, w_MCP, IODIRA, [noparse][[/noparse]%11111111]      ' Set all GPIO A pins to inputs
  I2COUT SDA, w_MCP, IODIRB, [noparse][[/noparse]%00000000]      ' Set all GPIO B pins to outputs

  I2COUT SDA, w_MCP, IOCONA, [noparse][[/noparse]%00100000]      ' Set GPIO A control bits
  I2COUT SDA, w_MCP, IOCONB, [noparse][[/noparse]%00100000]      ' Set GPIO B control bits

  ' -----[noparse][[/noparse] Program Code ]----------------------------------------------------

Main:

  I2CIN SDA, r_MCP, GPIO_A, [noparse][[/noparse]MCP_Data.LOWBYTE]
  I2CIN SDA, r_MCP, GPIO_B, [noparse][[/noparse]MCP_Data.HIGHBYTE]

  I2CIN SDA, r_MCP, IOCONA, [noparse][[/noparse]MCP_Con.LOWBYTE]
  I2CIN SDA, r_MCP, IOCONB, [noparse][[/noparse]MCP_Con.HIGHBYTE]

  DEBUG "GPIO A DATA:  ",BIN8 MCP_Data.LOWBYTE,CR
  DEBUG "GPIO B DATA:  ",BIN8 MCP_Data.HIGHBYTE, CR,CR

  DEBUG "GPIO A Control Byte:  ",BIN8 MCP_Con.LOWBYTE,CR
  DEBUG "GPIO B Control Byte:  ",BIN8 MCP_Con.HIGHBYTE, HOME


  PAUSE 200     'For the heck of it

GOTO Main




Thanks,

Roger

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Roger Pierson
Senior Electronics Technicain
DTI Assoicates

Post Edited (Roger Pierson) : 2/16/2007 10:42:56 PM GMT

Comments

  • FranklinFranklin Posts: 4,747
    edited 2007-02-16 21:37
      I2COUT SDA, w_MCP, IOCONA, [noparse][[/noparse]%00100000]      ' Set GPIO A control bits
      I2COUT SDA, w_MCP, IOCONA, [noparse][[/noparse]%00100000]      ' Set GPIO B control bits
    
    
    

    Are you sure you want IOCONA in both lines?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Roger PiersonRoger Pierson Posts: 62
    edited 2007-02-16 21:40
    No, the second one is supposed to be IOCONB, I just forgot to switch it back after messing with it. Doesn't change any results though. [noparse]:([/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Roger Pierson
    Senior Electronics Technicain
    DTI Assoicates
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-16 21:47
    Do you have the MCP23017 reset line tied to +5V or the reset line for the Stamp?

    You do have an error just above "[noparse][[/noparse] Program Code ]" where you use IOCONA when you probably meant IOCONB.
  • Roger PiersonRoger Pierson Posts: 62
    edited 2007-02-16 22:39
    Mike,

    Originally, I had the reset line tied to the stamp's reset line, which in turn was tied to a watchdog timer. When I placed the MCP on a professional development board to troubleshoot, I left it floating.

    I just now tried connecting the reset line to VDD and nothing changed.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Roger Pierson
    Senior Electronics Technicain
    DTI Assoicates
  • Roger PiersonRoger Pierson Posts: 62
    edited 2007-02-17 19:46
    Just as an update, I've fired up the o-scope and confirmed that there is communication happening on the I2C bus. (That's something, I guess.)

    The MCP is definately not being reached though. I've even tried turning on the internal pull-up resistors thinking that if I was suddenly reading VDD on the inputs then that would prove that I was getting through to the device - but I got nothing.

    This is really frustrating. This was supposed to be the simple part of my project.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Roger Pierson
    Senior Electronics Technicain
    DTI Assoicates

    Post Edited (Roger Pierson) : 2/19/2007 1:33:23 PM GMT
  • Roger PiersonRoger Pierson Posts: 62
    edited 2007-02-19 13:33
    Alright then. There must be a reason why this device doesn't seem to be to popular. Guess I'll go to the MCP23016.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Roger Pierson
    Senior Electronics Technicain
    DTI Assoicates
Sign In or Register to comment.