STM32 I2C Lecture 19: Implementation of I2C master sending data API: Part 2

  • Post author:
  • Post category:Blog

 

Implementation of I2C master sending data API:Part 2

 

 


Creation of I2C related status flags definitions section to define flag macros:

Instead of writing I2C_TXE_FLAG, write the flag name followed by the flag, as shown in Figure 1. In this case, the flag name is TXE. Naming like this will be helpful because while coding, if we just type I2C_FLAG, then the eclipse will list all the options which are preceding with the word I2C_FLAG.

 

I2C master sending data API
Figure 1. Creation of I2C related status flags.

 

Let’s use a similar naming convention for the flag macros. Create the definitions for all the flags, as shown in Figure 2.

I2C master sending data API
Figure 2. Code to create the definitions for all the flags.

 

The master has to wait till the I2C_GetFlagStatus function returns  1. The while statement is used for this purpose, as shown in Figure 3.

I2C master sending data API
Figure 3. Code to make the master wait till the I2C_GetFlagStatus () returns 1.

 

Implement I2C_GetFlagStatus () in the I2C driver.c file, as shown in Figure 4.

Implementation of I2C master sending data API
Figure 4. Code to implement I2C_GetFlagStatus ().

 

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.