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;

相关推荐
jianqiang.xue8 小时前
把Agent塞进MCU:工具次数和上下文长度怎么卡
java·前端·网络·单片机·esp32·ai编程
创界工坊工作室10 小时前
106-基于51单片机的自行车测速仪设计
stm32·单片机·嵌入式硬件·51单片机·proteus
意法半导体STM3212 小时前
【官方原创】LAT1726 如何通过STM32H5 Bootloader进行固件升级与运行
stm32·单片机·嵌入式硬件·stm32h5·bootloader
橘为己有44112 小时前
STM32:串口_重定向CIO(3)
stm32·单片机·嵌入式硬件
少司府1 天前
嵌入式外设篇(二)GPIO·二:GPIO输出与LED控制
linux·stm32·单片机·嵌入式硬件·mcu·51单片机·系统
Flying Bear1 天前
Keithley 2450 SourceMeter源表上位机开发笔记
笔记·单片机·嵌入式硬件
无敌贵点大王1 天前
从寄存器层面重学STM32(11)——ADC理论
stm32·单片机·嵌入式硬件
Zw-awa1 天前
卡尔曼到底在算什么:从一维到它的变式以及工程版卡尔曼滤波算法C语言实现
stm32
希和20271 天前
代码讲解:STM32F103C8T6 驱动 HC-SR04 超声波测距
stm32·单片机·嵌入式硬件
编程小白菜1231 天前
STM32L0 ADC串扰揭秘:充电电压如何“伪造”压力数据
stm32·单片机·嵌入式硬件