买到的WiFi模块型号是ESP-12S,除复位、串口、下载、电源外,还有6个口可以进行DIY,分别是GPIO2GPIO4GPIOI5GPIO12GPIO13GPIO14,本文通过实例来演示如何通过一个按键控制一个小灯的闪烁。
适应读者:已完成开发环境的配置,并能导入SDK和编译完成。
模块的最小系统原理图
首先说下用到的工具及环境:
1、使用的SDK是安信可官方下载的直接可编译的
2、安信可官网下载的ESP8266开发环境,是用eclipse和cygwin在windows环境下载开发,使用还是蛮简单的
3、下载工具用FLASH_DOWNLOAD_TOOLS
4、下面直接上user_main.c文件的内容,只需修改该文件内容,其它文件先不要动
/******************************************************************************
* Copyright 2013-2014 Espressif Systems (Wuxi)
*
* FileName: user_main.c
*
* Description: entry file of user application
*
* Modification history:
* 2014/1/1, v1.0 create this file.
*******************************************************************************/
#include "ets_sys.h"
#include "osapi.h"
#include "gpio.h"//io引脚
#include "user_interface.h"
#include "user_devicefind.h"
#include "user_webserver.h"
#if ESP_PLATFORM
#include "user_esp_platform.h"
#endif
void user_rf_pre_init(void)
{
}
/*定时器结构体 */
static os_timer_t os_timer;
/*******************************************************************************
* 自定义引脚运行函数_定时器回调
*******************************************************************************/
void Task_Run(void){
static bool status = false;
if(GPIO_INPUT_GET(14)){//读取GPIO14的引脚电平
if (status == true){
status = false;
GPIO_OUTPUT_SET(GPIO_ID_PIN(12), 0);//GPIO12输出低电平
}else{
status = true;
GPIO_OUTPUT_SET(GPIO_ID_PIN(12), 1);//GPIO12输出高电平
}
}else{
GPIO_OUTPUT_SET(GPIO_ID_PIN(12), 1);//GPIO12输出高电平
}
}
/******************************************************************************
* FunctionName : user_init
* Description : entry of user application, init user function here
* Parameters : none
* Returns : none
*******************************************************************************/
void user_init(void)
{
/*设置串口波特率*/
uart_init(115200,9600);
/*打印版本信息*/
os_printf("\r\n");os_printf("SDK version:%s\n", system_get_sdk_version());
/*配置GPIO12*/
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U,FUNC_GPIO12);
/*配置GPIO14*/
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTMS_U,FUNC_GPIO14);
/*配置软件定时器 */
os_timer_disarm(&os_timer);//关闭定时器
os_timer_setfn(&os_timer,(ETSTimerFunc *) (Task_Run), NULL);//配置回调函数
os_timer_arm(&os_timer,1000,true);//启动定时器
}
编译成功的标志是这样的
烧录的步骤:
1、将GPIO_0引脚接地,断开模块电源;
2、打开ESP FLASH DOWNLOAD TOOL;
3、按照本文的第二张图片进行配置后,点击START按钮;
4、打开模块电源后就看到工具提示下载中;
5、若失败,请尝试重复以上操作!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。