cancel
Showing results for 
Search instead for 
Did you mean: 

How to clear HAL_BUSY situation for I2C

srdjan
Associate II
Posted on December 22, 2016 at 14:36

Hello,

On my board I have 2 STM32 processors which communicate to each other over I2C. One is always a master and the other one is slave.

The slave prepares some data, and then I do:

   HAL_I2C_Slave_Receive_IT

and wait for command from the master MCU. Once I receive the command I preprare the data and perform

HAL_I2C_Slave_Transmit_IT.

This works fine except in the case when master doesn't read the data back. I might get an interrupt where I need to communicate to some other device on the bus, for example.

The slave gets stuck in the Slave transmit routine waiting for the master to read the data but the bigger problem is that the I2C bus is now blocked. I have other devices connected to the same bus, and when the master tries to perform write I always get HAL_BUSY.

How can I get out of this situation? Reseting the master MCU unblocks the i2c bus, which means that the slave is not locking it, but it's the master. What's the correct procedure that I need to follow in this case?

Thank you.

#stm32 #i2c
1 REPLY 1
Nor Sch
Associate III
Posted on December 22, 2016 at 15:38

You have to implement a State Machine for I2C with TimeSlices for Send and Receive. Take a look into this Thread:

https://community.st.com/0D50X00009XkgfoSAB

Edit: and directly in the ErrorState I make a DeInit, clear up some Stuff (buffers etc) and a new Init.