Skip to main content
CHill.1
Visitor II
June 17, 2020
Solved

How to transition from blocking to non-blocking I2C?

  • June 17, 2020
  • 2 replies
  • 3617 views

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?

This topic has been closed for replies.
Best answer by TDK

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

2 replies

YS.K
Associate II
June 17, 2020

I haven't tested the I2C dma mode yet.

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

TDK
TDKBest answer
June 17, 2020
"If you feel a post has answered your question, please click ""Accept as Solution""."
Visitor II
July 5, 2023

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.