How to detect I2C master Timeouts

14 Nov 2014

I'm porting some code into mbed, and am having trouble in one area.

The current code uses lower level I2C code, and can determine if a I2C read failure happens because of timeout or because or a nak. It behaves differently in each case. But timeout detection does not appear to be exposed at the mbed class level. When I look at the mbed source code, I see this in the i2c_api.c file i2c_byte_read() function:

    // Wait transfer complete
    timeout = FLAG_TIMEOUT;
    while (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_TC) == RESET) {
        timeout--;
        if (timeout == 0) {
            return -1;
        }

link the the whole file here: http://developer.mbed.org/users/mbed_official/code/mbed-src/file/7fa56b1b9d45/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/i2c_api.c

can anyone tell me if I can get the timeout flag, and how to do it?