Skip to main content
Graduate II
January 9, 2023
Question

F411 I2C Recover from Error

  • January 9, 2023
  • 4 replies
  • 1658 views

I have my own F411 PCB board, on which there are a few devices that MCU/F411 uses I2C1 (I2C HAL) to communicate.

Sometimes I2C HAL API (HAL_I2C_Mem_Read, HAL_I2C_Master_Transmit, HAL_I2C_Master_Receive) calls may return with error: most of the time error code is 32, timeout. My problem is once the error occurs, it is there persistently. I have to power on/off the board to get rid of it.

Is there a clear step by step guide on how to software-reset I2C state so that my firmware can recover nicely from that error?

I have to admit: there may be hardware issue that causes the problem, which we need to resolve.

    This topic has been closed for replies.

    4 replies

    Graduate II
    January 9, 2023

    How about :

    void ResetI2Cperipheral(I2C_HandleTypeDef *hi2c){
    HAL_I2C_DeInit (hi2c);
    HAL_I2C_Init (hi2c);
    }
     

    HDaji.1Author
    Graduate II
    January 9, 2023

    Thx Javier, for your advice.

    But it does not work.

    The strange thing about my board is that after power off, I need to wait for a few minutes to power it on; otherwise the I2C problem is still there.

    After power on, if I2C has no problem, it can run a few hours.

    Visitor II
    January 9, 2023

    Generate 9 or 18 stop bits by sw bitbang on gpios. Ideally, test before generating a start bit that both sda and scl are high. Apply 9 stop bit otherwise. chatGPT can help you get code snippets.

    HDaji.1Author
    Graduate II
    January 10, 2023

    Sorry, what do you mean by one stop bit, one High-Low or Low-High pulse?

    Visitor II
    January 10, 2023

    Google image will draw it for you. I2C stop bit. Per the standard, repeat 9 or 18 of them.