GPIO_Init函数

GPIO_Init函数:

void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)

功能描述: 根据GPIO_InitStruct中指定的参数初始化外设GPIOx寄存器
输入参数1: GPIOx:x可以是A,B,C,D或者E,来选择GPIO外设
输入参数2: GPIO_InitStruct:指向结构GPIO_InitTypeDef的指针,包含了外设GPIO的配置信息
由此我们知道第二个参数“&GPIO_InitStructure”包含的是外设GPIO的配置信息,主函数开头我们进行了这样一个私有数据声明:

GPIO_InitTypeDef  GPIO_InitStructure;

在头文件“stm32f10x_gpio.h”看到对GPIO_InitTypeDef 的定义:

 typedef struct
{
        uint32_t GPIO_Pin;             
                              
       GPIOMode_TypeDef GPIO_Mode;    
       GPIOSpeed_TypeDef GPIO_Speed;  
       GPIOOType_TypeDef GPIO_OType;  
       GPIOPuPd_TypeDef GPIO_PuPd;    
}GPIO_InitTypeDef;

对GPIO配置的参数理解:
GPIOMode_TypeDef GPIO_Mode:

typedef enum
{ 
  GPIO_Mode_IN   = 0x00, /*!<
  • 2
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
HAL_GPIO_Init 函数是一个在 STM32 系列单片机的 HAL 库中定义的函数,用于初始化 GPIO 口的配置。 其函数原型如下: ```c HAL_GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_Init) ``` 其中,GPIO_TypeDef* GPIOx 表示要初始化的 GPIO 口所在的 GPIOx 端口,例如 GPIOA、GPIOB 等,GPIO_InitTypeDef* GPIO_Init 表示 GPIO 口的配置信息,包括 GPIO 口的模式、输出类型、上拉下拉等参数。 在使用 HAL_GPIO_Init 函数初始化 GPIO 口时,需要先创建一个 GPIO_InitTypeDef 的结构体,然后根据需要设置 GPIO 口的各个参数,最后将结构体作为参数传入 HAL_GPIO_Init 函数中,即可完成 GPIO 口的初始化配置。 以下是 GPIO_InitTypeDef 结构体的定义: ```c typedef struct { uint32_t Pin; /* Specifies the GPIO pins to be configured. This parameter can be any value of @ref GPIO_pins_define */ uint32_t Mode; /* Specifies the operating mode for the selected pins. This parameter can be a value of @ref GPIO_mode_define */ uint32_t Pull; /* Specifies the Pull-up or Pull-Down activation for the selected pins. This parameter can be a value of @ref GPIO_pull_define */ uint32_t Speed; /* Specifies the speed for the selected pins. This parameter can be a value of @ref GPIO_speed_define */ uint32_t Alternate; /* Peripheral to be connected to the selected pins. This parameter can be a value of @ref GPIOEx_Alternate_function_selection */ } GPIO_InitTypeDef; ``` 其中,Pin 表示要配置的 GPIO 口的引脚编号,Mode 表示 GPIO 口的工作模式,Pull 表示 GPIO 口的上拉/下拉模式,Speed 表示 GPIO 口的速度,Alternate 表示 GPIO 口的复用功能。 总之,HAL_GPIO_Init 函数是 STM32 系列单片机 HAL 库中一个非常重要的函数,它能够帮助我们实现 GPIO 口的初始化和配置。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值