2023-01-09 01:25 AM
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.
2023-01-09 01:30 AM
How about :
void ResetI2Cperipheral(I2C_HandleTypeDef *hi2c){
HAL_I2C_DeInit (hi2c);
HAL_I2C_Init (hi2c);
}
2023-01-09 01:56 AM
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.
2023-01-09 10:26 AM
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.
2023-01-09 05:32 PM
Sorry, what do you mean by one stop bit, one High-Low or Low-High pulse?
2023-01-09 09:18 PM
Google image will draw it for you. I2C stop bit. Per the standard, repeat 9 or 18 of them.