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

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

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

建立线程

[cpp]  view plain  copy
  1. /* wifi thread entry */  
  2. static void wifi_thread_entry(void* parameter)  
  3. {  
  4. rt_device_t uart_wifi_dev;  
  5.   
  6. uart_wifi_dev = rt_device_find("uart2");  
  7.   
  8. if(uart_wifi_dev!=RT_NULL)  
  9. {  
  10. rt_device_open(uart_wifi_dev, RT_DEVICE_OFLAG_RDWR);  
  11. while(1)  
  12. {  
  13. rt_device_write(uart_wifi_dev,0,"Hello Wi-Fi!\r\n",14);  
  14. rt_thread_delay(RT_TICK_PER_SECOND);  
  15. }  
  16. }  
  17.   
  18. }  


启动线程

[cpp]  view plain  copy
  1. /* wifi thread entry */  
  2. static void wifi_thread_entry(void* parameter)  
  3. {  
  4. rt_device_t uart_wifi_dev;  
  5.   
  6. uart_wifi_dev = rt_device_find("uart2");  
  7.   
  8. if(uart_wifi_dev!=RT_NULL)  
  9. {  
  10. rt_device_open(uart_wifi_dev, RT_DEVICE_OFLAG_RDWR);  
  11. while(1)  
  12. {  
  13. rt_device_write(uart_wifi_dev,0,"Hello Wi-Fi!\r\n",14);  
  14. rt_thread_delay(RT_TICK_PER_SECOND);  
  15. }  
  16. }  
  17.   
  18. }  



查看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了


转载于http://blog.csdn.net/iamlvshijie/article/details/55001124

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值