Skip to main content
NAnto.4
Associate
November 1, 2021
Question

Hello, Is there any way to receive unknown bytes count with i2c (by interruption) and hal lib? I cannot find appropriate way in api. Thanks

  • November 1, 2021
  • 2 replies
  • 997 views

..

This topic has been closed for replies.

2 replies

TDK
November 1, 2021

Did you try HAL_I2C_Master_Receive_IT? If it gets a NACK, it's going to do something. Either go to the error interrupt or still hit the transfer complete interrupt. Either way, it probably has enough information in the state machine to discern how many bytes were received.

"If you feel a post has answered your question, please click ""Accept as Solution""."
NAnto.4
NAnto.4Author
Associate
November 1, 2021

I use slave so i tried HAL_I2C_Slave_Receive_IT. I found the similar question https://community.st.com/s/question/0D50X00009XkXWw/stm32-i2c-hal-slave-receive-callback-not-called, my problem looks the same.

Tesla DeLorean
Guru
November 1, 2021

Which STM32?

This is a general deficiency in the HAL, as it likely does interrupt for each byte you could probably override the lackluster implementation by goosing the appropriate counter within the device instance..

Look at the logic the code calling the call-back implements. The source is open and reviewable.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..