AnsweredAssumed Answered

LPI2C not releasing bus, STOP not sent

Question asked by Dave Marples on Feb 28, 2020
Latest reply on Apr 2, 2020 by Victor Jimenez

There appears to be a race bug in fsl_lpi2c.c in LPI2C_MasterStop / LPI2C_MasterCheckAndClearError whereby after the STOP command is added to the FIFO, if a NAK arrives then the STOP may be lost, resulting in the bus not being released. I think this patch addresses the issue;

 

diff --git a/devices/MIMXRT1021/drivers/fsl_lpi2c.c b/devices/MIMXRT1021/drivers/fsl_lpi2c.c
index 1ff3078..1267fff 100644
--- a/devices/MIMXRT1021/drivers/fsl_lpi2c.c
+++ b/devices/MIMXRT1021/drivers/fsl_lpi2c.c
@@ -248,8 +248,12 @@ status_t LPI2C_MasterCheckAndClearError(LPI2C_Type *base, uint32_t status)
         /* Clear the flags. */
         LPI2C_MasterClearStatusFlags(base, status);

-        /* Reset fifos. These flags clear automatically. */
-        base->MCR |= LPI2C_MCR_RRF_MASK | LPI2C_MCR_RTF_MASK;
+        /* Reset fifos (Except for NAK, which doesn't generate a STOP automatically). */
+        /* These flags clear automatically. */
+        if (kStatus_LPI2C_Nak != result)
+          {
+            base->MCR |= LPI2C_MCR_RRF_MASK | LPI2C_MCR_RTF_MASK;
+          }
     }
     else
     {

Regards

DAVE

Outcomes