I2C hangs

I don't think you're ever going to be able to fix this from software. It's probably a noise spike from the motor glitching something in the ITG and the ITG is not able to recover automatically. If the ITG is stuck with the SCL/SDA line low it's going to screw up everything on the bus.

OK, I'll continue testing with other I2C devices.
About ITG , I think either it is damaged or defective by design.
During testing I even put it in metal shield and signal wires also wrap in shield, nothing helped.

During testing I even put it in metal shield and signal wires also wrap in shield, nothing helped.

That won't do anything to the noise that is on the supply line, that might only help with noise from an external field or radiation source.

Right now, I tested ADXL345, that is soldered on the same board with ITG, on the same power supply and the same signal wires.
There is no lockups, there is no single failure of reading. All goes great.
The board is SparkFun 6 Degrees of Freedom IMU Digital Combo Board - ITG3200/ADXL345 - SEN-10121 - SparkFun Electronics (http://www.sparkfun.com/datasheets/Sensors/IMU/6DOF-Digital-v10.pdf).

kaor:
Right now, I tested ADXL345, that is soldered on the same board with ITG, on the same power supply and the same signal wires.
There is no lockups, there is no single failure of reading. All goes great.
The board is SparkFun 6 Degrees of Freedom IMU Digital Combo Board - ITG3200/ADXL345 - SEN-10121 - SparkFun Electronics (http://www.sparkfun.com/datasheets/Sensors/IMU/6DOF-Digital-v10.pdf).

I'm not saying that the GYRO is not bad but you can't really use that test as a determining factor. This is probably just telling you that the GYRO is more susceptible to noise than the accelerometer. Now if you remove the motor completely from the circuit and you still have the problem then there's a good chance there is something wrong with the GYRO.

I removed motor power and code part for motor and gyro was going ok.
Then I just start shaking the board and problems appeared again. If I shake the board, even ADX gives misreadings. Board itself is well soldered by manufacturer, my wires also looks like well soldered. I don't know, maybe to high acceleration causes some hardware problems that then appeared in software. I'll return to this problem later, just for curiosity. But for my project I'm migrating to another IMU.

Then I just start shaking the board and problems appeared again. If I shake the board, even ADX gives misreadings.

You probably have a loose connection or bad solder joint somewhere because that really shouldn't happen.

I'm sure that this isn't due to bad soldering , anyway I'll check everything with many tests when I have time.

I run the same code with L3G4200D and everything goes ok.

@kaor
There's another rev of the library that I just posted which seems to handle a majority of lockups now so you may want to try this one also.

wayneft, ok, I'll try it asap.

Hi there,

I came across the same problem as you did. I tried a couple of things concering I²C conduction and prohibition. But nothing did the trick for me. Finally I used a shielded cable for the 3.3V and GND connection, which solved my problems. Since then I have not experienced any problems again. I hope it workes for you or anybody else with that problem too!

P.S.: I am sorry to bring up this old thread. But this thread was more or less the hint for the right solution, so I thought it would be nice to leave a note for anybody with the same problem

I'm using itg3200/adxl345 to detect tilting angle and i'm having the exact problem. Reading from just the two sensors was a stroll down the park but when i try to run a motor and reading the sensors together in one loop, it starts to hang. The hangs happen randomly sometimes immediately after i power on the arduino, sometimes it takes a while to trigger the freeze.

I figured out, that you cant turn the 5V Pull Ups on the Mega off. Since I use a Level Shifter all the problems are gone.

Mr.Tentacle

How do you used a shielded cable for the 3.3V and GND connection?
I can't understand about it.

Hi,
I used a cable like this: http://www.eltim.eu/data/articles/images/small/s_1532.jpg , used the shield wire as the ground and the inner cable as the + cable. But like I said before, it didn't help. We just did it because we used 1000 watt engines and wanted to make sure that induction isn't running everything. But the problem with the board was that the i2c uses 5 volt on the mega but the sensor works with 3.3 volt. Nevertheless good luck with your project.

BenF,

I have the same issue where my i2C locks up my arduino but I really don't understand how to implement the fixes in the post you cited. I have updated my .h and .c file. but what do I need to add to my program?

I added this line in my setup() is that all I need to do?

TWCR = 0

Hi sorry for digging up that old issue but as I'm also struggeling with I2C freezes with a esp8266 as master and a ProMini as slave I'm wondering if the problem from this thread is now fixed in the latest WIRE or HARDWIRE version.

Attached are two resistors 10k as pullup to VCC between the ProMini and a levelshifter then following the ESP

btw is there a difference in stablility between the WIRE and HARDWIRE.h ?

Thanks!

I've battled this issue for years. Basically tried most of what was discussed in this thread. I was using an LCD with i2c to communicate to it. Problem can be invoked by touching one of the i2c connections with a screwdriver or something metallic. The noise will force the hang.

The software watchdog doesn't work all the time either. There are times even the watchdog itself will fail.

Solution: hardware watchdog. I used a hardware watchdog to detect a missing pulse from my loop and once that is detected the device is instantly restarted. It's the one sure way, and perfect for mission critical scenarios.