3.3串口收发控制实验

本例我们实现W800串口0的收发实验。我们在demo程序的基础上修改程序。首先打开uart demo的宏定义。

在串口示例中创建一个串口任务:
tls_os_task_create(NULL, NULL,
demo_uart_task,
(void ) demo_uart,
(void ) demo_uart_task_stk, /
任务栈的起始地址 /
DEMO_UART_TAST_STK_SIZE, /
* 任务栈的大小 */
DEMO_UART_TASK_PRIO, 0);
}
在任务中初始化串口配置,并配置串口引脚到PB20,PB19。
opt.baudrate = uart->bandrate;
opt.paritytype = uart->parity;
opt.stopbits = uart->stopbits;
opt.charlength = TLS_UART_CHSIZE_8BIT;
opt.flow_ctrl = TLS_UART_FLOW_CTRL_NONE;

        //选择待使用的引脚及具体的复用功能
        /* UART0_RX-PB20  UART0_TX-PB19 */
        wm_uart1_rx_config(WM_IO_PB_20);
        wm_uart1_tx_config(WM_IO_PB_19);

        if (WM_SUCCESS != tls_uart_port_init(TLS_UART_0, &opt, 0))
        {
            printf("uart0 init error
");
        }

接下来调用tls_uart_read函数读取串口数据,tls_uart_write函数发送串口数据。实现串口收发数据。

程序下载到开发板,运行程序,注意先输入配置指令t-uart=(115200,0,0),指定通信波特率为115200。然后即可随意发数据到开发板串口0,串口0收到数据会原样返回。

原文地址:https://www.cnblogs.com/doiting/p/14108908.html