Skip to content

Commit e398d7d

Browse files
committed
Add extra I2C available checks to improve reliability
Don't ask me why, but this seems to help. A lot...
1 parent 091f2d2 commit e398d7d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/SparkFun_BNO080_Arduino_Library.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,14 @@ boolean BNO080::receivePacket(void)
14301430
}
14311431
else //Do I2C
14321432
{
1433+
if (_i2cPort->available() > 0) // Don't ask me why, but including this seems to make a big difference to the reliability
1434+
{
1435+
if (_printDebug == true)
1436+
{
1437+
_debugPort->print(F("receivePacket (I2C): before calling requestFrom, _i2cPort->available was: ")); _debugPort->println(_i2cPort->available());
1438+
}
1439+
}
1440+
14331441
_i2cPort->requestFrom((uint8_t)_deviceAddress, (size_t)4); //Ask for four bytes to find out how much data we need to read
14341442
if (waitForI2C((size_t)4) == false)
14351443
return (false); //Error
@@ -1512,6 +1520,14 @@ boolean BNO080::getData(uint16_t bytesRemaining, uint8_t channelNumber, uint8_t
15121520
if (numberOfBytesToRead > (I2C_BUFFER_LENGTH - 4))
15131521
numberOfBytesToRead = (I2C_BUFFER_LENGTH - 4);
15141522

1523+
if (_i2cPort->available() > 0) // Don't ask me why, but including this seems to make a big difference to the reliability
1524+
{
1525+
if (_printDebug == true)
1526+
{
1527+
_debugPort->print(F("getData: before calling requestFrom, _i2cPort->available was: ")); _debugPort->println(_i2cPort->available());
1528+
}
1529+
}
1530+
15151531
_i2cPort->requestFrom((uint8_t)_deviceAddress, (size_t)(numberOfBytesToRead + 4));
15161532
if (waitForI2C((size_t)(numberOfBytesToRead + 4)) == false)
15171533
return (false); //Error

0 commit comments

Comments
 (0)