Go Down

Topic: Problem with I2Cdev after a while (Read 223 times) previous topic - next topic

Joaqks

Sep 04, 2017, 05:57 pm Last Edit: Sep 04, 2017, 06:10 pm by Joaqks
Hi!

I am using an Arduino Due and a MPU6050 in my project. I read the MPU6050 whitout problems, but, randomly, the Arduino stops work and the I2C read/write don't works (can't connect to IMU). I have to power off the board, reset don't works.


Do you know if there a problem with this library? I don't know if it is important, but in the setup function I try to configure the I2C speed with:

Wire.setClock(I2C_SPEED);   // Change I2C speed
Wire.begin();

where I2C_SPEED = 800000L;

When I said that Arduino stops, I want to say that the frequency of the loop decreases a lot. Is like something is changing the clock settings.

Someone has problems with this library?

Thanks!

ard_newbie


I don't use any Library with I2C (TWI), although AFAIK the maximum frequency for this peripheral is
400 Kbps.

Joaqks

Doesn't matter if I change or not the I2C Speed, always have the same problems (just tested now). Thanks!

ard_newbie

#3
Sep 04, 2017, 06:38 pm Last Edit: Sep 04, 2017, 08:16 pm by ard_newbie

Unlike AVR chips, there is one big difference in the order that registers get set in Atmel ARM chips .The Sam3x expects you to set the stop bit in the control register before you send the last read, just before the next to last read. If you don't set the stop bit properly, the uc will send an ACK instead of NACK on the last read and the uc may hang. If you read only one byte, send a Start and a Stop at the same time.

Joaqks

Hi!

I have done some progress. I discovered, with an oscilloscope, that when the Arduino crashes, the signal SCL in the bus I2C is continuous, not a clock signal.

Too, I am unable to put the speed that I want on I2C clock (I am trying to put it at 400 KHz). I tried to use  Wire.setClock(), and, put what you put,the frequency is 180KHz or 80 KHz. Too, I tried to change the TWI_FREQ in Wire.h, and the same occurs.

Any idea?

Joaqks

News!

Now, I fixed the problem with the frequency and I get the 400KHz on I2C SCL. The crash remains, randomly, SCL remains on high level and I2C doesn't work. Looks like a problem with Wire library....Any suggestion?

MartinL

#6
Sep 07, 2017, 11:28 am Last Edit: Sep 07, 2017, 12:18 pm by MartinL
Hi Joaqks,

You could try Kris Winer's excellent code for the MPU-6050 located on Github: https://github.com/kriswiner.

It comes together with example code that's easy to use and should at least determine if your issue is software related.

Also, you could also try using Wire1 (pull-up resistors not included) instead of Wire and see if the problem persists.

Go Up