3.3串列埠收發控制實驗
阿新 • • 發佈:2020-12-09
本例我們實現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\n");
}
接下來呼叫tls_uart_read函式讀取串列埠資料,tls_uart_write函式傳送串列埠資料。實現串列埠收發資料。
程式下載到開發板,執行程式,注意先輸入配置指令t-uart=(115200,0,0),指定通訊波特率為115200。然後即可隨意發資料到開發板串列埠0,串列埠0收到資料會原樣返回。