当前位置:网站首页>[flight control development basic tutorial 3] crazy shell · open source formation UAV - serial port (basic transceiver)
[flight control development basic tutorial 3] crazy shell · open source formation UAV - serial port (basic transceiver)
2022-07-26 16:49:00 【efans_ Mike】
COCOFLY course
—— Crazy shell · Unmanned aerial vehicle (uav) · series
A serial port ( Basic transceiver )

chart 1
One 、 Serial port introduction
In the field of embedded development, serial port usually refers to UART,UART That is, universal asynchronous transceiver (Universal Asynchronous Receiver/Transmitter). It's a universal serial data bus , For asynchronous communication . The bus communicates in both directions , Can achieve full duplex transmission and reception .
UART It is often used for data transmission between two single-chip computers , As shown in the figure below .
chart 2
The communication process is shown in the figure below .
chart 3
STM32F103 Provides 3 Serial port , Support synchronous single line communication and half duplex single line communication 、 Support LIN、 Support modem operation 、 Smart card protocol and IrDA SIR ENDEC standard 、 have DMA etc. . The pins that can be configured as serial ports are limited , Therefore, when designing the hardware circuit, we need to pay attention to which pins can be configured as serial port pins , As shown in the following table .
Serial port pin mapping
chart 4
Two 、UART Serial communication protocol
In the process of serial communication, a frame of data contains the start bit 、 Data bits 、 Stop bits and optional parity bits , In addition to knowing these concepts , You also need to understand the concept of baud rate .
(1) Start bit , When no data is sent , The data line is in logic “1” state ; Let's start with a logic “0” The signal , Indicates the start of character transfer ;
(2) Data bits , Immediately after the start bit 8 Data . Start at the lowest level ;
(3) Parity bit , Generally do not use ;
(4) Stop bit , It's usually 1 position ( It can also be 1.5 Bits or 2 position ), High level . As a sign of the end ;
(5) Baud rate , Baud rate indicates the number of symbols transmitted per second , Is a measure of data transfer rate .
As shown in the figure below , It is the frame composition of a frame of serial port data .

chart 5
3、 ... and 、UART Serial port register
STM32F103 There are many registers related to serial port , Here we will only talk about a few important registers .
(1)USART_SR: Status register , As shown in the figure below :
chart 6
The bits that need to be understood are :TXE: Send register is empty ;TC: Send complete ;RXNE: The read data register is not empty ;ORE: Overflow error ;FE: Frame error ;PE: Parity error .
(2)USART_DR: This register has only low 8 Bit effective , And it has read and write operations , Whether the data in this register is to be sent or received depends on the operation performed “ Read ” still “ write in ”. As shown in the figure below :
chart 7
(3)USART_BRR: Baud rate register , Used to set the baud rate of serial communication , As shown in the figure below :
chart 8
The corresponding value will be set in the register ,DIV_Mantissa[11:0] Used to set the integer part of the frequency division coefficient ,DIV_Fraction[3,0] Used to set the fractional part of the frequency division coefficient .
The baud rate calculation formula of serial port is as follows :
The formula 1
there fPCLKx(x=1、2) It's a clock for peripherals (PCLK1 be used for USART2、3、4、5, PCLK2 be used for USART1, here STM32F103CBT6 No serial port, no explanation ).USARTDIV Is an unsigned floating-point number . Assume that the baud rate of the serial port is 115200, Serial port is used 1, The clock of the serial port is PCLK2 The clock of ( namely APB2 Bus clock ) by 72MHz, As shown in the figure below .
chart 9
According to the formula, we can get :
USARTDIV=72000000/(115200*16)=39.0625
So the decimal part DIV_Fraction=0.0625*16=1=0x01.
Integral part DIV_Mantissa=39=0x27.
Four 、 Serial port basic transceiver experiment
Serial port transceiver experiment use STM32 Serial port 1 namely UART1, Connect the computer through the serial port module , Use the serial port debugging assistant to communicate ,STM32 After receiving the data, send the received data back to the computer . The serial port pin is shown in the figure below :
chart 10
The two serial port pins are respectively connected with PA9 And PA10 Pin to pin , Then we are right PA9 And PA10 Pin and serial port module are configured , Configuration code ( By calling the official library ).
The idea of coding is as follows :
Programming ideas
surface 1
The serial port initialization code is as follows :
chart 11
The serial port interrupt function code is as follows :
chart 12
Set the serial port 1 The baud rate of is 115200, The code is as follows :
chart 13
preservation 、 compile 、 Download code , Put the on the flight control USART1 Unplug the connected visual module first , Then connect. USB Serial port module , As shown in the figure below :
chart 14
Then I'm putting USB Plug the serial transfer module into the computer USB mouth , Open the serial port debugging assistant on the computer , Find the corresponding COM mouth ( The premise is that USB Serial port drive ), Set the baud rate to 115200, open , Enter... In the input box of the serial port debugging assistant “www.fengke.club”, Point send , Then you can see that the serial port debugging assistant receives a message from STM32 Postback message of , It's also “www.fengke.club”, As shown in the figure below .
chart 15
More complete learning materials and corresponding open source Suites , Please visit the official website :“ Crazy shell ”
For customized development , Please use the official website “ Crazy shell ” At the bottom of the page “ Contact us ” Make contact
边栏推荐
- 如何保证缓存和数据库一致性
- Vlang's way of beating drums
- Marxan模型保护区优化与保护空缺甄选技术、InVEST生态系统中的应用
- 2022-2023 topic recommendation of information management graduation project
- 广州市安委办发布高温天气安全防范警示提醒
- 别用Xshell了,试试这个更现代的终端连接工具
- 什么是分布式定时任务框架?
- Threads and processes
- IDEA 阿里云多模块部署
- DTS is equipped with a new self-developed kernel, which breaks through the key technology of the three center architecture of the two places Tencent cloud database
猜你喜欢

Nacos win10 安装配置教程

Re7: reading papers fla/mlac learning to predict charges for critical cases with legal basis

How does win11 automatically clean the recycle bin?

2022牛客暑期多校训练营1(ACDGIJ)

Win11 how to close a shared folder

【飞控开发基础教程3】疯壳·开源编队无人机-串口(基础收发)

营销指南 | 几种常见的微博营销打法

Understanding JS foundation and browser engine

限流对比:Sentinel vs Hystrix 到底怎么选?

Marxan model, reserve optimization and protection vacancy selection technology, application in invest ecosystem
随机推荐
搭建typora图床
带你一分钟了解对称加密和非对称加密
VS2017打开项目提示需要迁移的解决方法
PXE高效批量网络装机
【E-MR】NameNode的错误恢复记录
Response object - response character data
Marxan模型保护区优化与保护空缺甄选技术、InVEST生态系统中的应用
公安部发出暑期旅游客运交通安全预警:手握方向盘 绷紧安全弦
kubernetes之ReplicationController与ReplicaSet
How can win11 system be reinstalled with one click?
接口比较器
Configmap of kubernetes
Singleton mode
A firefox/chrome plug-in that visualizes browser history
What is a distributed timed task framework?
Marxan model, reserve optimization and protection vacancy selection technology, application in invest ecosystem
DTS is equipped with a new self-developed kernel, which breaks through the key technology of the three center architecture of the two places Tencent cloud database
Marketing guide | several common micro blog marketing methods
Understanding JS foundation and browser engine
TCP 和 UDP 可以使用相同端口吗?