STM32库函数中GPIO_Init的理解
STM32库函数中GPIO_Init的理解 (2011-07-21 10:14:34)转载
STM32中GPIO的配置风格和以往研究的MCU有很大的不同,研究了好一段时间才搞通。
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;
配置一个引脚只需要4位寄存器,而上面却定义了8位,仔细研究GPIO_Init()函数后,确定为ST开发人员加上去的标识位。0x1_ 的是输出标识,其他则为输入模式。
下面看一下GPIO_Init()这个函数:
void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
{
uint32_t currentmode = 0x00, currentpin = 0x00, pinpos = 0x00, pos = 0x00; uint32_t tmpreg = 0x00, pinmask = 0x00;
/* Check the parameters
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));
assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin));
/*---------------------------- GPIO Mode Configuration -----------------------
currentmode = ((uint32_t)GPIO_InitStruct->GPIO_Mode) & ((uint32_t)0x0F);//屏蔽高半个字节的标识位
if ((((uint32_t)GPIO_InitStruct->GPIO_Mode) & ((uint32_t)0x10)) != 0x00)//判断是否为输出,0x1_
{
/* Check the parameters
assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed));
/* Output mode
currentmode |= (uint32_t)GPIO_InitStruct->GPIO_Speed;//如果是输出,则加上相关的速度标志
}
/*---------------------------- GPIO CRL Configuration ------------------------ /* Configure the eight low port pins
if (((uint32_t)GPIO_InitStruct->GPIO_Pin & ((uint32_t)0x00FF)) != 0x00)//判断引脚是否有效
{
tmpreg = GPIOx->CRL; //读出CRL寄存器中的值,并保存
for (pinpos = 0x00; pinpos < 0x08; pinpos++)
{
pos = ((uint32_t)0x01) << pinpos;
/* Get the port pins position 找出引脚的位置
currentpin = (GPIO_InitStruct->GPIO_Pin) & pos;
stm32库函数解释_信息与通信_工程科技_专业资料。部分库函数简介 一、通用输入/...} GPIO_InitTypeDef; GPIO_Pin 该参数选择待设置的 GPIO 管脚,使用操作符“...
STM32_GPIO_Init()函数解析_计算机硬件及网络_IT/计算机_专业资料。STM32库函数...库函数里面的 GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_...
stm32库函数部分解释_教学案例/设计_教学研究_教育专区。stm32库函数部分解释,非常...GPIO_DeInit(GPIOA); 2 函数 GPIO_AFIODeInit 功能描述:将复用功能(重映射事...
解析STM32 的库函数 意法半导体在推出 STM32 微控制器之初,也同时提供了一...GPIOSpeed_TypeDef GPIO_Speed; GPIOMode_TypeDef GPIO_Mode; }GPIO_InitTypeDef...
理解STM32 GPIO初始化 库函数_计算机软件及应用_IT/计算机_专业资料 暂无评价0人阅读0次下载举报文档 理解STM32 GPIO初始化 库函数_计算机软件及应用_IT/...
STM32 GPIO口固件库中与 GPIO 有关的函数主要有: 函数名 GPIO_Init GPIO_...GPIO_Init void GPIO_Init(GPIO_TypeDef* GPIO_InitTypeDef* GPIO_InitStruct...
STM32_GPIO库函数使用_电子/电路_工程科技_专业资料。STM32F10x系列GPIO库函数/...(GPIOA);//Read the GPIOC input data port and store it in ReadValue ...
的底层函数,stm32_gpio.c 包含配置 GPIO 的底层函数; stm32f10x_lib.c 则.../* 复位系统时钟设置 */ RCC_DeInit(); /* 开启 HSE */ RCC_HSEConfig...
STM32中使用GPIO的总结(超强)_计算机软件及应用_IT/计算机_专业资料。STM32 GPIO...GPIO_DeInit(GPIOA); 函数 GPIO_AFIODeInit 功能描述:将复用功能(重映射事件控...
解析STM32的库函数_数学_自然科学_专业资料。以最常用的 GPIO 设备的初始化函数...}GPIO_InitTypeDef; 由此可知 GPIO_InitTypeDef 是一个结构体类型同义字,其功能...
热门文档