您当前的位置: 首页 > 

鱼香ROS

暂无认证

  • 0浏览

    0关注

    498博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

ESP8266_RTOSv3.X第一弹——GPIO的使用和代码讲解

鱼香ROS 发布时间:2019-07-03 01:23:06 ,浏览量:0

一、GPIO介绍
  1. IO数量及功能 关于esp8266的板子上的引脚,是这样子的,ESP芯片一共33个个引脚,其中包括电源,使能引脚、深度睡眠唤醒引脚、SPI引脚以及连接晶振和作为烧写Flash的引脚。所谓的GPIO(General-purpose input/output)引脚一共有17个,esp8266的SDK把其放进了一个枚举类型里。源码如下:

    typedef enum {
        GPIO_NUM_0 = 0,     /*!< GPIO0, input and output */
        GPIO_NUM_1 = 1,     /*!< GPIO1, input and output */
        GPIO_NUM_2 = 2,     /*!< GPIO2, input and output */
        GPIO_NUM_3 = 3,     /*!< GPIO3, input and output */
        GPIO_NUM_4 = 4,     /*!< GPIO4, input and output */
        GPIO_NUM_5 = 5,     /*!< GPIO5, input and output */
        GPIO_NUM_6 = 6,     /*!< GPIO6, input and output */
        GPIO_NUM_7 = 7,     /*!< GPIO7, input and output */
        GPIO_NUM_8 = 8,     /*!< GPIO8, input and output */
        GPIO_NUM_9 = 9,     /*!< GPIO9, input and output */
        GPIO_NUM_10 = 10,   /*!< GPIO10, input and output */
        GPIO_NUM_11 = 11,   /*!< GPIO11, input and output */
        GPIO_NUM_12 = 12,   /*!< GPIO12, input and output */
        GPIO_NUM_13 = 13,   /*!< GPIO13, input and output */
        GPIO_NUM_14 = 14,   /*!< GPIO14, input and output */
        GPIO_NUM_15 = 15,   /*!< GPIO15, input and output */
        GPIO_NUM_16 = 16,   /*!< GPIO16, input and output */
        GPIO_NUM_MAX = 17,
        /** @endcond */
    } gpio_num_t;
    
    
  2. 初始化函数及结构体 众所周知,想使用一个东西之前,一定要先把其初始化,如果是使用C语言,又要初始化一个比较多参数的东东,那估计就要用结构体了,ESP82666 GPIO的初始化函数是

    esp_err_t gpio_config(const gpio_config_t * pGPIOConfig )		//参数是gpio_config_t 类型的指针
    

    这个函数的返回值是esp_err_t,其值如果是ESP_OK就代表成功,如果是ESP_ERR_INVALID_ARG意思是参数错误,这个时候我们就要去检查一次参数了,参数是什么呢?参数是gpio_config_t 类型的指针

    那我们再看一下gpio_config_t 的定义:

    /**
     * @brief  gpio_config函数的配置参数
     */
    typedef struct {
        uint32_t pin_bit_mask;          /*!< 引脚: 32位的参数,每一位对应着一个GPIO*/
        gpio_mode_t mode;               /*!            
关注
打赏
1666092100
查看更多评论
0.0366s