Where to put #define I2C_RETRY_TIMES

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Where to put #define I2C_RETRY_TIMES

跳至解决方案
2,610 次查看
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 项奖励
回复
1 解答
2,566 次查看
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

在原帖中查看解决方案

2 回复数
2,567 次查看
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

2,566 次查看
danielchen
NXP TechSupport
NXP TechSupport

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

Best reagards

Daniel

0 项奖励
回复