cancel
Showing results for 
Search instead for 
Did you mean: 

How to transition from blocking to non-blocking I2C?

CHill.1
Associate

I'm trying to talk to a New Haven NHD-0216CW-AG3 OLED, and I set up a driver using the HAL system on a STM32F373 controller. I realized once I'd written it that it's blocking, and I want to move to a non-blocking system using the _IT functions.

Just changing the transmit commands from HAL_I2C_Master_Transmit to HAL_I2C_Master_Transmit_IT suddenly turned all my results into gibberish on the screen instead of nice text like I had. What do I need to do to move from blocking to non-blocking I2C commands?

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

HAL_I2C_Master_Transmit_IT is a nonblocking function. There are example projects of its usage here:

https://github.com/STMicroelectronics/STM32CubeF3/blob/8fa3aadf0255818f0ca72ba6a5a6731ef8c585fb/Projects/STM32F303RE-Nucleo/Examples/I2C/I2C_TwoBoards_ComIT/readme.txt

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

View solution in original post

3 REPLIES 3
YS.K
Associate III

I haven't tested the I2C dma mode yet.

But using I2C dma is one of the non-blocking methods.

TDK
Guru

HAL_I2C_Master_Transmit_IT is a nonblocking function. There are example projects of its usage here:

https://github.com/STMicroelectronics/STM32CubeF3/blob/8fa3aadf0255818f0ca72ba6a5a6731ef8c585fb/Projects/STM32F303RE-Nucleo/Examples/I2C/I2C_TwoBoards_ComIT/readme.txt

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

Clearly whoever wrote this ST HAL driver doesn't understand what the word "non-blocking" means.  When you have a function I2C_WaitOnFlagUntilTimeout(), which contains a while loop and it just sits there waiting until a hardware condition is true, you don't have a non-blocking function.

 

While HAL_I2C_Master_Transmit_IT() is non-blocking, the corresponding HAL_I2C_Master_Receive_IT() is not, even though the comment in the HAL source code says it is non-blocking.