ESP8266简单的串口应用
ESP8266共有两组UART接⼝,分别为:
UART0:
U0TXD: pin26(U0TXD)
U0RXD: pin25(U0RXD)
U0CTS: pin12(MTCK)
U0RTS: pin13(MTDO)
UART1:
U1TXD: pin14(GPIO2)
UART0作为数据通信接⼝口,UART1作为debug信息的打印。不过在最新发布的SDK1.0.1中,debug信息的默认打印也改到通过UART0接口了,可以直接利用os_printf()进行信息输出。当你想通过UART1输出debug信息时,通过以下接⼝可以设置从uart0或者uart1口输出打印。void UART_SetPrintPort(uint8 uart_no);
由于ESP8266的开发环境没有在线调试功能,所以利用os_printf()进行信息输出在程序调试过程中尤为重要。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
/* 串口发送举例 www.tansoo.cn */ #include <ets_sys.h> #include <osapi.h> #include <os_type.h> #include <gpio.h> #include "driver/uart.h" //定义一个时间定时器变量hello_timer LOCAL os_timer_t hello_timer; LOCAL void ICACHE_FLASH_ATTR hello_cb(void *arg) { os_printf("Hello World!\r\n"); } void user_init(void) { // 设置 UART0与UART1的通讯速率 uart_init(BIT_RATE_115200, BIT_RATE_115200); //UART_SetPrintPort(UART1); // SDK V1.0.1 有效; // 取消(停止)定时器hello_timer os_timer_disarm(&hello_timer); // 将时间定时器变量hello_timer关联到一个函数hello_cb(),这个函数会在到达定时时间时执行一次, os_timer_setfn(&hello_timer, (os_timer_func_t *)hello_cb, (void *)0); // 设置时间定时器变量hello_timer的时间周期为3秒钏,第三个参数为0时,hello_cb()只会执行一次,当为1时,hello_cb()会循环执行。 os_timer_arm(&hello_timer, 3000, 1); } |
-
-
-
-
-
显示评论请问,有ESP8266接收的例程吗?这种发送的例程看懂了,但是对于接收,还是云里雾里?
俺也一样!!!!
你们有接收的例子吗?跪求
同求接受的,全TM是发送的。。。
现在用Ardunio就可以很方便的写ESP8266的程序,例子也很多,一般的开发应该能够应付了