STM32 GPIO 使用初始化

// At first, define a function named Init;

//结构体GPIO_INITSTRUCT

void LED_Init(void)

{

//step 1

/*********定义一个GPIO_InitTypeDef 类型的结构体**********/

GPIO_InitTypeDef GPIO_InitStruct;

//step 2 Assign values to the GPIO_InitStruct

//Set three Values to the InitStuct;

/*********选择要控制的GPIOx的引脚**********/

GPIO_InitStructure.GPIO_Pin =GPIO_Pin_4;

/*********设置引脚速率为50MHZ**********/

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;

/*********设置引脚模式为通用推完输出**********/

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

//step 3 open RCC of GPIOx

/*打开LED使用的GPIO的时钟使能*/

RCC_APB2PeriphClockCmd(RCC__APB2Periph_GPIOA, ENABLE);

//STEP 4 Init GPIOx

//

/*初始化相应的GPIO*/

GPIO_Init(GPIOA, &GPIO_InitStruct); //初始化GPIO_LED

}

//Content of GPIO_InitTypeDef

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;

//Content of GPIO_Init(GPIOx, &InitStruct);

// Because GPIOx IS a Address InitStruct is a variable, Should Add & sign before InitStuct;

//

/*定义GPIOA-H 寄存器结构体指针*/
#define GPIOA ((GPIO_TypeDef *) GPIOA_BASE)
#define GPIOB ((GPIO_TypeDef *) GPIOB_BASE)
#define GPIOC ((GPIO_TypeDef *) GPIOC_BASE)
#define GPIOD ((GPIO_TypeDef *) GPIOD_BASE)
#define GPIOE ((GPIO_TypeDef *) GPIOE_BASE)
#define GPIOF ((GPIO_TypeDef *) GPIOF_BASE)
#define GPIOG ((GPIO_TypeDef *) GPIOG_BASE)
#define GPIOH ((GPIO_TypeDef *) GPIOH_BASE)

//void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)

// Content of GPIO_Init( )

//Content of GPIO_TypeDef;

typedef struct

{

__IO uint32_t CRL;

__IO uint32_t CRH;

__IO uint32_t IDR;

__IO uint32_t ODR;

__IO uint32_t BSRR;

__IO uint32_t BRR;

__IO uint32_t LCKR;

} GPIO_TypeDef;

相关推荐
u152109648491 小时前
S.S.Audio PRO A2音频隔离器
嵌入式硬件·音视频·实时音视频·视频编解码·视频
zd8451015001 小时前
RS485 总线详解
单片机·嵌入式硬件
半条-咸鱼2 小时前
【STM32】I2C协议原理、HAL读写与OLED显示操作
嵌入式硬件·c·信息与通信
牛根生同志2 小时前
SPI数据收发的时候 TXE与RXNE标志位置位的时机
stm32·spi·transfer
wohoo_wangzi3 小时前
苏州晟雅泰电子:关于W25Q128JVSIQ这个芯片物料的参数,规格及应用领域
嵌入式硬件
goldenrolan4 小时前
学习型红外控制系统稳定性挂测工装专项总结
软件测试·python·stm32·嵌入式·红外
✎ ﹏梦醒͜ღ҉繁华落℘5 小时前
编程基础 --高内聚,低耦合
c语言·单片机
科芯创展5 小时前
1A,1MHz,30VIN,XZ4115,降压恒流LED驱动芯片
单片机·嵌入式硬件
集芯微电科技有限公司5 小时前
四通道2A输出集成功率电感降压模块专为紧凑型方案设计
人工智能·单片机·嵌入式硬件·生成对抗网络·计算机外设
踏着七彩祥云的小丑6 小时前
嵌入式测试学习第 37 天:异常场景测试:断电、拔插、干扰、非法指令
单片机·嵌入式硬件·学习