I am using I2C port expanders namely TCA9554A and TCA6424A in my project. I have two options to read the inputs - (a) wait for interrupt and read (b) continuously keep polling the chip for any input changes.
Here is the sample arduino code to read a port:
Wire.beginTransmission(0x22); //0x22 is device's i2c address for TCA6424A
Wire.write(0x00); //Command to access port 0
Wire.endTransmission();
Wire.beginTransmission(0x22);
Wire.requestFrom(0x22, 1); //Requesting port state as 1 byte data
byte inputs=Wire.read();
Serial.println(inputs, BIN); //Printing the received state data
My concerns regarding polling way are the following:
1) Whether I2C lines are fine with handling traffic continuously for extended period of time. My project will be running for months (if not years). Only downtime will be when mains go off but that won't happen for more than an hour or so in a month's time period.
2) Since reading the state involves writing some data to some registers, will it wear off those registers causing an early failure of the port expander than it's expected lifetime.
Datasheets:
1) TCA9554A
2) TCA6424A