I2C error IRQ handler implementation
In this article, let’s learn about the implementation of I2C_ER_IRQHandling.
Exercise:
1. Download the file (Figure 1) attached to the resource section.
2. In the downloaded file, the code is partially written, and it contains some comments (Figure 2), according to which you have to implement the code.
3. Steps for implementation:
- When the I2C error IRQ handling (I2C_ER_IRQHandling()) is called first, you need to check what kind of error has happened.
- Check for the bus error by checking the bus error flag in the status register 1 (Figure 3). If it is set, then clear the bus error flag, then notify the application about the error by calling the I2C_ApplicationEventCallback(), and the event I2C_ERROR_BERR is passed as a parameter of I2C_ApplicationEventCallback(), as shown in Figure 3. BERR is nothing but a bus error.
- The procedure to clear the bus error flag is given in the document itself. Check the BERR flag of the status register 1 shown in Figure 4.
If the BERR flag is set, then it means that misplaced start or stop condition. This flag is set by the hardware when the interface detects an SDA’s rising or falling edge while SCL is high, occurring in a non-valid position during a byte transfer, and the hardware will not clear it automatically. The software clears it. But this flag will get cleared automatically when you disable the peripheral (PE=0).
- The bus error flag is cleared, as shown in Figure 5.
- Similar things you have to do for other errors.
- Copy the definition of all the event flags which will be sent to the application (Figure 6) and paste it into the header file driver.h, as shown in Figure 7.
In the following article, let’s do the exercise :Testing I2C interrupt APIs.
FastBit Embedded Brain Academy Courses
Click here: https://fastbitlab.com/course1