Razor-AHRS / razor-9dof-ahrs

AHRS Firmware for the SparkFun 9DOF Razor IMU and SparkFun 9DOF Sensor Stick
Other
450 stars 264 forks source link

9DOF Stick locks up I2C while reading Gyro #45

Open pdeschulthess opened 8 years ago

pdeschulthess commented 8 years ago

I've been evaluating this _excellent _ AHRS code for my project and would like to report a possible bug when using the 9 DOF Sensor Stick. After running perfectly for about an hour at 15Hz (i.e. after more than 50000 successful iterations) the code unexpectedly locks up the Arduino while trying to read from the Gyro sensor.

The line of code that hangs is Wire.requestFrom(GYRO_ADDRESS, 6). It just never comes back -- you have to reset the Arduino! There appears to be a known issue with the ITG-3200 Gyroscope as discussed on the Arduino forum topic (forum.arduino.cc/index.php?topic=66353).

It would appear that this problem is with the Wire I2C implementation. The ITG-3200 Gyroscope can get in a twist and hold the CLK low. Since the Wire library doesn't have a timeout feature you can't get control back and the Arduino waits indefinitely for the data.

I was wondering if anyone had tried to use felias-fogg's SoftI2CMaster library instead which has a timeout feature (github.com/felias-fogg/SoftI2CMaster). I'm not sure if I'm up to the task, but rewriting this way may be my only option for reliable comms...

Or I could increase my sensor cost and purchase the Razor IMU which uses serial instead of I2C.

Any suggestions or ideas are gratefully received!