cancel
Showing results for 
Search instead for 
Did you mean: 

Is HAL_I2C_GetState() required in polling IO mode?

DavePfz
Associate II

I am using the HAL library with an STM32L07xx processor. To keep things simple, I have implemented master transfers on the I2C bus in the polling IO mode. Most of the time it seems to work, however once in a while a master transmit seems to get lost. My thought was that if I use the polling mode, the I2C bus would be in the ready state (HAL_I2C_STATE_READY) on completion of any previous call - either read or write.

However, this begs the question: When does the library return relative to the actual transfer? For example, does it not return until the end of the STOP sequence (what I'm expecting) or whenever the software has done it's last thing and the hardware continues with the final sequence? In this last case, the return from the library could occur before the bus itself is ready for another transfer and the program should check for the ready state before initiating another transfer.

Thanks for any insight...

1 REPLY 1
TDK
Guru

Look at the source. HAL_GetState just returns hi2c->State, which, if the blocking functions complete successfully, will always be HAL_I2C_STATE_READY.

Monitoring the return value of HAL_I2C functions is all you need. HAL_GetState is not useful in blocking mode.

 

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