1.COMMON
1.includePath
ctrl+shift+p进入命令面板输入C/C++:Edit Configurations
在包含文件中选择include文件目录
2.输出监视器
在platformio.ini文件中编写
monitor_speed = 74880可使电脑接收串口波特率设置为74880
3.在include文件夹下手动添加user_config.h文件
#ifndef USER_CONFIG_H
#define USER_CONFIG_H
#endif
2.UART
内核初始化默认以74880波特率在UART0输出初始化信息
之后以用户设置为主的波特率输出
uart_iniost();
os_printf();
uart0_sendStr();
3.watchdog
任务持续运行时一定要及时喂狗,否则会自动重启
#include “c_types.h” // uint8_t等变量类型
system_soft_wdt_feed();
4.delay
void os_delay_us(uint16 us);
5.GPIO
#include “eagle_soc.h” // GPIO函数、宏定义
输出
PIN_FUNC_SELECT();
GPIO_OUTPUT_SET();
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO4_U, FUNC_GPIO4);
GPIO_OUTPUT_SET(GPIO_ID_PIN(4),1);
输入
GPIO_DIS_OUTPUT();
PIN_PULLUP_DIS();
GPIO_INPUT_GET();
外部中断
ETS_GPIO_INTR_DISABLE();
ETS_GPIO_INTR_ATTACH();
gpio_pin_intr_state_set();
ETS_GPIO_INTR_ENABLE();
6.OS_Timer
os_timer_t定义软件定时器结构体
os_timer_disarm();
os_timer_setfn();
os_timer_arm();
7.HW_TIMER
添加hw_timer.c
hw_timer_init();
hw_timer_set_func();
hw_timer_arm();
8.TASK
最多设置3个任务
define
~~
消息队列深度
os_event_t
~~
*queue
~~
//消息队列指针
os_malloc();
~~
//分配消息队列空间
system_os_task();
system_os_post();
9.R/W FLASH
0x70扇区之后
spi_flash_erase_sector();
spi_flash_write();
spi_flash_read();
10.AP mode
#define
~~
ESP8266_AP_SSID “
~~
”
#define
~~
ESP8266_AP_PASS “
~~
”
wifi_set_opmode();
struct
~
softap_config
~
//ap属性
os_memset();
~~
//初始化ap结构体
os_strcpy();
~~
//ssid,password
wifi_softap_set_config();
wifi_get_opmode();
wifi_get_ip_info();
wifi_softap_get_station_num();
11.AP_UDP_Server
10+
#include “espconn.h”
struct
~~
espconn
~~
//类似定义一个socket
.type
.proto.udp
.proto.udp->local_port
espconn_regist_sentcb();
espconn_regist_recvcb();
espconn_create();
espconn_get_connection_info();
espconn_send();
12.AP_UDP_Client
11+
.proto.udp->remote_port = 8888; // 设置目标端口
.proto.udp->remote_ip[0] = 192; // 设置目标IP地址
.proto.udp->remote_ip[1] = 168;
.proto.udp->remote_ip[2] = 4;
.proto.udp->remote_ip[3] = 2;
13.AP_TCP_Server
10+
#include “espconn.h”
struct
~~
espconn
~~
//类似定义一个socket
.type
.proto.tcp
.proto.tcp->local_port
espconn_regist_connectcb
espconn_regist_reconcb
espconn_accept
espconn_regist_time
espconn_regist_sentcb
espconn_regist_recvcb
espconn_regist_disconcb
14.AP_TCP_Client
13+
proto.tcp->remote_port = 8888; // 设置目标端口
.proto.tcp->remote_ip[0] = 192; // 设置目标IP地址
.proto.tcp->remote_ip[1] = 168;
.proto.tcp->remote_ip[2] = 4;
.proto.tcp->remote_ip[3] = 2;
15.STA mode
STA模式下默认开启DHCP,接入WIFI时自动分配IP地址
#define
~~
ESP8266_STA_SSID
~~
//要连接的wifi名
#define
~~
ESP8266_STA_PASS
~~
//要连接的wifi密码
wifi_set_opmode();
struct station_config();
os_memset();
os_strcpy();
wifi_station_set_config();
16.STA_UDP_Server/Client
参考11/12
17.STA_TCP_Server/Client
参考13/14
espconn_connect
18.DNS/HTTP
STA TCP CLIENT 模式下
espconn_gethostbyname();
espconn_connect();
espconn_send();
~~
//http特殊指令
19.SNTP
#include “sntp.h”
STA模式下
void ICACHE_FLASH_ATTR ESP8266_SNTP_Init_JX(void)
{
ip_addr_t * addr = (ip_addr_t *)os_zalloc(sizeof(ip_addr_t));
sntp_setservername(0, "us.pool.ntp.org");
sntp_setservername(1, "ntp.sjtu.edu.cn");
ipaddr_aton("210.72.145.44", addr);
sntp_setserver(2, addr);
os_free(addr);
sntp_init();
OS_Timer_SNTP_Init_JX(1000,1);
}
sntp_get_current_timestamp();
sntp_get_real_time();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)