当前位置:网站首页>Introduction to GPIO
Introduction to GPIO
2022-07-06 23:55:00 【Xiao Hou_ two thousand and twenty-two】
GPIO brief introduction
1. Introduce
GPIO Is the abbreviation of general input and output port , In a nutshell STM32 Controllable pins ,STM32 Chip GPIO Pins are connected to external devices , So as to realize external communication 、 Control and data acquisition functions .STM32 Chip GPIO Divided into many groups , Each group has 16 One pin , If the model is STM32F103VET6 The models of chips have GPIOA、GPIOB、GPIOC to GPIOE common 5 Group GPIO, The chip is a total of 1O0 One pin , among GPIO It's a big part of it , be-all GPIO All pins have basic input and output functions .
The most basic output function is made up of STM32 Control pin output high 、 Low level , Switch control is realized , If you put GPIO Pin into LED The lamp , Then you can control LED The light goes on and off , Pin into relay or triode , Then you can control the on-off of external high-power circuits through relays or triodes .
The most basic input function is to detect the external input level , If you put GPIO Pin to key , Distinguish whether the key is pressed by the level .
1.1 Protection diode and upper 、 Pull down resistance
** The two protection diodes of the pin can prevent too high or too low voltage input outside the pin ,** When the pin voltage is higher than VDD when , The diode above is on , When the pin voltage is below Vss when , The diode below is on , Prevent abnormal voltage from being introduced into the chip and causing the chip to burn . Despite this protection , It doesn't mean that STM32 The pin can be directly connected to the high power driver , Such as direct drive motor , Forced drive or the motor doesn't work , Or cause the chip to burn out , It is necessary to increase the power and isolate the circuit drive .
1.2 P-MOS Tube and N-MOS tube
GPIO The pin line passes through two protection diodes , Up to “ The input mode ” structure , Down to “ The output mode ” structure . Let's look at the output mode section first , The line goes through a road made up of PMOS and N-MOS A cell circuit made up of tubes . This structure makes GPIO Possess “ Push pull output ” and “ Open drain output ” Two modes .
So-called Push pull output mode , It's based on these two MOS Named after the way the tube works .** In this structure, high level is input , After the reverse , At the top of the P-MOS Conduction , At the bottom of the N-MOS close , External output high level ; In this structure, low level is input , After the reverse ,N-MOS The pipe is open ,P-MOS close , External output low level .***** When the pin level switches between high and low , Two pipes turn on ,P The tube is responsible for filling the current ,N The tube is responsible for pulling the current , The load capacity and switching speed are greatly improved compared with ordinary methods .* The low level of push-pull output is 0 v , The high level is 3.3 v , Refer to figure push-pull equivalent circuit for details , It is the equivalent circuit of push-pull output mode .
And in the Open drain output mode when , At the top of the P-MOS It doesn't work at all . If we control the output to be 0, Low level , be PMOS The tube is closed ,N-MOS The pipe is open , Ground the output , If the control output is 1( It can't directly output high level ) when , be P-MOS Tube and N-MOS All the tubes are closed , So the pin neither outputs high level , It doesn't output low level either , It's a high resistance state .
Open drain output is generally used in I2C、SMBUS Communication, etc “ Line and ” Function of the bus circuit
typedef enum
{
GPIO_Mode_AIN = 0x0, // Analog input
GPIO_Mode_IN_FLOATING = 0x04, // Floating input
GPIO_Mode_IPD = 0x28, // Drop down input
GPIO_Mode_IPU = 0x48, // Pull up input
GPIO_Mode_Out_OD = 0x14, // Open drain output
GPIO_Mode_Out_PP = 0x10, // Push pull output
GPIO_Mode_AF_OD = 0x1C, // Reuse open drain output
GPIO_Mode_AF_PP = 0x18 // Multiplexing push pull output
} GPIOMode_TypeDef;
1.3 Lighten up LED The lamp
technological process
1) Can make IO Port clock , By calling :
RCC_ABP2PeriphColckCmd( )
- initialization IO Mouth mode , call :
GPIO_Init( )
- operation IO mouth , Output high and low level
GPIO_SetBits( )
GPIO_ResetBits( )
# In order to increase the portability of the code , Define hardware related macros in bsp_LED.h in
#ifndef _BSP_LED_H
#define _BSP_LED_H
#define LED1_GPIO_CLK RCC_APB2Periph_GPIOA
#define LED1_GPIO_PORT GPIOA
#define LED1_GPIO_PIN GPIO_Pin_8
#define LED2_GPIO_CLK RCC_APB2Periph_GPIOD
#define LED2_GPIO_PORT GPIOD
#define LED2_GPIO_PIN GPIO_Pin_2
#include "stm32f10x.h"
void LED_GPIO_Config(void);
#endif/*_BSP_LED_H*/
LED Initialize configuration
#include "./LED/bsp_led.h"
void LED_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitType_struct_A;
GPIO_InitTypeDef GPIO_InitType_struct_D;
/* Step 1 turn on the peripheral clock */
RCC_APB2PeriphClockCmd(LED1_GPIO_CLK,ENABLE);
RCC_APB2PeriphClockCmd(LED2_GPIO_CLK,ENABLE);
/* The second step is to configure the peripheral initialization structure */
GPIO_InitType_struct_A.GPIO_Pin = LED1_GPIO_PIN;
GPIO_InitType_struct_A.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitType_struct_A.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitType_struct_D.GPIO_Pin = LED2_GPIO_PIN;
GPIO_InitType_struct_D.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitType_struct_D.GPIO_Speed = GPIO_Speed_10MHz;
/* Step 3 call the initialization function , Write the configured structure members to the register */
GPIO_Init(LED1_GPIO_PORT,&GPIO_InitType_struct_A);
GPIO_Init(LED2_GPIO_PORT,&GPIO_InitType_struct_D);
The main program
#include "stm32f10x.h"
#include "./LED/bsp_led.h"
void delay(uint32_t count)
{
for(;count!=0;count--);
}
int main(void)
{
LED_GPIO_Config( );
while(1)
{
GPIO_SetBits(LED2_GPIO_PORT,LED2_GPIO_PIN);
GPIO_ResetBits(LED1_GPIO_PORT,LED1_GPIO_PIN);
delay(0xfffff);
GPIO_SetBits(LED1_GPIO_PORT,LED1_GPIO_PIN);
GPIO_ResetBits(GPIOD,LED2_GPIO_PIN);
delay(0xfffff);
}
}
边栏推荐
- 短链的设计
- GPIO简介
- 11 preparations for Web3 and Decentralization for traditional enterprises
- Laravel8 uses passport authentication to log in and generate a token
- How to answer the dualistic opposition of Zhihu
- How does win11 restore the traditional right-click menu? Win11 right click to change back to traditional mode
- 【自动化测试框架】关于unittest你需要知道的事
- 服务器SMP、NUMA、MPP体系学习笔记。
- PostgreSQL highly available repmgr (1 master 2 slave +1witness) + pgpool II realizes master-slave switching + read-write separation
- leetcode:236. 二叉树的最近公共祖先
猜你喜欢
STM32通过串口进入和唤醒停止模式
电脑重装系统u盘文件被隐藏要怎么找出来
[automated testing framework] what you need to know about unittest
The programmer refused the offer because of low salary, HR became angry and netizens exploded
零代码高回报,如何用40套模板,能满足工作中95%的报表需求
App general function test cases
Automatic test tool katalon (WEB) test operation instructions
DAY TWO
Gradle knowledge generalization
Basic chart interpretation of "Oriental selection" hot out of circle data
随机推荐
Oracle对表进行的常用修改命令
openresty ngx_lua子请求
Basic chart interpretation of "Oriental selection" hot out of circle data
Gradle knowledge generalization
leetcode:236. 二叉树的最近公共祖先
[automated testing framework] what you need to know about unittest
The intranet penetrates the zerotier extranet (mobile phone, computer, etc.) to access intranet devices (raspberry pie, NAS, computer, etc.)
DAY FOUR
Without CD, I'll teach you a trick to restore the factory settings of win10 system
How about the order management of okcc call center
Résumé des connaissances de gradle
【精品】pinia 基于插件pinia-plugin-persist的 持久化
app通用功能测试用例
Server SMP, NUMA, MPP system learning notes.
Use Yum or up2date to install the postgresql13.3 database
Win11怎么恢复传统右键菜单?Win11右键改回传统模式的方法
DAY SIX
达晨史上最大单笔投资,今天IPO了
Compile logisim
Unity 颜色板|调色板|无级变色功能