cancel
Showing results for 
Search instead for 
Did you mean: 

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

NAnto.4
Associate
 
3 REPLIES 3
TDK
Guru

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
Associate

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.

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 Venmo
Up vote any posts that you find helpful, it shows what's working..