Intermittently, my fsl_i2c driver code is getting stuck in a forever while loop while trying to read bytes from an external I2C EEPROM chip.
I'm using the fsl_i2c driver for the MK64F and am trying to read 4 bytes via I2C read using I2C_MasterTransferBlocking(). At the end of reading the 4 bytes in I2C_MasterReadBlocking(), when (rxSize == 0U), the driver code executes I2C_MasterStop().
This is supposed to issue a STOP command with the following:
/* Issue the STOP command on the bus. */
base->C1 &= ~(uint8_t)(I2C_C1_MST_MASK | I2C_C1_TX_MASK | I2C_C1_TXAK_MASK);
However, the code then gets stuck in the while loop:
while(0U != (base->S & (uint8_t)kI2C_BusBusyFlag))
{
}
By my understanding the BUSY bit of base->S should be cleared when a STOP signal is detected. Why did the base->C1 write fail to issue the STOP command?
It also appears that the NACK that is supposed to be issued after the 4th byte is read is not actually being issued:
if (rxSize == 1U)
{
base->C1 |= I2C_C1_TXAK_MASK;
}

As mentioned at the top of the post, the I2C_MasterReadBlocking works most of the time (I can read out all of the 4096 bytes from this EEPROM many times before occasionally running into this issue).