Where to put #define I2C_RETRY_TIMES

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

Where to put #define I2C_RETRY_TIMES

Jump to solution
1,509 Views
zhiqunhu
Contributor III

I noticed that a missing or bad I2C device causes MCU reset by watchdog. This is because of the infinite loop (Bold section in the code below) used in I2C driver functions such as:

1. I2C_MasterTransferNonBlocking() + I2C_MasterTransferAbort()

2. I2C_MasterTransferBlocking()

In the driver, if "I2C_RETRY_TIMES" defined, then it could get out the loop, see the code below.

   

#if I2C_RETRY_TIMES
    uint32_t waitTimes = I2C_RETRY_TIMES;
    /* Wait until bus not busy. */
    while ((0U != (base->S & (uint8_t)kI2C_BusBusyFlag)) && (0U != --waitTimes))
    {
    }

    if (0U == waitTimes)
    {
        result = kStatus_I2C_Timeout;
    }
#else
    /* Wait until data transfer complete. */
    while (0U != (base->S & (uint8_t)kI2C_BusBusyFlag))
    {
    }
#endif

I do not want to add the definition in either fsl_i2c.h or fsl_common.h file, I am wondering if there is a driver configuration file, like FreeRTOSConfig.h for FreeRTOS for user to pass the configure information, or what is the best way to do so.

Regards. 

0 Kudos
1 Solution
1,465 Views
zhiqunhu
Contributor III

One way to do it as my colleague Kevin pointed out is to define that in Preprocessor, "I2C_RETRY_TIMES=3". It does work but place it into a file will be better.

Thanks Kevin.

pastedImage_1.png

View solution in original post

2 Replies
1,466 Views
zhiqunhu
Contributor III

One way to do it as my colleague Kevin pointed out is to define that in Preprocessor, "I2C_RETRY_TIMES=3". It does work but place it into a file will be better.

Thanks Kevin.

pastedImage_1.png

1,465 Views
danielchen
NXP TechSupport
NXP TechSupport

Yes. put the macros in Preprocessor is the right way.

Best reagards

Daniel

0 Kudos