SLAAE50A January   2022  – October 2022 MSP430FR2533 , MSP430FR2533

 

  1.   Abstract
  2.   Trademarks
  3. 1Introduction
  4. 2Basic Knowledge and Principles of Self-Inductive Capacitive Touch
  5. 3MSP430FR2533 Liquid Level Measurement Application
    1. 3.1 System Design
    2. 3.2 Hardware Design
    3. 3.3 Software Design
    4. 3.4 Test Results
  6. 4Conclusion
  7. 5References
  8. 6Revision History

Software Design

A. Liquid Level Height Calculation

To show level height on the LCD, the application must measure the capacitance value at different liquid level heights. As Equation 6 shows, measure LTA and COUNT, and then calculate the C t o u c h .

Equation 6. C t o u c h = C t o u c h - C b a s e = α * G a i n ( 1 L T A + D e l t a -     1 L T A )

By measuring multiple sets of data, Figure 3-6 shows the relationship between the liquid level height and the capacitance value change. According to the fitting result, the relationship between the liquid level height and the C t o u c h is: Y = 341.5X − 34.249.

GUID-E6FC4AC0-AD6B-481A-BFE0-2A3CEA40D021-low.png Figure 3-6 Correspondence Between Height and Capacitance Change

B. Flow chart

The software design mainly includes three parts: capacitance detection, LCD display liquid level height and I2C communication. Figure 3-7 shows the overall code design flow chart.

GUID-193FCCD5-FAFE-4481-8B4B-4C302CECADBC-low.png Figure 3-7 Overall Code Design Flow Chart

When the program starts, the MCU initializes the IO ports, clock, etc. Then the LCD displays “Start” to indicate that the measurement can be performed. After a short delay, the measurement is started through CAPT_appStart(), and the measurement function is called back in APP_init(). The APP_init() function includes continuously scanning each channel, calculating the height in real time according to the scanned data, and displaying it through the LCD.

C. Calibration and Communication

Communication with the host MCU is recommended for development using the provided UART and I2C library functions. First of all, the default code generated by the GUI will complete IO configuration and clock configuration of the UART (eUSCI_A0) and I2C (eUSCI_B0) in the BSP_configureMCU() function. Therefore, it is only necessary to configure the communication module and write the communication protocol. This design uses the I2C to communicate with the host, which can send commands to perform calibration and receive data from the slave. The specific operation steps are as follows:

  1. Directly modify the definition of CapTIvate_config→CAPT_UserConfig.h→CAPT_INTERFACE , the default is UART, change to I2C communication
  2. Write a custom frame processing function, because I2C send and receive share a 32-byte buffer here, and the receive and send data segment in this buffer has an offset of 3 bytes. Therefore, the fourth byte of the buffer corresponds to the first byte of the received or transmitted data. Table 3-1 shows the communication protocol.
Table 3-1 I2C Communication Protocol
Master Host
pBuffer[0]-[3] Not care
pBuffer[4] = 01 Do calibration
pBuffer[5] = 01 Save height data to pBuffer[6]
pBuffer[7] = 01 Save code version to pBuffer[8]
pBuffer[9] = 01 Bootloader, software update

When the MCU receives the data sent by the host, if the fourth bit of the data is 0x01, the MCU performs calibration. If the fifth bit of the data is 0x01, the height data is stored in pBuffer[6], and the host can read it. If the seventh bit is 0x01, the host can read the version number from pBuffer[8]. If the ninth bit is 0x01, that is for bootloader, the software can be updated.