初始化
GPIO配置
配置流程
通常为:
1.GPIOx口时钟使能
如:RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
2.配置初始化结构体,见下
3.初始化GPIO口
GPIO_InitTypeDef结构体分析
源码:
typedef struct
{
uint32_t GPIO_Pin; /*!< Specifies the GPIO pins to be configured.
This parameter can be any value of @ref GPIO_pins_define */
GPIOMode_TypeDef GPIO_Mode; /*!< Specifies the operating mode for the selected pins.
This parameter can be a value of @ref GPIOMode_TypeDef */
GPIOSpeed_TypeDef GPIO_Speed; /*!< Specifies the speed for the selected pins.
This parameter can be a value of @ref GPIOSpeed_TypeDef */
GPIOOType_TypeDef GPIO_OType; /*!< Specifies the operating output type for the selected pins.
This parameter can be a value of @ref GPIOOType_TypeDef */
GPIOPuPd_TypeDef GPIO_PuPd; /*!< Specifies the operating Pull-up/Pull down for the selected pins.
This parameter can be a value of @ref GPIOPuPd_TypeDef */
}GPIO_InitTypeDef;
这里可说的不多,基本上通过字面意思和查找相应的结构体定义都能理解,这里着重说一下GPIO_OType和GPIO_PuPd。
先看GPIO_OType:
typedef enum
{
GPIO_OType_PP = 0x00,
GPIO_OType_OD = 0x01
}GPIOOType_TypeDef;