zoukankan      html  css  js  c++  java
  • stm32的gpio函数介绍

    一、gpio_init函数 void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)

    调用时的格式一般是例如

    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);//使能时钟

    GPIO_InitTypeDef  GPIO_InitStructure; 

    GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;

    GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;

    GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;

    GPIO_Init(GPIOD,&GPIO_InitStructure);

    参数1是GPIO_TypeDef类型,如下,就是7个寄存器的地址。

    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;

    下面是宏定义

    #define GPIOD               ((GPIO_TypeDef *) GPIOD_BASE)

    #define GPIOD_BASE            (APB2PERIPH_BASE + 0x1400)

    #define APB2PERIPH_BASE       (PERIPH_BASE + 0x10000)

    #define PERIPH_BASE           ((uint32_t)0x40000000) 

    可以看出0x40000000是外设的首地址,在STM32芯片的内部STM32有两个,一个叫APB1,一个叫APB2

    参数2为GPIO_InitTypeDef* GPIO_InitStruct。就是一个指向GPIO _InitTypeDef的地址。

    typedef struct

    {

      uint16_t GPIO_Pin;

      GPIOSpeed_TypeDef  GPIO_Speed;  

      GPIOMode_TypeDef  GPIO_Mode;  

     }GPIO_InitTypeDef;

  • 相关阅读:
    python numpy 介绍
    python+图像分割seg
    C++ 添加库
    input标签的disabled和readonly的区别
    linux中mysql忘记密码解决办法
    memcached服务安装与卸载
    app与服务端通信时如何进行消息校验
    缓存同步问题
    数据中添加对字段的说明
    服务器报警
  • 原文地址:https://www.cnblogs.com/ma77045728/p/7050790.html
Copyright © 2011-2022 走看看