STM32 I2C Lecture 22: Implementation of I2C master sending data API: Part 5

  • Post author:
  • Post category:Blog

 

Implementation of I2C master sending data API:Part 5

 

 


Testing I2C MasterSendData() API:

Before testing the code, build the code to check whether we encounter any error or not.

  • Save the file.
  • Right-click on the project and select the build project option to build the project.
  • There are a couple of errors, as shown in Figure 1. 

 

Implementation of I2C master sending
Figure 1. Errors encountered while building the project.

 

The problem is with the I2C driver.h, there are no include guards. The include guards prevent the inclusion of multiple definitions during the preprocessor stage of the compilation. It prevents the multiple inclusion of the header file contents. Whenever you create a header file, the include guards will be added automatically by the eclipse. But for I2C, there are no include guards. If you face the same problem, then add the no include guards in the I2C driver.h file, as shown in Figure 2. At the end of the program, add #endif.

 

Implementation of I2C master sending- I2C MasterSendData() API
Figure 2. Code to add no include guards in I2C driver.h file.

 

  • Compile once again. There is another error called redefinition of dummyRead. Remove the redefinition shown in Figure 3.
Implementation of I2C master sending-I2C MasterSendData() API
Figure 3. Redefinition of dummyRead.

 

  • Then compile once again, now the code is compiled successfully (Figure 4).
I2C MasterSendData() API
Figure 4. Code is compiled successfully without any error.

 

FastBit Embedded Brain Academy Courses

https://fastbitlab.com/course1

 

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.