6. SBUS model airplane remote control6.1. Experimental purpose6.2. Configure pin information6.3. Analysis of experimental flow chart6.4. Core code interpretation6.5. Hardware connection6.6. Experimental effect
Using STM32 serial port communication, the SBUS protocol data transmitted by remote control transmitter of aircraft model is analyzed, and the values of each channel are printed.
Change the mode of serial port 2 to Asynchronous synchronous communication, the baud rate is 100000, the data width is 9 bits, the check is Even, and the stop bit is 2 bits. Serial port 2 Only uses the receiving function, so the Data Direction can be Receive and Transmit or Receive Only.
Open the serial port 2 interrupt Settings.
Add the following content to bsp_uart.c:
USART1_Init(): initializes content related to the serial port and enables serial ports 1 and 2 to receive one data.
In the serial port interrupt callback, check whether data is received from serial port 2 and determine whether data is received from serial port 1 or serial port 2.
Create bsp_sbus.h and bsp_sbus.c files to manage sbus data parsing. Create the following in bsp_sbus.h:
SBUS_ALL_CHANNELS controls the number of channels to be resolved. By default, only eight channels are displayed, and if full channels are required, the value is changed to 1.
4.SBUS_Reveive(data) receives serial port data as cache. If it conforms to SBUS communication protocol, a frame data is updated to sbus_data array.
According to the data from the analytical sbus_data SBUS communication protocol.
The SBUS_Handle() function is looped in Bsp_Loop() to print the parsed data of each channel through the serial port.
Because SBUS communication needs to connect the SBUS receiver to the SBUS interface on the expansion board, S is connected to the signal, V is connected to the positive terminal of the power supply, and G is grounded. Therefore, you need to bring your own model remote control and SBUS receiver, pair them well in advance and turn on the power switch.
After the program is burned, the LED light flashes every 200 milliseconds, the expansion board is connected to the computer through the micro-USB data cable, and the serial port assistant is opened (specific parameters are shown in the figure below). You can see that the serial port assistant has been printing the data of each channel of the model airplane remote control. When we manually flip the rocker or button of the model airplane remote control, the data will change.