Ok not too bad. I got a patch for you to try out. You will need to edit a few lines in i2c_t3.cpp file. Change as indicated in red below (this is around line ~1620 or so).
At the top a line is added, and at the bottom two lines are commented out. Try this and let me know if it fixes the problem. If so I will roll this into the next update.
Code:
#if defined(__MKL26Z64__) // LC
else if(flt & I2C_FLT_STOPF) // STOP detected (LC only)
{
// There is some weird undocumented stuff going on with the I2C_FLT register on LC.
// If you read it back, bit4 is toggling, but it is supposed to be part of FLT setting.
// Writing just the STOPF bit causes things to get stuck, but writing back the read value
// seems to work
*(i2c->FLT) = flt; // clear STOP intr
*(i2c->FLT) &= ~I2C_FLT_STOPIE; // disable STOP intr
i2c->currentStatus = I2C_WAITING;
if(i2c->user_onReceive != nullptr)
{
i2c->rxBufferIndex = 0;
i2c->user_onReceive(i2c->rxBufferLength);
}
}
#endif
else
{
// Continue Slave Receive
//
// setup SDA-rising ISR - required for STOP detection in Slave Rx mode for 3.0/3.1
#if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) // 3.0/3.1
i2c->irqCount = 0;
if(i2c->currentPins == I2C_PINS_18_19)
attachInterrupt(18, i2c_t3::sda0_rising_isr, RISING);
else if(i2c->currentPins == I2C_PINS_16_17)
attachInterrupt(17, i2c_t3::sda0_rising_isr, RISING);
#if I2C_BUS_NUM >= 2
else if(i2c->currentPins == I2C_PINS_29_30)
attachInterrupt(30, i2c_t3::sda1_rising_isr, RISING);
else if(i2c->currentPins == I2C_PINS_26_31)
attachInterrupt(31, i2c_t3::sda1_rising_isr, RISING);
#endif
// #elif defined(__MKL26Z64__)
// *(i2c->FLT) |= I2C_FLT_STOPIE; // enable STOP intr
#endif
data = *(i2c->D);
if(i2c->rxBufferLength < I2C_RX_BUFFER_LENGTH)
i2c->rxBuffer[i2c->rxBufferLength++] = data;
}
*(i2c->S) = I2C_S_IICIF; // clear intr
}
}
#if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) // 3.0/3.1
// ------------------------------------------------------------------------------------------------------
// SDA-Rising Interrupt Service Routine - 3.0/3.1 only
//
// Detects the stop condition that terminates a slave receive transfer.
// If anyone from Freescale ever reads this code, please email me at
// paul@pjrc.com and explain how I can respond to the I2C stop without
// inefficient polling or a horrible pin change interrupt hack?!
//