-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
It's possible that reading the temperature register will fail and return 0xFFFF instead of a valid temperature reading. The library attempts to catch this, but unfortunately there's a problem:
readTempC():
...
// Read from temperature register
registerByte[0] = readRegister(0);
registerByte[1] = readRegister(1);
if (registerByte[0] == 0xFF && registerByte[1] == 0xFF)
{
return NAN;
}
...
The problem is that readRegister() reads both bytes of the temperature register, but only returns one, so it takes two readRegister() calls (and two requestFrom() calls) to get both bytes:
uint8_t TMP102::readRegister(bool registerNumber)
{
uint8_t registerByte[2]; // We'll store the data from the registers here
// Read current configuration register value
_i2cPort->requestFrom(_address, 2); // Read two bytes from TMP102
registerByte[0] = (_i2cPort->read()); // Read first byte
registerByte[1] = (_i2cPort->read()); // Read second byte
return registerByte[registerNumber];
}
If one of the requestFrom() calls fails and other succeeds, then one byte will contain 0xFF and the other byte will have valid data. Since both bytes are not 0xFF, readTempC() doesn't catch it and passes it on as valid data.
Currently getting about one read failure per 1000 requests.
Metadata
Metadata
Assignees
Labels
No labels