cancel
Showing results for 
Search instead for 
Did you mean: 

F411 I2C Recover from Error

HDaji.1
Senior

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.

5 REPLIES 5
Javier1
Principal

How about :

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

we dont need to firmware by ourselves, lets talk

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.

S.Ma
Principal

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.1
Senior

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

S.Ma
Principal

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