STM32 I2C Lecture 50: I2C IRQ handler implementation Part 7

  • Post author:
  • Post category:Blog

 

I2C IRQ handler implementation Part 7

 

 


In this article, let’s learn about the creation of some I2C application events. In the I2C event IRQ handling, we have used the macros for different events (Figure 1), which is not yet created. If you don’t define these macros, then the compiler will issue errors.

I2C IRQ handler implementation Part 7
Figure 1. I2C event IRQ handling.

 

Go to the I2C header file and create I2C application event macros, as shown in Figure 2.

The events we are going to generate from the I2C driver is as follows:

  • I2C_EV_TX_CMPLT
  • I2C_EV_STOP
  • I2C_EV_RX_CMPLT
I2C IRQ handler implementation Part 7
Figure 2. Creation of I2C application event macros.

 

Build the project to check whether there are any errors or not (Figure 3).

I2C IRQ handler implementation Part 7
Figure 3. Building the project.

 

I2C IRQ handler implementation Part 7
Figure 4. Results of compilation.

 

Look at the results of the compilation (Figure 4). There are a couple of problems. Now let’s solve them one by one.

  • We have changed the prototype of the I2C_ClearADDRFlag(). The parameter of this function is changed to an I2C pointer variable. But we didn’t apply these changes to the function call of I2C_ClearADDRFlag() in the driver code. That’s why the compiler issues some errors, as shown in Figure 4. Now let’s go to the I2C driver and search for I2C_ClearADDRFlag (Figure 5). Here the parameter is no longer a base address; therefore, change it to a pointer to the handle, as shown in Figure 6.
I2C IRQ handler implementation Part 7
Figure 5. Search for I2C_ClearADDRFlag.

 

I2C IRQ handler implementation Part 7
Figure 6. Changes made to the I2C_ClearADDRFlag().

 

  • Implicit declaration of I2C_CloseReceiveData: Compiler will issue this error since we have not yet implemented I2C_CloseReceiveData() function.
  • I2CHandle undeclared: The I2CHandle is not a variable; it is a pointer. Therefore, replace I2CHandle with pI2CHandle everywhere in your program (Figure 7).
I2C IRQ handler implementation Part 7
Figure 7. Replacing I2CHandle with pI2CHandle.

 

Again, build the project. Now the code builds successfully. But we have 2 more functions to implement (Figure 8) that is I2C_CloseReceiveData and I2C_CloseSendData.

Figure 8. Warning for the unimplemented functions.

 

FastBitLab

The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.