I'm using MCUXpresso SDK version 2.8.0 with the MK64FX512VLL12. I'm working with 3 I2C buses (I2C0, I2C1, and I2C2).
I'm having an issue where I2C_MasterTransferBlocking() hangs in an infinite loop waiting on the kI2C_TransferCompleteFlag:
/* Wait until the data register is ready for transmit. */
while (0U == (base->S & (uint8_t)kI2C_TransferCompleteFlag))
{
}
The hang doesn't occur on I2C0 or I2C1. However, I2C2 is shared with another master. Transfers work on that bus until the other master performs a transfer. The next time I call I2C_MasterTransferBlocking(), this results in an infinite loop waiting on kI2C_TransferCompleteFlag near the very top of the function.
It appears the other master's transfer results in the I2C2_S:TCF flag being cleared, so I'm not surprised to see the loop above hang infinitely. In fact, the K64 reference manual says this about I2Cx_S:TCF:
"TCF - Transfer Complete Flag: Acknowledges a byte transfer; TCF is set on the completion of a byte transfer. This bit is valid only during or immediately following a transfer to or from the I2C module. TCF is cleared by reading the I2C data register in receive mode or by writing to the I2C data register in transmit mode."
I can work around the issue by replacing the existing loop with:
while (base->S & (uint8_t)kI2C_BusBusyFlag)
{
}
So to my question(s):
Solved! Go to Solution.
Hello @steve32768,
Since you're using the blocking function, the API will wait until the transfer ends to continue in the code. The TCF
Yes, the SDK is not enabled to work as Multimaster so checking the busy flag before a transfer to see if there's any pending transfer in the bus is a good approach.
Best Regards,
Alexis Andalon
Hi @steve32768
I cannot reproduce the issue on my side using a multi-master system(3 k64 I2C instance, 2 as master and 1 as slave). The data transfered by other master did and should not affect the TCF bit since the TCF is set to indicate the byte transfer completion done by this module not other master on bus. May you please share more of the transfer sequence when this situation happens? And what kind of I2C master and slave module are sharing the bus?
Thanks
Kate,
Thanks for the response.
The two masters on the bus are 1) K64 MCU, and 2) i.MX8 running Linux. The only slave on the bus is a DS1340U RTC. The transfers from master #2 are early in the Linux bootup sequence, and happen after the master #1 calls I2C_MasterInit() and before master #1 calls I2C_MasterTransferBlocking() to read a register from the slave.
I'll need some time before I can recreate the test setup and reproduce the issue. I should be able to get you more information in a few days.
Hello @steve32768,
Since you're using the blocking function, the API will wait until the transfer ends to continue in the code. The TCF
Yes, the SDK is not enabled to work as Multimaster so checking the busy flag before a transfer to see if there's any pending transfer in the bus is a good approach.
Best Regards,
Alexis Andalon
Thanks for the response. I'll go ahead with my workaround as described.