AnsweredAssumed Answered

Kinetis I2C driver infinite loop

Question asked by Arpad Maroti on Apr 6, 2016
Latest reply on Apr 7, 2016 by Arpad Maroti

Hi everyone,

 

I have a strange issue with the I2C driver of KSDK 2.0 (and I also had this with the previous versions).

In my system, I have an I2C master which I use without interrupts (I call I2C_MasterTransferBlocking from my project). My device is also an SPI slave which has interrupts (tx not empty and rx full). The SPI interrupt routine does not interact with the I2C hardware, I2C reads and writes are only issued from the main thread.

 

It seems, that when there are frequent interrupts from the SPI (e.g I'm sending long string) the I2C driver can stuck at the while loops:

    /* Wait until ready to complete. */

    while (!(base->S & kI2C_TransferCompleteFlag))

    {

    }

and

            /* Wait until data transfer complete. */

            while (!(base->S & kI2C_IntPendingFlag))

            {

            }

So basically the hardware never sets these flags thus generating an infinite loop.

This lock-up never happens, when I don't communicate on the SPI, so I assume that this is a timing related problem (the I2C function misses something, that happens during the SPI interrupt).

Have anyone seen something like this? Would it be enough to introduce timeouts to these while loops to avoid endless loops?

 

Best regards,

Arpad Maroti

Outcomes