STM32 微处理器通过 UART 连接传感器。驱动软件使能串口,并采集传感器的实时数据,供应用层软件使用。如图 4-5 所示,温湿度数据采集模块设计自下而上分为四个部分。

第一部分是 UART 驱动程序。这部分是意法半导体提供的 STM32 微处理器 UART 外设控制器的數據读取接口。用于完成 UART 物理层数据获取。

第二部分是传感器驱动程序。驱动程序读取 BSP 中的 UART 接口,缓存温湿度传感器发送到 STM32 的 UART 十六进制数据流。该数据流是持续性输出的,所以传感器驱动程序需要设计一个内存缓冲区缓存数据。

第三部分是传感器数据协议栈。协议栈解析传感器驱动程序缓存的十六进制数据流内容。并根据温湿度传感器数据手册提供的数学换算公式,将十六进制数据换算成实际的温湿度数据信息保存下来。

最后一部分是传感器数据采集任务。该任务线程是一个周期执行的线程任务,以 10 毫秒一个周期,读取协议栈解析完成的温湿度数据。

The STM32 microprocessor is connected to sensors through UART. The driver software enables the UART and collects real-time data from the sensors for use by the application layer software. As shown in Figure 4-5, the temperature and humidity data acquisition module is designed from the bottom up into four parts.

The first part is the UART driver program, which is the data reading interface of the STM32 microprocessor UART peripheral controller provided by STMicroelectronics. It is used to complete the physical layer data acquisition of the UART.

The second part is the sensor driver program. The driver program reads the UART interface in the BSP and caches the hexadecimal data stream sent by the temperature and humidity sensor to the STM32. Since the data stream is continuously output, the sensor driver program needs to design a memory buffer to cache the data.

The third part is the sensor data protocol stack. The protocol stack parses the hexadecimal data stream content cached by the sensor driver program. According to the mathematical conversion formula provided in the temperature and humidity sensor data manual, it converts the hexadecimal data into actual temperature and humidity data information and saves it.

The last part is the sensor data acquisition task. This task thread is a cycle execution thread task with a period of 10 milliseconds. It reads the temperature and humidity data parsed by the protocol stack at the end of each cycle.

STM32 微处理器通过 UART 连接传感器:驱动软件和数据采集

原文地址: https://www.cveoy.top/t/topic/lN8A 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录