


You see the problem? The function readBytes accepts one last parameter which is "timeout" but the function getFIFOCount uses readBytes without the timeout parameter! That's probably a bug cause sometimes I think the readBytes takes too long to execute and a TIMEOUT SHOULD BE set to avoid the function hanging out forever. I2Cdev::readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout) I checked the function "readBytes()" inside I2Cdev.cpp and I found this: Return (((uint16_t)buffer) << 8) | buffer I2Cdev::readBytes(devAddr, MPU6050_RA_FIFO_COUNTH, 2, buffer) Inside the file MPU6050.cpp there is a code like this: So I discovered everytime my arduino hanged/freezes it was at a line with getFIFOCount() or getIntStatus(). I discovered that inserting many Serial.print with tags along my entire code so I could know exactly which line hanged. I discovered it is usually when executin getFIFOCount() or getIntStatus(). It took me almost a full year to discover the problem and today I had some spare time and I tried to find where exactly arduino hangs/freezes. The Arduino, which would be the master-i2c-device, can send instructions to the individual slave-i2c-devices using a fancy communication protocol.Sometimes my Arduino freezes or crashes when using JEFF ROWBERG library to read DMP data from MPU6050. With this unique address you can talk to each device individually. So how do these devices talk to each other? Well, they all have an address, much like you have a mailing address at your house. i2c is often called the 'two wire interface'.

Now you can buy i2c chips which do just about everything, and all these chips are able to communicate with eachother using only two wires. A long time ago Phillips said 'hell with all these wires - we need a way for all the devices to talk to eachother with only two wires'. One thing you will notice, as you begin to work with electronics, is that you always have a mess of wires. I will try to give a very simple explanation of i2c. Expect to be very confused at first. If you plan to do any intermediate and advanced electronics learning i2c is imperative. To understand i2c you are going to have to do a bit of reading. I2c is handled using the Arduino wire library. If you want to use i2c devices it is best to understand how the code works otherwise you are going to have many problems down the road.
