How to get constant loop time Reading my sensor (I2C,BNO055)

I am using BNO055 Sensor from Bosch On Arduino Due .But the problem is that i the time its taking to read the sensor varies from above 2020us to as low as 292us .I want to keep the time to read the sensor as low as possible.I am attaching my code .It will be very helpful if any body looks though it.Thanks in advance

sketch_oct24a.ino (6.01 KB)

I doubt you can, you are talking to a whole microcontroller inside that device. Perhaps if you
figure out how to drive the two-wire interface native on the Due you can avoid any blocking
calls.

Hi,

I took a brief look of your code.

I think the datasheet page 38, "3.7 Interrupts" will help you. https://cdn-shop.adafruit.com/datasheets/BST_BNO055_DS000_12.pdf

To get continuos measurements with even rate you need to enable the interrupt based behaviour of the IMU chip, and tie the interrupt signalling to the "host" i.e your Due.

Now you are poll-reading in the loop that is not acting evenly.

Thanks MarkT

MarkT: I doubt you can, you are talking to a whole microcontroller inside that device. Perhaps if you figure out how to drive the two-wire interface native on the Due you can avoid any blocking calls.

Do you mean i will have to code in Atmel studio? one thing i have noticed is that if i set baud rate at 250000,i get above 500us reading time after 15 or more full readings.can you enlighten me on that. Thanks in advance