MCP23017 I2C Communications
Roger Pierson
Posts: 62
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:
Thanks,
Roger
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Roger Pierson
Senior Electronics Technicain
DTI Assoicates
Post Edited (Roger Pierson) : 2/16/2007 10:42:56 PM GMT
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
Are you sure you want IOCONA in both lines?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Roger Pierson
Senior Electronics Technicain
DTI Assoicates
You do have an error just above "[noparse][[/noparse] Program Code ]" where you use IOCONA when you probably meant IOCONB.
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
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 Pierson
Senior Electronics Technicain
DTI Assoicates