Can the configuration registers be read (registers 6 & 7)? The datasheet is clear about the issues when reading the output registers, but is silent on this question.
If a bit is set to output and the device resets due to a glitch, reading the bit status (input or output) would reveal immediately if a reset had occurred (defaults to input).
I added a routine to Keith Neufeld’s i2c_gpio code as follows:
// the gpio_check routine reads the configuration registers to see if outputs
// have been changed to inputs, indicating a power-on reset has occurred
int gpio_check(int address) {
int data = 0;
Wire.beginTransmission(address); // Send input register address
Wire.write(REGISTER_CONFIG);
Wire.endTransmission();
Wire.beginTransmission(address); // Connect to device and request two bytes
Wire.requestFrom(address, 2);
if (Wire.available()) {
data = Wire.read(); }
if (Wire.available()) {
data |= Wire.read() << 8; }
Wire.endTransmission();
return data; } // end of gpio_check
then used it to check the registers with a suitably mixed control byte (0x0135)
// check the configuration registers
gpio_dir(_relay, 0x0135) ; // write a "checkable" pattern
if(gpio_check(_relay) == 0x0135) {
blinker(150) ; // three quick blinks show gpio config
blinker(150) ; // read works
blinker(150) ; }
else {
blinker(500) ; // two long means not read
blinker(500) ; }
// end of check
and I got the 3 blinks, so I’m assuming the control registers are readable.