当前位置:网站首页>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 */
}
边栏推荐
- [CSDN] C1 training problem analysis_ Part III_ JS Foundation
- Spark cluster installation and deployment
- Leetcode daily question (2090. K radius subarray averages)
- Send mail using WP mail SMTP plug-in
- Flink learning notes (IX) status programming
- Make the most basic root file system of Jetson nano and mount NFS file system on the server
- Jetson nano custom boot icon kernel logo CBOOT logo
- numpy. Reshape() and resize() functions
- SSB Introduction (PbCH and DMRs need to be supplemented)
- Arduino handles JSON data, arduinojson assistant
猜你喜欢
Successful graduation [3]- blog system update...
Development of electrical fire system
LeetCode每日一题(931. Minimum Falling Path Sum)
How does the nr-prach receiver detect the relationship between prembleid and Ta
PolyWorks script development learning notes (4) - data import and alignment using file import
Design and development of biological instruments
CEF下载,编译工程
Hudi quick experience (including detailed operation steps and screenshots)
UCI and data multiplexing are transmitted on Pusch (Part V) -- polar coding
【順利畢業】[1]-遊覽 [學生管理信息系統]
随机推荐
用Redis实现分布式锁
[combinatorics] Introduction to Combinatorics (combinatorial thought 2: mathematical induction | mathematical induction promotion | multiple induction thought)
Runtime.getRuntime().gc() 和 Runtime.getRuntime().runFinalization() 的区别
Desktop icon recognition based on OpenCV
小王叔叔的博客目录【持续更新中】
Leetcode daily question (1024. video sticking)
307. Range Sum Query - Mutable
Common software open source protocols
JMX、MBean、MXBean、MBeanServer 入门
QT qstring:: number apply base conversion
Shell logic case
顺利毕业[2]-学生健康管理系统 功能开发中。。。
Development of fire power monitoring system
Nodemcu-esp8266 development board to build Arduino ide development environment
Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 4 --blinker_ DHT_ WiFi (lighting technology app control + temperature and humidity data app display)
[combinatorics] Introduction to Combinatorics (context of combinatorics | skills of combinatorics | thought of combinatorics 1: one-to-one correspondence)
Nr-prach:prach format and time-frequency domain
Win10 install elk
LeetCode每日一题(2115. Find All Possible Recipes from Given Supplies)
Leetcode daily question (516. long palindromic subsequence)