Posted: Wed Mar 23, 2022 12:29 am Post subject: MCP23017 Question
Hello Everyone,
I have a question regarding the MCP23017 I/O expander IC from Microchip. Hopefully someone who has experience with these can spot what I am overlooking.
I have spent a couple of days working on this thing and not making much headway with being able to read the registers. I can configure the registers on another chip on the board to use as relay driver outputs, that one device works fine...for output.
The issue for whatever reason is when I try to read back the contents of a register, the value that was last written to the chip is returned. For example if I want to read the GPIO A register which is located at &H12, the value that is returned will be the same value that was sent with the I2cwbyte &H43 (the byte that sets up the chip for read). I would expect a value of &HFF to be returned since all of the chip Port A inputs are high at this point.
I have cut out the section of the code below to show what I have written. I've also put in a screen shot of the logic analyzer output that looks like the bus is hanging and not completing the read operation. The two Start conditions are present, but the Stop condition is not present.
'I2cinit 'Setup Port A Direction Register (Set port pins to Input) I2CStart I2cWByte In_Expander_W '42 hex I2cWByte In_Expander_IODIRA
I2cWByte&HFF 'FF hex (All inputs) I2CStop
'Setup Port B Direction Register (Set port pins to Input) I2CStart I2cWByte In_Expander_W
I2cWByte In_Expander_IODIRB
I2cWByte&HFF
I2CStop
'Read Port A Inputs Do i2cstart i2cwbyte In_Expander_W 'Device address, R/W bit = 0 (Write) i2cwbyte In_Expander_GPIO_A 'Register to read (GPIO A)
i2crepstart i2cwbyte In_Expander_R 'Device address, R/W bit = 1 (Read) **This is the value returned in the read below** i2crbyte portA_In ,nack i2cStop
waitms2'delay for terminal application Print #2, PortA_In
PortA_In =0 Loop
Return
(BASCOM-AVR version : 2.0.8.2 , Latest : 2.0.8.5 )
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum