the MCP23017 from Microchip is an I2C based 16-pin IO extender. I have been able to set up the device once (set pin direction and values), but after that i cannot change the values as expected unless i reset / power cycle the device. this is the code i used to initalize it and set the pins up the first time:
I2C_Start(); I2C_Write(0x40); // slave address I2C_Write(0x00); // address register ... (sequential mode so next 10 are set to I2C_Write(0x00); I2C_Write(0x08); // IOCON: HAEN=1 I2C_Write(0x08); // IOCON: HAEN=1 ... (sequential mode so next 6 are set to I2C_Write(0x00); I2C_Write(0xFEu); // GPIOA I2C_Write(0x01u); // GPIOB I2C_Stop();
after this i would like to be able to toggle the output values (0xFE <-> 0x01). I attempted this code:
I2C_Start(); I2C_Write(0x40); // slave address I2C_Write(0x12); // address register I2C_Write(0x01u); // GPIOA I2C_Write(0xFEu); // GPIOB I2C_Stop();
at this point it seems to go out to lunch, the pins seem to be random in value (input vs. output, output High vs Low). If anyone as used this I2C IO extender please help me out. even if your not fully sure your more than welcome to comment. NOTE: I2C API shown here is a bit bang algorithm all clock cycles have aprox. 1ms weights between them.
useful documents (kind of): http://ww1.microchip.com/downloads/en/DeviceDoc/21952b.pdf