nodemcu GPIO口操作

一、硬件平台 nodemcu
二、利用ESP8266的GPIO12管脚,对应的是nodemcu的D6.
三、软件代码:

#include "osapi.h"
#include "user_interface.h"
#include "ets_sys.h"
#include "mem.h"
#include "eagle_soc.h"

/******************************************************************************
 * FunctionName : user_rf_cal_sector_set
 * Description  : SDK just reversed 4 sectors, used for rf init data and paramters.
 *                We add this function to force users to set rf cal sector, since
 *                we don't know which sector is free in user's application.
 *                sector map for last several sectors : ABBBCDDD
 *                A : rf cal
 *                B : at parameters
 *                C : rf init data
 *                D : sdk parameters
 * Parameters   : none
 * Returns      : rf cal sector
*******************************************************************************/
uint32 ICACHE_FLASH_ATTR
user_rf_cal_sector_set(void)
{
    enum flash_size_map size_map = system_get_flash_size_map();
    uint32 rf_cal_sec = 0;

    switch (size_map) {
        case FLASH_SIZE_4M_MAP_256_256:
            rf_cal_sec = 128 - 5;
            break;

        case FLASH_SIZE_8M_MAP_512_512:
            rf_cal_sec = 256 - 5;
            break;

        case FLASH_SIZE_16M_MAP_512_512:
        case FLASH_SIZE_16M_MAP_1024_1024:
            rf_cal_sec = 512 - 5;
            break;

        case FLASH_SIZE_32M_MAP_512_512:
        case FLASH_SIZE_32M_MAP_1024_1024:
            rf_cal_sec = 1024 - 5;
            break;

        case FLASH_SIZE_64M_MAP_1024_1024:
            rf_cal_sec = 2048 - 5;
            break;
        case FLASH_SIZE_128M_MAP_1024_1024:
            rf_cal_sec = 4096 - 5;
            break;
        default:
            rf_cal_sec = 0;
            break;
    }

    return rf_cal_sec;
}


void ICACHE_FLASH_ATTR user_init()
{
        gpio_init();
        PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U,FUNC_GPIO12);// //将MTDI_U管脚设置为GPIO口
        gpio_output_set(BIT12,  0,  BIT12,  0);//将该引脚输出高电平
        //gpio_output_set(0,    BIT12,  BIT12,  0);//将该引脚输出低电平
        PIN_PULLUP_EN(PERIPHS_IO_MUX_MTDI_U);//上拉使能。


    }

四、测试结果
nodemcu GPIO口操作_第1张图片
nodemcu GPIO口操作_第2张图片

五、代码链接:
http://download.csdn.net/download/crjmail/9969733

你可能感兴趣的:(nodemcu,esp8266-gpio)