Skip to main content
MM..1
Chief III
July 1, 2025
Question

Issues with I2C HAL in TouchGFX RTOS thread.

  • July 1, 2025
  • 2 replies
  • 428 views

Hello, i see trouble with I2C 

HAL_I2C_Master_Transmit(&hi2c2, addr==0 ? I2C_ADDR_DACR : addr, Buff,3,5);

in project with TouchGFX RTOS i have two threads. One for GUI and second is this hw I2C.

On scope i see, that I2C sometimes (random) split send or receive with clock stretch and sometimes complete hang or skip bytes. How is right setup for use it in multitask envi?

Seems when thread block more as timeout in this cmd , then cmd skip bytes or...

Now on U5, but i mean issue is all HAL. And i ask some tips, except DMA and IT, this ofcourse can change situation.

2 replies

TDK
Super User
July 1, 2025

A 5ms timeout is small, particularly if other interrupts or task switching is happening. Perhaps it is timing out. SCL stretching when the CPU hasn't sent data yet is expected.

 

Can you show scope traces where this happens?

Does the function return HAL_OK?

"If you feel a post has answered your question, please click ""Accept as Solution""."
MM..1
MM..1Author
Chief III
July 1, 2025

I mean timeout is ok , real 3 bytes in fast mode is around 65us. Use bigger timeout isnt solution. I need info how RTOS handle this. Example for priority equal and upper lower as GUI or second next threads...

TDK
Super User
July 1, 2025

If task switches away for 5ms, it's not enough. Evidence suggests that's happening.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Pavel A.
Super User
July 2, 2025

Yes, the HAL library with its funny "locks" is not RTOS friendly. Be creative.