Calibration readback should work on the INA226 (register 0x05) should read back whatever I wrote to it, right?
I've got something odd going on. If I reset the chip and read 0x05 I read 0x0000 which is the reset value - that's expected. If I write the value I want to it (838 decimal) then when I read 0x05 I get back nonsense.
My write is using the wire library like this:
uint16_t cal = 838; Wire.beginTransmission(INA_ADDR); Wire.write(0x05); /* cal register */ Wire.write( (cal >> 8) | 0xFF ); /* high byte */ Wire.write( cal & 0xFF ); /* low byte */ Wire.endTransmission();
When I read I have to do something completely different. I have to set the register first, like this:
uint16_t cal = 838; Wire.beginTransmission(INA_ADDR); Wire.write(0x05); /* cal register */ Wire.endTransmission(); Wire.requestFrom(INADDR, 2); byte high = Wire.read(); byte low = Wire.read(); Wire.endTransmission();
I'm not sure why, but if I try to do it in a single transaction (begin, write, read, read, end) it doesn't seem to latch the address in correctly. They have to be two totally separate transactions.
I think my read is working fine (I can read back bus and shunt voltages and they make sense) but I think my write must somehow be off. I tried doing the configuration in two transactions - write the register address (then endTransmission), then write the value. It didn't work that way, either.
For those not familiar, endTransmission is essentially STOP in I2C language.