我是靠谱客的博主 火星上嚓茶,这篇文章主要介绍GPIO描述及应用GPIO是什么解析程序实现,现在分享给大家,希望可以做个参考。

GPIO

  • GPIO是什么
  • 解析
  • 程序实现

GPIO是什么

GPIO(general porpose intput output):通用输入输出端口的简称。功能类似8051的P0—P3,其接脚可以供使用者由程控自由使用,PIN脚依现实考量可作为通用输入(GPI)或通用输出(GPO)或通用输入与输出(GPIO),如当clk generator, chip select等。

解析

需要使用GPIO先要对其进行初始化
下面展示 GPIO初始化结构体。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
typedef struct { uint16_t GPIO_Pin; /*!< Specifies the GPIO pins to be configured. This parameter can be any value of @ref GPIO_pins_define */ GPIOSpeed_TypeDef GPIO_Speed; /*!< Specifies the speed for the selected pins. This parameter can be a value of @ref GPIOSpeed_TypeDef */ GPIOMode_TypeDef GPIO_Mode; /*!< Specifies the operating mode for the selected pins. This parameter can be a value of @ref GPIOMode_TypeDef */ }GPIO_InitTypeDef;

GPIO_Pin:选择IO口
GPIO_Speed:在输出模式下,配置输出驱动电路的驱动速度(在输入模式下配置速度无意义),芯片内部在输出部分有不同速度的驱动电路,以此适应不同场景对速度和功耗的需求。对于速度的选择应当合适,在低频场景时使用较高速度会增加功耗和干扰。

复制代码
1
2
3
4
5
6
7
typedef enum { GPIO_Speed_10MHz = 1, GPIO_Speed_2MHz, GPIO_Speed_50MHz }GPIOSpeed_TypeDef;

GPIO_Mode:共有八种模式
1.GPIO_Mode_AIN:模拟输入,用于ADC采样。
2.GPIO_Mode_IN_FLOATING :浮空输入用于串口RX
3.GPIO_Mode_IPD :下拉输入
4.GPIO_Mode_IPU :上拉输入
在这里插入图片描述

5.GPIO_Mode_Out_OD :开漏输出
6.GPIO_Mode_Out_PP :推挽输出
7.GPIO_Mode_AF_OD :复用开漏输出
8.GPIO_Mode_AF_PP :复用推挽输出
开漏输出需要外接上拉电阻。

复制代码
1
2
3
4
5
6
7
8
9
10
11
typedef enum { GPIO_Mode_AIN = 0x0, GPIO_Mode_IN_FLOATING = 0x04, GPIO_Mode_IPD = 0x28, GPIO_Mode_IPU = 0x48, GPIO_Mode_Out_OD = 0x14, GPIO_Mode_Out_PP = 0x10, GPIO_Mode_AF_OD = 0x1C, GPIO_Mode_AF_PP = 0x18 }GPIOMode_TypeDef;

程序实现

实现控制led灯亮灭

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void LED_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);//时钟使能 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(GPIOA,&GPIO_InitStructure); } void LED_Control(u16,int state) { if(state == 1{ GPIO_SetBits(GPIOA,GPIO_Pin_1); } else { GPIO_ResetBits(GPIOA,GPIO_Pin_1); } }

最后

以上就是火星上嚓茶最近收集整理的关于GPIO描述及应用GPIO是什么解析程序实现的全部内容,更多相关GPIO描述及应用GPIO是什么解析程序实现内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(73)

评论列表共有 0 条评论

立即
投稿
返回
顶部