cancel
Showing results for 
Search instead for 
Did you mean: 

HAL I2C example from I2C_TwoBoards_ComIT

achin
Associate II
Posted on February 28, 2017 at 18:59

I am having trouble following the example code as given for the CubeMX

How does it not get stuck in the while(1) loop in the main function? I understand that it is an interrupt, but the only thing that the function call back does is toggle an LED. How else does it know to get out of the infinite loop since everything else is contained in the main function. I see all the stuff for reading the buffer, but it is outside of the while loop.

1 REPLY 1
achin
Associate II
Posted on February 28, 2017 at 20:32

Oh, wait, I see, this is a one shot program, isn't it? It runs once and not again?

Another question I have is with the function call back. It does not accept any a parameters other than the handler. So, If my main thing was to depack a message into a buffer, do I not do that in the function call back? Would I simply do that after HAL_I2C_Slave_Receive_IT() was called?  Wouldn't this essentially be blocking? So, even if you you chose the interrupt version of I2C, you still need to block anyways to unpack your buffer? Also, if I did want to do everything in teh function call back, wouldn't I have to make my buffer variables global?