当前位置:网站首页>[basic course of flight control development 1] crazy shell · open source formation UAV GPIO (LED flight information light and signal light control)
[basic course of flight control development 1] crazy shell · open source formation UAV GPIO (LED flight information light and signal light control)
2022-07-26 16:49:00 【efans_ Mike】
COCOFLY course
—— Crazy shell · UAV series
GPIO(LED Flight information light 、 Signal light control )
chart 1
One 、LED
1.1LED brief introduction
LED(Light Emitting Diode) It is the abbreviation of light emitting diode .LED It is a very common lighting device in life .LED There are many kinds of forms in our life , As shown in the figure below .
chart 2

chart 3
Even though LED There are many forms in our life , But all this LED In the circuit, the symbols shown in the figure below are used to represent .
chart 4
1.2LED The principle of luminescence
LED The most important light-emitting structure is the lamp beads as big as mung beans . Although its volume is very small , But it has heaven and earth inside , As shown in the figure below LED Internal construction .
chart 5
This structure is extremely complex , It is divided into several layers : The top layer is called P Type semiconductor layer 、 The middle layer is a light-emitting layer 、 The lowest layer is called N Type semiconductor layer .
Understand from the perspective of Physics : When the current passes through the chip ,N The electrons in a semiconductor are related to P The holes in A-type semiconductor collide and recombine violently in the light-emitting layer to produce photons , Emit energy in the form of photons ( The light you see ).
Two 、GPIO
2.1GPIO brief introduction
GPIO(General-purpose input/output), Short for general input and output , The pins of the single chip microcomputer can be used freely by users , Can be configured to output , It can also be configured as input . The output can be output “ High level ” perhaps “ Low level ”. In electronic circuits “ High level ” The voltage is high , Represented by logic is 1,“ Low level ” The voltage is low , Represented by logic is 0.
STM32F103 Series is based on ARM Cortex M3 Kernel 32 Bit MCU , The main core used in flight control is 48 Foot's STM32F103CBT6, Its pins are shown in the figure below .
chart 6
STM32F103CBT6 Of GPIO More functions , Yes A、B、C、D Wait for four groups GPIO, Each group GPIO All ports can be used as output ports except , It can also be used as a multiplexing pin , For example, serial port 、I2C、SPI And other special interface pins . However, it should be noted that the multiplexing function of each pin is limited , Therefore, it is necessary to pay attention to the multiplexing function of each pin when connecting the hardware , This can be STM32F103 In the data book of .GPIO There are altogether 8 Patterns , Respectively : Floating input , Pull up input , Drop down input , Analog input , Open drain output , Push pull output , Push pull multiplexing , Open drain multiplexing function , As shown in the following table .
STM32F103GPIO Working mode
chart 7
this 8 We won't introduce the functions one by one , If you are interested, you can search the Internet to find out , Here we mainly explain the difference between open drain output and push-pull output .
(1) Open drain output :
The output is equivalent to the collector of triode . You need to pull up the resistor to get a high level , Use the driving ability of external pull-up resistor , Reduce IC Internal drive , Strong driving power , It is suitable for current drive , Accessible 20mA.
(2) Push pull output :
Can output high , Low level , Connect digital devices , It consists of two triodes with the same parameters or MOSFET Connect in push-pull mode , They are responsible for the amplification of positive and negative half cycle waveforms . When the circuit is working , Only one of the two symmetrical power switches is on at a time , So the conduction loss is small 、 Efficient , Both improve the load capacity of the circuit , And increase the switching speed .
To sum up : The push-pull output can output strong high and low levels , Connect digital devices ; The open drain output can only output low level , The high level depends on the external resistance . The output is equivalent to the collector of triode , To get a high level state, you need to pull up the resistor , It is suitable for current drive , Its ability to absorb current is relatively strong ( commonly 20ma within ).
2.2GPIO Related registers
STM32F103 Each GPIO Ports have : Two 32 Bit configuration register (GPIOx_CRL and GPIOx_CRH)、 Two 32 Bit data register (GPIOx_IDR and GPIOx_ODR)、 One 32 Position position / Reset register (GPIOx_BSRR)、 One 16 Bit reset register (GPIOx_BRR)、 One 32 Bit lock register (GPIOx_LCKR).
(1)GPIOx_CRL register (x=A~G)
chart 8
This register is used for configuration IO0~7 Input / output mode and rate setting .
(2)GPIOx_CRH register (x=A~G)
chart 9
This register is used for configuration IO8~15 Input / output mode and rate setting .
(3)GPIOx_IDR register (x=A~G)
chart 10
IDR yes GPIO Input data register . adopt IDR Registers can be read IO The state of . It should be noted that IDR Registers can only be written in words (16 position ) Read out in the form of .
(4)GPIOx_ODR register (x=A~G)
chart 11
ODR yes GPIO The output data register of . adopt ODR Registers can output high and low levels .
(5)GPIOx_BSRR register (x=A~G)
chart 12
BSRR yes GPIO Port bit setting of / Clear register .BSRR The height of the register 16 Bit is clear IO position , low 16 Bit is set IO position . It should be noted that BSRR Only writing 1 When , Only the corresponding function works , write in 0 It's invalid .
(6)GPIOx_BRR register (x=A~G)
chart 13
BRR yes GPIO Port bit clear register .BRR The foundation is only written 1 When , Only the corresponding function works , write in 0 Invalid .
(7)GPIOx_LCKR register (x=A~G)
chart 14
LCKR yes GPIO Port configuration lock register for .LCKR Registers are used to lock IO Port configuration , After setting , It cannot be configured except after reset IO The state of .
2.3GPIO experiment
The content of this experiment is to periodically light the flight information lights and signal lights of the UAV , Among them, the flight information light is under the four propellers , And the signal lights are on both sides of the switch .
Looking at the schematic diagram, we can know that the flight information lights of the UAV are connected to NPN triode Q1 On , And the base of the triode is connected to the single chip microcomputer PA8 On ; Two signal lights are connected to PC13 and PC14 On .
chart 15

chart 16
chart 17
The idea of writing code is shown in the following table
chart 18
Follow the code idea , Write code ( By calling the official library ) As shown in the figure below :
chart 19
chart 20
After completing the configuration, you only need to turn on and off periodically LED that will do .
chart 21
The delay is shown in the figure below .
chart 22
preservation 、 compile 、 download , As shown in the figure below ,1 For preservation ,2 To compile ,3 Download for .
chart 23
Download the code to the flight control , You can see the flight control LED The indicator light and the navigation light under the four propellers flicker periodically , As shown in the figure below .
chart 24
边栏推荐
- PXE efficient batch network installation
- The process and harvest of developing browser plug-ins with clojurescript
- How can win11 system be reinstalled with one click?
- 2022 Niuke summer multi school training camp 1 (acdgij)
- “青出于蓝胜于蓝”,为何藏宝计划(TPC)是持币生息最后的一朵白莲花
- NUC 11 build esxi 7.0.3f install network card driver-v2 (upgraded version in July 2022)
- mysql锁机制(举例说明)
- Digital currency of quantitative transactions - merge transaction by transaction data through timestamp and direction (large order consolidation)
- Replicationcontroller and replicaset of kubernetes
- About the idea plug-in I wrote that can generate service and mapper with one click (with source code)
猜你喜欢

Win11 auto delete file setting method

工作流引擎在vivo营销自动化中的应用实践
![[express receives get, post, and route request parameters]](/img/6c/ac936a8dff50b803993bef5192723b.png)
[express receives get, post, and route request parameters]

如何保证缓存和数据库一致性

Current limiting comparison: how to choose sentinel vs hystrix?

Oracle创建表分区后,查询的时候不给出partition,但是会给分区字段指定的值,会不会自动按照分区查询?

什么是分布式定时任务框架?

Matlab paper illustration drawing template issue 40 - pie chart with offset sector

Comprehensive design of an oppe homepage -- Design of navigation bar

IDEA 阿里云多模块部署
随机推荐
A firefox/chrome plug-in that visualizes browser history
Marxan model, reserve optimization and protection vacancy selection technology, application in invest ecosystem
研发效能的道与术 - 道篇
Chapter 1 Overview - Section 1 - 1.3 composition of the Internet
【飞控开发基础教程2】疯壳·开源编队无人机-定时器(LED 航情灯、指示灯闪烁)
Using MySQL master-slave replication delay to save erroneously deleted data
Win11 how to close a shared folder
NUC 11 build esxi 7.0.3f install network card driver-v2 (upgraded version in July 2022)
MVC和ECS两种设计架构的初浅理解
2022 software testing skills postman+newman+jenkins continuous integration practical tutorial
Re8: reading papers Hier spcnet: a legal stat hierarchy based heterogeneous network for computing legal case
How to use C language nested linked list to realize student achievement management system
营销指南 | 几种常见的微博营销打法
40个高质量信息管理专业毕设项目分享【源码+论文】(六)
C#转整型的三种方式的区别以及效率对比
Acl-ijcai-sigir top conference paper report meeting (AIS 2022) Note 3: dialogue and generation
【开发教程7】疯壳·开源蓝牙心率防水运动手环-电容触摸
工作流引擎在vivo营销自动化中的应用实践
What does it mean to lock financial products regularly? Can financial products be redeemed during the lock-in period?
2022-2023 topic recommendation of information management graduation project