Arduino Due I2C and serial issue

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. I'm powering the IMU with 3.3V, so the 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, pressure), and reading the GPS NMEA sentence.

Occasionally (<5 min) the I2C communication fails when calling endTransmission(), returns code 2, and I need to power cycle the entire thing to get it up and running again. This seems to occur when 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).

I have tried different I2C frequencies, different GPS NMEA output rates and baud rates. Nothing help. I have tried to separate the I2C lines as far as possible from the serial lines (in case of EMC issue). Added capacitor to the 3.3V (voltage taken from the Due). No difference.

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.

Serial comunication is slow compared to the I2C.Maybe you are taking to long to process the Serial data in your program and then the I2C fails.Try to speed up your UART speed to see if something changes

It does not matter. Communication is purely sequential for each device. Anyway, I have tried to speed it up. No difference.

I have also tried the other I2C port. Same issue..

In Wire.cpp, I reach the timeout in TWI_WaitByteSent for some reason (makes endTransmission() return 2). Why could that be? What makes TWI_SR_TXRDY to never occur? Could it be the case that the serial communication messes with I2C through some interrupt routines/registers?

static inline bool TWI_WaitByteSent(Twi *_twi, uint32_t _timeout) {
uint32_t _status_reg = 0;
while ((_status_reg & TWI_SR_TXRDY) != TWI_SR_TXRDY) {
_status_reg = TWI_GetStatus(_twi);

if (_status_reg & TWI_SR_NACK)
return false;

if (--_timeout == 0)
return false;
}

return true;
}

I ran into the exact same issue. Can't make exactly the same hardware work together. I also tried a lot of diferent configs and wirings. Didn't dig this much into the code bug thoug.

Have you found a solution?

Tnx.