STM32-Serial Port Method

Experimental preparation

  1. STM32 motherboard

  2. 8-channel patrol module

  3. Several Dupont cables

STM32 needs to download the serial communication source code provided in the document

Experimental purpose

The content of this experiment is mainly to use the STM32 master to receive the data of the 8-channel patrol module through the serial port.

Experimental wiring

STM32 to serial port assistant If you are not using the black stm32 of Yabo, you need to use a usb to ttl module to connect to the computer. The wiring is described in the following table

stm32usb to ttl
PA10TX
PA9RX
vccvcc
GNDGND
If you are using the Yabo black stm32, you can directly use type-c to connect to the computer's serial port assistant 
STM328-channel line patrol module
PA2RX
PA3TX
5V5V
GNDGND

As shown in the figure: image-2024110100001

Experimental steps and phenomena

  1. After connecting the wires, open the serial port assistant and you can see the numerical data of the infrared module. Set the baud rate to 115200. As shown below

image-2024110100002

 

Experimental source code

SET_Eight_Mode(0,0,1);:The first parameter of this function is the calibration mode (0: exit calibration mode 1: enter calibration mode) The second parameter is whether to receive analog data The third parameter is whether to receive numerical data. This routine only provides parsing of numerical data. If you need to parse analog data, you can parse it yourself according to the protocol. The serial port parsing file of this project also has a function for parsing analog values. You can refer to it and call the Deal_Usart_AData function.