So, does HAL_I2C_Slave_Receive_IT() need to be called for every byte? I am a little confused because if you set the buffer size to one, wouldn't it just transfer one byte? Also, if this in an interrupt, why do we need to call HAL_I2C_Slave_Receive_IT() in the main loop? Don't we go directly to the function call back?
You would have to call it for every byte, yes, because you don't know the length of the i2c packet. Once you receive the one byte, then you decide if you need to receive more or not.
May also be possible to call it once set to the length of your shortest length packet, and then receive more if needed.
HAL_I2C_Slave_Receive_IT() is called to:
- Check i2c peripheral has been setup
- Set up HAL internal locks and mode tracking, etc.
- Enable i2c interrupt
There is a lot of housekeeping its doing. Sure some of that stuff is not useful to you, but thats the cost of ease of use.
If that doesn't work for you, then you will need to write your own interrupt functions to handle incoming data.