-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Description
Following up on the fixes from issue #13...
In the example as you suggested fifoCount should be converted to uint16_t.
This is important because occasionally, for whatever reason, the fifoCount is more than 42, quite often around 300 which would overflow the 8 bit fifoCount.
Related to this, and something that was causing me grief by corruption, there needs to be a check that when/if fifoCount is bigger than expected we do not overflow the fifoBuffer.. I added this check to protect against that.
// read FIFO content, make sure we do not overflow our buffer
if(fifoCount <= sizeof fifoBuffer) {
accelgyro.getFIFOBytes(fifoBuffer, fifoCount);
}else{
Serial.print("Trying to read too much FIFO ");
Serial.println(fifoCount);
accelgyro.resetFIFO();
return;
}
I think at least one reason for fifoCount being bigger than expected is if something causes the interrupt to be delayed (like a delay(1000)) in the loop.
Maybe the fifo could be read in the interrupt handler itself? That would avoid the fifo filling up.
Thanks