当前位置:网站首页>GPIO port details, Hal library operation keys
GPIO port details, Hal library operation keys
2022-07-03 09:41:00 【two thousand and twenty-one point zero nine】
This blog knowledge comes from Mr. Wei Dongshan's 7 Internet of things course .
One 、GPIO Detailed explanation
1、STM32F103C8T6 Altogether 48 One pin .
2、 Press A、B、C grouping , Each group 16 One pin , The number is 0~15,STM32F103C8T6 Yes 2 Group GPIO, Each group has 16 One pin , namely 32 individual GPIO Pin .
3、GPIO Working mode
STM32F103 Series of I/O The pins share 8 Working mode , There are four output modes : Push pull output 、 Open drain output 、 Multiplexing push pull output 、 Reuse open drain output ; There are four input modes : Pull up input 、 Drop down input 、 Floating input 、 Analog input .
- Push pull output ( Push-Pull, PP)

The push-pull structure consists of two MOS The tubes are connected in a complementary and symmetrical manner , At any time, one of the triodes is always on , The other triode is off . Pictured above 1 Shown , The interior consists of a P-MOS Tube and a N-MOS Tube composition , Two MOS The grid of the tube ( Gate, G) To the left “ Output control ” , Drain electrode ( Drain, D) Connected to external output , P-MOS The source of the tube ( Source, S) Receive VDD( 3.3V),N-MOS The source of the tube is connected to Vss( 0V).
MOS The tube is used as a switch ,“ Output control ” To two MOS Apply a certain voltage to the tube grid , P-MOS Conduction between the source and drain of the tube ,VDD after P-MOS Tubular S->G->D Output , N-MOS The tube is in a high resistance state ( The resistance is very high , Approximate open circuit ), The overall external is high level ;“ Output control ” Cancel to two MOS Apply voltage to the tube grid , P-MOS Tube source and grid cut-off , P-MOS The tube is in a high resistance state , N-MOS The source and drain of the tube are connected , The overall external is low level .
MOS The tube is used as a switch ,“ Output control ” To two MOS Apply a certain voltage to the tube grid , P-MOS Conduction between the source and drain of the tube ,VDD after P-MOS Tubular S->G->D Output , N-MOS The tube is in a high resistance state ( The resistance is very high , Approximate open circuit ), The overall external is high level ;“ Output control ” Cancel to two MOS Apply voltage to the tube grid , P-MOS Tube source and grid cut-off , P-MOS The tube is in a high resistance state , N-MOS The source and drain of the tube are connected , The overall external is low level .
- Open drain output ( Open-Drain, OD)

In open drain mode ,“ Output control ” Will not control P-MOS tube , “ Output control ” Only to N-MOS Apply a certain voltage to the tube grid , Two MOS All tubes are in the cut-off state , The two drains are suspended , It's called open drain .“ Output control ” Cancel the applied voltage of the grid , PMOS The tube is still in the high resistance state , N-MOS The pipe is open , The overall external is low level .
The open drain output mode can be equivalent to P-MOS The tube is regarded as nonexistent . That is, only low level can be output in this mode , To output high level , External resistance is required , The connected resistance is called pull-up resistance , At this time, the output level depends on the external power supply voltage of the pull-up resistor , As shown in the figure above, red VCC+ External circuit of resistance .
Push pull output mode can directly output high level , Open drain output mode requires external pull-up resistor to output high level , But the open drain output has some characteristics that the push-pull output does not have :
① Using external circuit driving capability . As shown in the figure above ,“ Output control ” Only a small gate drive current is required , VCC Increase the driving current for the external load through the pull-up resistor ;
② Realize level conversion . The push-pull output mode consists of VDD Provide , That is, only 3.3V level . After using the open drain output mode , VCC It can be for 5V, Thus, the effect of level conversion is realized .
③ Easy to implement “ Logic and ” function . Multiple open drain pins can be used directly together , Connect a suitable pull-up resistor uniformly , Can be realized “ Logic and ” Relationship , That is, when all pins output high level , The output is high level , If any pin outputs low level , Then output low level . stay I2C、 SMBUS And other bus circuits are often used .
VCC Can connect 5V/3.3V, Improve the driving ability of pins , I think the internal structure of the chip is very thin , The current that can pass through is limited , Add a thick circuit outside to connect , It can drive a large current . If VCC yes 5V It can realize the function of level conversion , Because normally ,IO The output is 3.3V.
- Reuse function push-pull / Open drain output ( Alternate Function, AF)
GPIO In addition to being a general-purpose input / The output pin uses an external pin , It can also be used as an on-chip peripheral ( USART、 I2C、 SPI etc. ) Dedicated pin , That is, one pin can be used for many purposes , But one pin can only use one of the multiplexing functions at the same time .
When the pin is set to the multiplexing function , The multiplexed push-pull output mode or multiplexed open drain output mode can be selected , When set to multiplex open drain output mode , It needs to be connected with pull resistance .
- Pull up input mode ( Input Pull-up)

As shown in the figure above , VDD Through the switch 、 Pull up resistance , Connect external I/O Pin . When the switch is closed , external I/O When there is no input signal , The default input is high . The typical application of this mode is the external key , When no key is pressed , MCU The pin of is the determined high level , When the key is pressed , The pin level is pulled to low level .
- Drop down input mode ( Input Pull-down)
As shown in the figure above , Vss Through the switch 、 Pull down resistance , Connect external I/O Pin . When the switch is closed , external I/O When there is no input signal , The default input is low . The typical application of this mode is also the external key , When no key is pressed , MCU The pin of is the determined low level , When the key is pressed , The pin level is pulled high .
- Floating input mode ( Floating Input)
As shown in the figure above , Two up / The pull-down resistance switches are disconnected , Neither pull-up nor pull-down , I/O The pins are connected directly TTL Schottky barrier
trigger , here I/O The pin is floating , The reading level is uncertain , What level is the external signal , MCU The pin inputs what level . MCU Reset after power on , The default is floating input mode .
- Analog input mode ( Analog mode)
As shown in the figure above , Two up / The pull-down resistance switches are disconnected , meanwhile TTL The Schottky trigger switch is also off , The pin signal is directly connected to the analog input , Realize the acquisition of external signals .
Two 、cubeMX Set up GPIO
1、 Choose one first GPIO, The choice here is PA1 For export .
2、 Click on the left GPIO.
3、 Click... In the middle PA1 Options , Then you can set PA1 Detailed parameters of .

4、 Here you can set the default output level 、 The output mode 、 Whether to pull up or down 、 The frequency of the clock is high, medium and low .

5、 It can be for PA1 Set an alias , Here we take LED. In the code, it is shown as : stay mian() find MX_GPIO_Init(), And then right-click go to definition, You can find it .


3、 ... and 、cubeMX Operate the buttons
1、 Hardware analysis of keys


The mechanical key will shake during pressing , So there will be hardware anti jitter and software anti jitter , The hardware anti jitter is the capacitance in the figure above .
2、cubeMX Generate engineering framework
PA0 Select input mode , Because for hardware pull , So you don't have to choose up and down . When the default key is released ,IO Read as high level , When the key is pressed ,IO Read low .
PA1 Set as output , control LED The lamp .

3、keil Some control logic
stay main() Functional while In circulation , Write control logic , Time delay is set 8ms Software De chattering . Press the key to press LED Extinguish , Release to LED bright .
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0) == GPIO_PIN_RESET)
{
HAL_Delay(8);
if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0) == GPIO_PIN_RESET)
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_1,GPIO_PIN_SET);
}
else
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_1,GPIO_PIN_RESET);
}
}
}
/* USER CODE END 3 */
}边栏推荐
- Definition and use of enum in C language
- [csdn] C1 analyse des questions de formation Partie III Bar _ JS Foundation
- Flink CDC practice (including practical steps and screenshots)
- Vscode Arduino installation Library
- Analysis of the implementation principle of an open source markdown to rich text editor
- Desktop icon recognition based on OpenCV
- LeetCode每日一题(2090. K Radius Subarray Averages)
- Jetson nano custom boot icon kernel logo CBOOT logo
- Leetcode daily question (931. minimum falling path sum)
- [male nanny style] teach you to open the first wechat applet
猜你喜欢

Electronic product design, MCU development, circuit cloning

LeetCode每日一题(2212. Maximum Points in an Archery Competition)

About the configuration of vs2008+rade CATIA v5r22

Analysis of the implementation principle of an open source markdown to rich text editor

Arduino handles JSON data, arduinojson assistant

MySQL data manipulation language DML common commands
![【順利畢業】[1]-遊覽 [學生管理信息系統]](/img/91/72cdea3eb3f61315595330d2c9016d.png)
【順利畢業】[1]-遊覽 [學生管理信息系統]

Solve editor MD uploads pictures and cannot get the picture address

数字身份验证服务商ADVANCE.AI顺利加入深跨协 推进跨境电商行业可持续性发展

Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 3 --blinker_ MIOT_ Light (lighting technology app control + Xiaoai classmate control)
随机推荐
About the configuration of vs2008+rade CATIA v5r22
Runtime.getRuntime().gc() 和 Runtime.getRuntime().runFinalization() 的区别
Error output redirection
PolyWorks script development learning notes (II) -treeview basic operations
Directory and switching operation in file system
1922. Count Good Numbers
解决Editor.md上传图片获取不到图片地址问题
PolyWorks script development learning notes (III) -treeview advanced operation
LeetCode每日一题(2115. Find All Possible Recipes from Given Supplies)
[combinatorics] Introduction to Combinatorics (context of combinatorics | skills of combinatorics | thought of combinatorics 1: one-to-one correspondence)
Common software open source protocols
DSP data calculation error
Getting started with shell programming
Code word in NR
Leetcode daily question (2109. adding spaces to a string)
顺利毕业[2]-学生健康管理系统 功能开发中。。。
QT sub window is blocked, and the main window cannot be clicked after the sub window pops up
Successful graduation [3]- blog system update...
JMX、MBean、MXBean、MBeanServer 入门
LeetCode每日一题(745. Prefix and Suffix Search)