Reset I2C connection

Hello great forum!

I have a complicated Arduino Due Project. The board is controlling a bunch of motors, and reading data from various sensors (analog, UART, I2C).

Im having problems with my I2C bus. Im polling LSM9DS0 IMU (gyroscope, magnetometer, accelerometer) by calling Sparkfun's library. ( SparkFun 9 Degrees of Freedom IMU Breakout - LSM9DS0 - SEN-12636 - SparkFun Electronics )
Sometimes after a while, the I2C communication bricks and the values are no longer refreshed when polling. I know this because I can write to a WHO_AM_I register which is supposed to return 0x49D4, but that doesnt happen. If you manually unplug the power from the board and plug it back in, everything starts working again.

I tried resetting the board in a software using a watchdog timer. The board goes trough a reset but the I2C connection is not getting re-established.

I used another microcontroller to pull Arduino Due's reset pin to ground via NPN transistor when the problem occurs but that doesnt always fixes the problem.

I suspect that some control registers dont get properly cleared after watchdog reset or after pulling reset pin to GND (a method which is not recommended according to what I saw on other forums).

What I really need is some kind of wire.reset() function call. Any advice on how to do that?
Please help!
Thank you!

Additional info: I am sure that this is not a wiring issue. I have 4 identical separate circuits, and all of them show this problem.

Based on what you describe, I would suspect one of the slaves devices is losing it's mind, and tying up the bus. What happens if you power-cycle JUST the slaves, and NOT the Due?

Ray L.

Thats a really good question, Ray.

I havent thought of that. I will try to rewire my set up and power cycle my I2C slave (the only slave on the bus) with an NPN transistor when the board detects a problem.

I know that if I pull the power wires from my slave, Im not getting 0x49D4 bytes when I am trying to write to WHO_AM_I register. When I plug the power back, the Aruino Due starts talking to the slave again and I am getting 0x49D4 . The connection gets re-established automatically.

However, I dont know how to force this I2C bug that im getting. I dont know what causes it, it happens on its own so Im not sure if powering the slave off and on will solve the problem. I will try it though !

Looks like powering down the IMU doesnt solve the problem. Im not geting the right bytes when reading WHO_AM_I :frowning: after I power the IMU off, wait 3 seconds, power the IMU on :frowning: