I2C + RTOS incompatiblity

25 Jan 2013

I can confirm the problem with I2C and mbed_rtos reported at https://mbed.org/forum/bugs-suggestions/topic/4128/

I am working on a project interfacing 4 L3GD20 gyroscopes via I2C (two devices on each I2C bus on the mbed LPC1768), and sending the data via UDP (which I'm using the new socket library, which requires mbed_rtos). I am seeing an error rate of somewhat less than 1%, spread randomly among my 4 I2C devices. Reducing the I2C clock speed from 400KHz to 100KHz actually makes the error rate somewhat larger. Hence I suspect it is a problem of the I2C functions being interrupted by something in the mbed_rtos.

Switching to the MODI2C library fixed the problem, I didn't see any read errors, however I had another problem with MODI2C which I'll probably report elsewhere (namely, it seems to be putting my mbed into a weird state - it works fine the first time but on a reset the i2c and/or DigitalIn pins behave strangely, and this behaviour persists until I power cycle the mbed).

Wrapping my I2C operations in disable_irq() and enable_irq() functions has certainly helped. I'm still seeing some read errors but only from one I2C device, so that might be a wiring problem (although this didn't seem to happen with MODI2C...). So I don't know if this is the correct fix or not? Any other suggestions?

19 May 2013