Hello!
I've been trying to understand I2C lately and I figured a MCP23017 would be a very simple chip to do it with. I've been following the code here
// pins 15~17 to GND, I2C bus address is 0x20
#include "Wire.h"
void setup()
{
Wire.begin(); // wake up I2C bus
// setup addressing style
Wire.beginTransmission(0x20);
Wire.write(0x12);
Wire.write(0x20); // use table 1.4 addressing
Wire.endTransmission();
// set I/O pins to outputs
Wire.beginTransmission(0x20);
Wire.write(0x00); // IODIRA register
Wire.write(0x00); // set all of bank A to outputs
Wire.write(0x00); // set all of bank B to outputs
Wire.endTransmission();
}
void binaryCount()
{
for (byte a=0; a<256; a++)
{
Wire.beginTransmission(0x20);
Wire.write(0x12); // GPIOA
Wire.write(a); // bank A
Wire.write(a); // bank B
Wire.endTransmission();
delay(100);
}
}
void loop()
{
binaryCount();
delay(500);
}
I found online.
The main thing is that I can't figure out the 0x20 register anywhere on the datasheet. I just don't get this whole thing. Can somebody explain?