This is a re-post, previously I did a post on a different section here on the forum. I will try my luck in this Due dedicated section.
I have this problem driving me insane the last couple of weeks.
My setup is:
Arduino Due (genuine)
Adafruit MTK3339 GPS
Adafruit 10DOF IMU
The IMU is connected to pin 20 and 21 (SCL, SDA) on the Due (have tried SCL1 and SDA1 as well). I'm powering the IMU with 3.3V, so the builtin lever shifter in the IMU is not active.
The GPS is connected to the Serial2, powered by 3.3V, using 9600 baud setting, only NMEA $GPRMC sentence active.
I have a test sketch reading the IMU sensors (rate, acceleration, magnetic), and reading the GPS NMEA sentence.
Occasionally (<5 min) the I2C communication fails. The bus gets locked and I have to power toggle or toggle the SCL wire a couple of times (slave is holding SDA low).
The failures seems to occur about the same time as the GPS sends its message. If I tell the GPS to be silent, but still active, I never see this issue (running four hours, reading sensors at around 200 Hz).
The I2C communication fails on different places, the following places (functions in Wire.c) are the ones I have observed so far:
TWI_WaitByteSent(), reason: timeout
TWI_WaitByteSent(), reason: ARBLST
TWI_WaitByteReceived(), reason: timeout
TWI_WaitTransferComplete(), called from requestFrom(), reason: timeout
TWI_WaitTransferComplete(), called from endTransmission(), reason: timeout
Interesting is that the TXRDY bit is set when it fails in the TWI_WaitTransferComplete() and TWI_WaitByteSent() functions. I don't know if this means something.
Sometimes I stumble upon a NACK, but that does not hang the bus.
I have tried different I2C frequencies, different GPS NMEA output rates and baud rates. Nothing helps. I have tried to separate the I2C wires as far as possible from the serial wires (in case of EMC issue). Added capacitor to the 3.3V (voltage taken from the Due). No difference.
Turning interrupts OFF (using "noInterrupts()") during I2C communication did no difference as well.
I have been diving in the Arduino code libs after clues - the Wire/TwoWire/TWI code is a bloody mess. But obviously it works when the GPS isn't sending NMEA.
I'm using 1.5.8, so the Wire library fix shall be included.
Please advice before I permanently goes insane and take up knitting as a hobby instead.
Let me know what else information you need.