Kinetis I2C driver infinite loop

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Kinetis I2C driver infinite loop

2,146 Views
arep
Contributor II

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

Labels (1)
0 Kudos
Reply
4 Replies

1,298 Views
arep
Contributor II

Hi all,

It seems that using the interrupt driven approach of the same driver (I2C_MasterTransferNonBlocking) solved my problem.

Thank you for your help.

Best Regards,

Arpad Maroti

0 Kudos
Reply

1,298 Views
Edrianocarlos
Contributor IV

Hello Arpad.

I am not using the I2C driver, instead i developed my own routine. And what i have seen about I2C hardware you can not use the  I2C_S_TCF to verify if a transmission was completed successfully instead you have to check I2C_S_IICIF as IICIF is a interrupt flag i assume that it is not setting when it happens inside your SPI interrupt.

TCF would be the right flag to polling but it does not work.

1,298 Views
arep
Contributor II

Hi Edriano,

Thank you for your response, I'll try changing checking of TCF to IICIF. Although I've already seen the code hanging at the second while loop, where IICIF is checked... I'll come back with the results.

0 Kudos
Reply

1,298 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, all,

This is my guess. I think the mcu is too busy to handle all the interrupt of both IIC and SPI, in order to test if it is the case, you can toggle a  pin in the main loop in the main.c. If it is the case, you can reduce the baudrate of both SPI and IIC so that the mcu have enough time to handle all the interrupts.

BR

Xiangjun Rong