I2C Interrupts
i2c_rec[10] = { 0 };
the data i send from the software is 11 22 33 44 55 66 66 77 88 99. This should be received in the i2c_rec.
Please let me know the difference of the above 4 cases.
I2C is very slow in microcontroller terms. The processor could do thousands of machine instructions in the time it takes to do an I2C transfer.
The “base” functions (without _IT, without _DMA) are ”blocking” - they do not return until the requested action is complete. During the transfer the processor is largely sitting idle.
Where you do have something else for the processor to do at the same time as the slow I2C transfer, you can use the _IT or _ DMA version of the call. The processor will return immediately so you can tell it to do other things. But until you get a callback/interrupt telling you that the I2C transfer is complete, you can’t do anything else with I2C - that bit of hardware is busy.
This should explain why you don’t see all the requested transactions when the first call is an interrupt one. Incidentally I assume those functions return a value. This would normally be HAL_OK but they should give an error code if the I2C is still busy with an earlier transaction.
I should add that I don’t use HAL because I don’t find enough documentation about how to use it. My needs are rarely close enough to the examples, and automatically-generated “help” files give no greater insight than reading the source code.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.