AnsweredAssumed Answered

Where to put #define I2C_RETRY_TIMES

Question asked by Zhiqun Hu on Jul 15, 2020
Latest reply on Jul 19, 2020 by Daniel Chen

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. 

Outcomes