请问一下各位大佬,在下述代码中,声明了两个串口的配置,为什么 uart_dev_echo 这个串口只是被定义并且初始化,并没有写sendMessage一类的方法,也没有被使用。
但是一旦删除这个定义和初始化,电脑端就无法收到来自单片机的消息了? 如果不删除的话,正常工作。
- void TaskUart(void *param)
- {
- uint8_t data[32];
- int ret;
- hosal_uart_dev_t <b><font color="#ff0000">uart_dev_echo </font></b>= {
- .config = {
- .uart_id = 0,
- .tx_pin = 4, // TXD GPIO
- .rx_pin = 3, // RXD GPIO
- .cts_pin = 255,
- .rts_pin = 255,
- .baud_rate = 9600,
- .data_width = HOSAL_DATA_WIDTH_8BIT,
- .parity = HOSAL_NO_PARITY,
- .stop_bits = HOSAL_STOP_BITS_1,
- .mode = HOSAL_UART_MODE_POLL,
- },
- };
- hosal_uart_dev_t uart_dev_log = {
- .config = {
- .uart_id = 1,
- .tx_pin = 16, // TXD GPIO
- .rx_pin = 7, // RXD GPIO
- .cts_pin = 255,
- .rts_pin = 255,
- .baud_rate = 115200,
- .data_width = HOSAL_DATA_WIDTH_8BIT,
- .parity = HOSAL_NO_PARITY,
- .stop_bits = HOSAL_STOP_BITS_1,
- .mode = HOSAL_UART_MODE_POLL,
- },
- };
- /* Uart init device */
- hosal_uart_init(&uart_dev_log);
- /* Uart init device */
- <font color="#ff0000"><b> hosal_uart_init(&uart_dev_echo);</b></font>
- while (1)
- {
- /* Uart receive poll */
- ret = hosal_uart_receive(&<b style=""><font color="#48d1cc">uart_dev_log</font></b>, data, sizeof(data));
- if (ret > 0)
- {
- /* Uart send poll */
- hosal_uart_send(&<font color="#48d1cc"><b>uart_dev_log</b></font>, data, ret);
- }
- }
- }
- /**
- * @brief main
- *
- */
- void main(void)
- {
- xTaskCreate(TaskUart, "TaskUart", 1024, NULL, 15, NULL);
- }
复制代码
|