title: example code, documents on MCP23017 (16 pin IO extender, I2C) as an 7-segment LCD driver
body: <p>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:<p></p>
  
  <pre>
    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();
  </pre>
  
  <p>after this i would like to be able to toggle the output values (0xFE &lt;-> 0x01).
  I attempted this code:</p>
  
  <pre>
    I2C_Start();
    I2C_Write(0x40);   // slave address
    I2C_Write(0x12);   // address register
    I2C_Write(0x01u);  // GPIOA
    I2C_Write(0xFEu);  // GPIOB
    I2C_Stop();
  </pre>
  
  <p>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.<p>
  useful documents (kind of): <a href="http://ww1.microchip.com/downloads/en/DeviceDoc/21952b.pdf" rel="nofollow noreferrer">http://ww1.microchip.com/downloads/en/DeviceDoc/21952b.pdf</a></p>