Skip to content

Commit fcbdf01

Browse files
committed
Changing I2C dataLength from int16_t to uint16_t. Added extra debug prints.
1 parent bf1f8d5 commit fcbdf01

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/SparkFun_BNO080_Arduino_Library.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -945,10 +945,10 @@ void BNO080::softReset(void)
945945
//Read all incoming data and flush it
946946
delay(50);
947947
while (receivePacket() == true)
948-
;
948+
; //delay(1);
949949
delay(50);
950950
while (receivePacket() == true)
951-
;
951+
; //delay(1);
952952
}
953953

954954
//Get the reason for the last reset
@@ -1328,7 +1328,7 @@ boolean BNO080::receivePacket(void)
13281328
shtpHeader[3] = sequenceNumber;
13291329

13301330
//Calculate the number of data bytes in this packet
1331-
uint16_t dataLength = ((uint16_t)packetMSB << 8 | packetLSB);
1331+
uint16_t dataLength = (((uint16_t)packetMSB) << 8) | ((uint16_t)packetLSB);
13321332
dataLength &= ~(1 << 15); //Clear the MSbit.
13331333
//This bit indicates if this package is a continuation of the last. Ignore it for now.
13341334
//TODO catch this as an error and exit
@@ -1355,7 +1355,7 @@ boolean BNO080::receivePacket(void)
13551355
}
13561356
else //Do I2C
13571357
{
1358-
_i2cPort->requestFrom((uint8_t)_deviceAddress, (uint8_t)4); //Ask for four bytes to find out how much data we need to read
1358+
_i2cPort->requestFrom((uint8_t)_deviceAddress, (size_t)4); //Ask for four bytes to find out how much data we need to read
13591359
if (waitForI2C() == false)
13601360
return (false); //Error
13611361

@@ -1372,10 +1372,17 @@ boolean BNO080::receivePacket(void)
13721372
shtpHeader[3] = sequenceNumber;
13731373

13741374
//Calculate the number of data bytes in this packet
1375-
int16_t dataLength = ((uint16_t)packetMSB << 8 | packetLSB);
1375+
uint16_t dataLength = (((uint16_t)packetMSB) << 8) | ((uint16_t)packetLSB);
13761376
dataLength &= ~(1 << 15); //Clear the MSbit.
13771377
//This bit indicates if this package is a continuation of the last. Ignore it for now.
13781378
//TODO catch this as an error and exit
1379+
1380+
// if (_printDebug == true)
1381+
// {
1382+
// _debugPort->print(F("receivePacket (I2C): dataLength is: "));
1383+
// _debugPort->println(dataLength);
1384+
// }
1385+
13791386
if (dataLength == 0)
13801387
{
13811388
//Packet is empty
@@ -1403,7 +1410,7 @@ boolean BNO080::getData(uint16_t bytesRemaining)
14031410
if (numberOfBytesToRead > (I2C_BUFFER_LENGTH - 4))
14041411
numberOfBytesToRead = (I2C_BUFFER_LENGTH - 4);
14051412

1406-
_i2cPort->requestFrom((uint8_t)_deviceAddress, (uint8_t)(numberOfBytesToRead + 4));
1413+
_i2cPort->requestFrom((uint8_t)_deviceAddress, (size_t)(numberOfBytesToRead + 4));
14071414
if (waitForI2C() == false)
14081415
return (0); //Error
14091416

@@ -1481,8 +1488,16 @@ boolean BNO080::sendPacket(uint8_t channelNumber, uint8_t dataLength)
14811488
{
14821489
_i2cPort->write(shtpData[i]);
14831490
}
1484-
if (_i2cPort->endTransmission() != 0)
1491+
1492+
uint8_t i2cResult = _i2cPort->endTransmission();
1493+
1494+
if (i2cResult != 0)
14851495
{
1496+
if (_printDebug == true)
1497+
{
1498+
_debugPort->print(F("sendPacket(I2C): endTransmission returned: "));
1499+
_debugPort->println(i2cResult);
1500+
}
14861501
return (false);
14871502
}
14881503
}

0 commit comments

Comments
 (0)