RT-Thread-学习笔记2 添加串口设备

今天添加串口设备,串口ESP8266,使用uart2通信,因为uart1作为调试串口了。

在uart.c中,会初始化uart底层,此时确保uart.h中 RT_USING_UART2是define的就行

建立线程

/* wifi thread entry */
static void wifi_thread_entry(void* parameter)
{
rt_device_t uart_wifi_dev;

uart_wifi_dev = rt_device_find("uart2");

if(uart_wifi_dev!=RT_NULL)
{
rt_device_open(uart_wifi_dev, RT_DEVICE_OFLAG_RDWR);
while(1)
{
rt_device_write(uart_wifi_dev,0,"Hello Wi-Fi!\r\n",14);
rt_thread_delay(RT_TICK_PER_SECOND);
}
}

}


启动线程

/* wifi thread entry */
static void wifi_thread_entry(void* parameter)
{
rt_device_t uart_wifi_dev;

uart_wifi_dev = rt_device_find("uart2");

if(uart_wifi_dev!=RT_NULL)
{
rt_device_open(uart_wifi_dev, RT_DEVICE_OFLAG_RDWR);
while(1)
{
rt_device_write(uart_wifi_dev,0,"Hello Wi-Fi!\r\n",14);
rt_thread_delay(RT_TICK_PER_SECOND);
}
}

}



查看debug串口

msh >ps
 thread  pri  status      sp     stack size max used   left tick  error
-------- ---- ------- ---------- ---------- ---------- ---------- ---
wifi     0x14 suspend 0x00000084 0x00000100 0x0000009c 0x00000014 000
led      0x14 suspend 0x0000007c 0x00000100 0x0000007c 0x00000014 000
tshell   0x19 ready   0x0000008c 0x00000400 0x0000013c 0x00000006 000
tidle    0x1f ready   0x00000050 0x00000100 0x00000050 0x0000001a 000


查看uart2串口,

Hello Wi-Fi!
Hello Wi-Fi!
Hello Wi-Fi!
Hello Wi-Fi!
Hello Wi-Fi!
Hello Wi-Fi!
Hello Wi-Fi!

至此,wifi使用的串口通了,下面就是对接wifi了

你可能感兴趣的:(RT-Thread,Embedded,System,IoT)