cancel
Showing results for 
Search instead for 
Did you mean: 

I2C master remain in timeout status.

FMass.1
Associate III

Hi, I have a problem with I2C communication between two MCU.
The MCU that acts as I2C master in its main loop calls the HAL_I2C_Master_Receive function at an interval of approximately 1 second and reads the status of the MCU that acts as I2C slave.

Everything works, but I noticed that if for some reason the MCU that acts as a I2C slave is turned off and on again (a normal reset cycle for example, whatchgod timeout os something like that), the master always goes into error HAL_I2C_ERROR_TIMEOUT when it calls the HAL_I2C_Master_Receive function.

So communication only works, master and slave start together and always remain active together. But if the slave is turned off, when it is turned back on the communication no longer restarts, and continues to time out even if the slave is active.

it's as if the I2C master once goes into error, always remains in error. I need something that can "reset" the I2C master after the timeout error, I don't know if I need to clean some flags or something like that.

Can you help me?

1 ACCEPTED SOLUTION

Accepted Solutions
Pierre_Paris
ST Employee

Hello @FMass.1,

Thank you for your question.

"A software reset can be performed by clearing the PE bit in the I2C_CR1 register. In that case I2C lines SCL and SDA are released. Internal states machines are reset and communication control bits, as well as status bits come back to their reset value. The configuration registers are not impacted." I suggest you to read the chapter 30.4.5 Software reset of the RM0385.

Best Regards,

Pierre

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

2 REPLIES 2
AScha.3
Chief III

this is what i do, if "unknown" error on I2C : just restart it.

HAL_I2C_DeInit(&hi2cx);

HAL_I2C_Init(&hi2cx);

If you feel a post has answered your question, please click "Accept as Solution".
Pierre_Paris
ST Employee

Hello @FMass.1,

Thank you for your question.

"A software reset can be performed by clearing the PE bit in the I2C_CR1 register. In that case I2C lines SCL and SDA are released. Internal states machines are reset and communication control bits, as well as status bits come back to their reset value. The configuration registers are not impacted." I suggest you to read the chapter 30.4.5 Software reset of the RM0385.

Best Regards,

Pierre

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.