Implementation of I2C interrupt-based APIs
The code for MasterSendDataIT API is shown in Figure 1.
Steps of implementation:
1. Save all the details into the header, as shown in Figure 2.
2. Trigger the start condition (Figure 3). When the start condition is triggered, the SB or start bit will be set to 1, causing an interrupt. After that, sending other data like address phase and other things will be taken care of by the interrupt service routine or ISR.
3. Enable all the required control bits, as shown in Figure 4.
Look at Figure 5. The first interrupt which is going to be triggered in this case will be SB interrupt. Therefore, the SB flag will be set, and since the control bit ITEVFEN is already enabled, the interrupt will be triggered on the IRQ number 31, and the interrupt handler will handle the triggered interrupt.
After completing the interrupt phase, you can send other data like addresses and other things.
The I2C_MasterReceiveDataIT is similar to master send data, but the difference is you have to mention the RX buffer instead of the TX buffer and set the state to I2C_BUSY_IN_RX, as shown in Figure 5.
4. Compile the code to confirm whether the build is proper or not.
Observe Figure 6, the compilation is successful, and there are no errors in the code.
In the following article, let’s see I2C IRQ handler implementation.
FastBit Embedded Brain Academy Courses
Click here: https://fastbitlab.com/course1