当前位置:网站首页>[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
边栏推荐
- 我的sql没问题为什么还是这么慢|MySQL加锁规则
- Re7: reading papers fla/mlac learning to predict charges for critical cases with legal basis
- 极大似然估计
- How to use C language nested linked list to realize student achievement management system
- Alibaba Cloud Toolkit —— 项目一键部署工具
- Marxan model, reserve optimization and protection vacancy selection technology, application in invest ecosystem
- [arm learning (9) ARM compiler understanding learning (armcc/armclang)]
- Re8: reading papers Hier spcnet: a legal stat hierarchy based heterogeneous network for computing legal case
- Comprehensive design of an oppe homepage -- Design of navigation bar
- 数字化转型怎么就那么的难?!
猜你喜欢

【开发教程8】疯壳·开源蓝牙心率防水运动手环-三轴计步伐

【Flutter -- 进阶】打包

Use verdaccio to build your own NPM private library

数字化转型怎么就那么的难?!

How to write unit tests

操作系统迁移实战之在openEuler上部署MySQL数据库
![[arm learning (9) ARM compiler understanding learning (armcc/armclang)]](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[arm learning (9) ARM compiler understanding learning (armcc/armclang)]

Win11 how to close a shared folder

TCP 和 UDP 可以使用相同端口吗?

【飞控开发基础教程2】疯壳·开源编队无人机-定时器(LED 航情灯、指示灯闪烁)
随机推荐
Win11自动删除文件设置方法
Threads and processes
Guangzhou Municipal Safety Committee Office issued warnings and reminders on safety precautions in hot weather
如何借助自动化工具落地DevOps|含低代码与DevOps应用实践
Who is safe to open the VIP account of CICC securities?
MySQL lock mechanism (example)
Tcpdump命令详解
抓包与发流软件与网络诊断
Guetzli simple to use
TDengine 落地协鑫能科,数百亿数据压缩至 600GB
[arm learning (9) ARM compiler understanding learning (armcc/armclang)]
2022 Niuke summer multi school training camp 2 (bdghjkl)
极大似然估计
Response对象-响应字符数据
微信小程序---网络数据请求
该怎么写单元测试呢
快速学会配置yum的本地源和网络源,并学会yum的使用
srec_cat 常用参数的使用
Detailed explanation of tcpdump command
搭建typora图床