STM32 I2C Lecture 40: I2C handle structure modification

  • Post author:
  • Post category:Blog

 

I2C handle structure modification

 

 


In this article, let’s develop master send data API with interrupt and master receive data API with interrupt. The master send data, and the master receive data APIs that we develop now are the interrupt flavors or non-blocking flavors of APIs developed in earlier parts.

Similar to what we have done in the SPI section, here also modify the handle structure (Figure 1) to store various data like other transmission buffer addresses, received buffer addresses, length information, the slave address information, etc.

I2C handle structure modification
Figure 1. Modifying handle structure to store placeholder variables.

 

The handle structure must be modified according to the information in Figure 1.

Remember that, unlike SPI, the I2C is half-duplex communication. Therefore, in I2C, only one variable is enough to store the transmission and reception state, and it is combinely called TxRxState, as shown in Figure 1. Because in I2C, you cannot receive data while transmitting, and even it is not possible to transmit the data while receiving. The application states may be I2C_READY, I2C_BUSY_IN_RX, or I2C_BUSY_IN_TX.

Look at Figure 1,

  • Variable pTxBuffer is used to hold the application’s TX buffer address.
  • Variable pRxBuffer is used to hold the application’s RX buffer address.
  • TxLen and RxLen variables are used to store the length information.
  • Variable DevAddr is used to store a slave or device address.
  • RxSize variable is used to store the Rx size. We will discuss the detailed description of this variable while implementing the ISR.
  • The variable called Sr or repeated start is used to store the information about the repeated start.

Now change the handle structure according to the structure shown in Figure 1 and include all these member elements. 

In the following article, let’s see I2C adding interrupt related macros and interrupt APIs .

 

Get the Full Course on I2C Here.

FastBit Embedded Brain Academy Courses,

Click here: 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.