STM32F4的GPIO使用

本文详细介绍了如何在STM32F4单片机中启用GPIO时钟,并进行GPIO初始化,包括设置GPIOx、GPIO_InitTypeDef结构体、IO口模式、输出类型、速度和上下拉配置。通过理解这些步骤,开发者可以更好地掌握STM32F4的GPIO使用。
摘要由CSDN通过智能技术生成

一.GPIO时钟使能
void RCC_AHB1PeriphClockCmd(uint32_t RCC_AHB1Periph, FunctionalState NewState);

  • 参数RCC_AHB1Periph可选择的范围如下:
#define RCC_AHB1Periph_GPIOA             ((uint32_t)0x00000001)
#define RCC_AHB1Periph_GPIOB             ((uint32_t)0x00000002)
#define RCC_AHB1Periph_GPIOC             ((uint32_t)0x00000004)
#define RCC_AHB1Periph_GPIOD             ((uint32_t)0x00000008)
#define RCC_AHB1Periph_GPIOE             ((uint32_t)0x00000010)
#define RCC_AHB1Periph_GPIOF             ((uint32_t)0x00000020)
#define RCC_AHB1Periph_GPIOG             ((uint32_t)0x00000040)
#define RCC_AHB1Periph_GPIOH             ((uint32_t)0x00000080)
#define RCC_AHB1Periph_GPIOI             ((uint32_t)0x00000100) 
#define RCC_AHB1Periph_GPIOJ             ((uint32_t)0x00000200)
#define RCC_AHB1Periph_GPIOK             ((uint32_t)0x00000400)
  • 参数NewState可选择的范围如下:
typedef enum {
   
DISABLE = 0, 
ENABLE = !DISABLE
} FunctionalState;
  • 使能与去使能
  if (NewState != DISABLE)
  {
   
    RCC->AHB1ENR |= RCC_AHB1Periph;
  }
  else
  {
   
    RCC->AHB1ENR &= ~RCC_AHB1Periph;
  }

通过改写外设时钟使能寄存器(RCC_AHB1ENR) 使能和去使能外设

  • RCC的定义
    就是RCC_TypeDef结构体的地址
    RCC的边界地址为:0x4002 3800 - 0x4002 3BFF(大小0x3FF)
    所以RCC_BASE就是0x4002 3800
#define RCC                 ((RCC_TypeDef *) RCC_BASE)
typedef struct
{
   
  __IO uint32_t CR;            /*!< RCC clock control register,                                  Address offset: 0x00 */
  __IO uint32_t PLLCFGR;       /*!< RCC PLL configuration register,                              Address offset: 0x04 */
  __IO uint32_t CFGR;          /*!< RCC clock configuration register,                            Address offset: 0x08 */
  __IO uint32_t CIR;           /*!< RCC clock interrupt register,                                Address offset: 0x0C */
  __IO uint32_t AHB1RSTR;      /*!< RCC AHB1 peripheral reset register,                          Address offset: 0x10 */
  __IO uint32_t AHB2RSTR;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值