neptune开发板w800的UART1可以用tls_uart_write发送数据,但是怎么用tls_uart_read获取串口发送过来的数据?

发布于 2022-10-27 08:52:38

neptune开发板w800的UART1可以用tls_uart_write发送数据,但是怎么用tls_uart_read获取串口发送过来的数据?

case DEMO_MSG_UART_RECEIVE_DATA:

{
    rx_len = uart->rx_data_len;
    while (rx_len > 0)
    {
        printf("\n----1  rx_len----%d", rx_len);
        len = (rx_len > DEMO_UART_RX_BUF_SIZE) ? DEMO_UART_RX_BUF_SIZE : rx_len;
        printf("\n----2  len----%d", len);
        memset(uart->rx_buf, 0, (DEMO_UART_RX_BUF_SIZE + 1));
        tls_uart_read(TLS_UART_1, msg_rxfifo_buf, len);
        tls_uart_read(TLS_UART_1, rx_fifo_buf1[0], len);
        printf("\n----####  msg_rxfifo_buf----%s\n", msg_rxfifo_buf);
        printf("\n----####  rx_fifo_buf1[0]----%s\n", rx_fifo_buf1[0]);
        ret = tls_uart_read(TLS_UART_1, (u8 *)uart->rx_buf, len);
        ret = tls_uart_read(TLS_UART_1, (u8 *)uart->rx_buf, len); /* input */
        printf("\n----####  DEMO_MSG_UART_RECEIVE_DATA----%s\n", uart->rx_buf);
        printf("\n----3  ret----%d", ret);

        if (ret <= 0)
        {
            break;
        }

        rx_len -= ret;
        uart->rx_data_len -= ret;

if USE_DMA_TX_FTR

        // tls_uart_dma_write(uart->rx_buf, len, uart_dma_done, TLS_UART_1);

else

        tls_uart_write(TLS_UART_1, uart->rx_buf, len); /* output */
        printf("\n----4  DEMO_MSG_UART_RECEIVE_DATA  uart->rx_buf----%s\n", uart->rx_buf);

endif

    }
    printf("\n----5  DEMO_MSG_UART_RECEIVE_DATA  uart->rx_msg_num----%s\n", uart->rx_msg_num);
    if (uart->rx_msg_num > 0)
    {
        uart->rx_msg_num--;
    }

    printf("\n----6  DEMO_MSG_UART_RECEIVE_DATA----%s\n", uart->rx_buf);
}
break;

代码用的是开发板自带的wm_uart_demo.c
我修改了下,运行得不到发送过来的1234

image.png

查看更多

关注者
0
被浏览
2.5k
2 个回答
ZYQ
ZYQ 2022-10-27
我已不再支持W80X任何相关问题的回复,请大家不要私信,有问题找 isme 谢谢

直接调用不就好了,只要有数据就可以读取到,或者调用tls_uart_try_read

hitiger
hitiger 2022-10-27
这家伙很懒,什么也没写!

case DEMO_MSG_UART_RECEIVE_DATA:

    {
        rx_len = uart->rx_data_len;
        while (rx_len > 0)
        {
            printf("\n----1  rx_len----%d", rx_len);
            len = (rx_len > DEMO_UART_RX_BUF_SIZE) ? DEMO_UART_RX_BUF_SIZE : rx_len;
            printf("\n----2  len----%d", len);
            memset(uart->rx_buf, 0, (DEMO_UART_RX_BUF_SIZE + 1));
            tls_uart_read(TLS_UART_1, msg_rxfifo_buf, len);
            tls_uart_read(TLS_UART_1, rx_fifo_buf1[0], len);
            printf("\n----####  msg_rxfifo_buf----%s\n", msg_rxfifo_buf);
            printf("\n----####  rx_fifo_buf1[0]----%s\n", rx_fifo_buf1[0]);
            ret = tls_uart_read(TLS_UART_1, (u8 *)uart->rx_buf, len);
            ret = tls_uart_read(TLS_UART_1, (u8 *)uart->rx_buf, len); /* input */
            printf("\n----####  DEMO_MSG_UART_RECEIVE_DATA----%s\n", uart->rx_buf);
            printf("\n----3  ret----%d", ret);

            if (ret <= 0)
            {
                break;
            }

            rx_len -= ret;
            uart->rx_data_len -= ret;

if USE_DMA_TX_FTR

            // tls_uart_dma_write(uart->rx_buf, len, uart_dma_done, TLS_UART_1);

else

            tls_uart_write(TLS_UART_1, uart->rx_buf, len); /* output */
            printf("\n----4  DEMO_MSG_UART_RECEIVE_DATA  uart->rx_buf----%s\n", uart->rx_buf);

endif

        }
        printf("\n----5  DEMO_MSG_UART_RECEIVE_DATA  uart->rx_msg_num----%s\n", uart->rx_msg_num);
        if (uart->rx_msg_num > 0)
        {
            uart->rx_msg_num--;
        }

        printf("\n----6  DEMO_MSG_UART_RECEIVE_DATA----%s\n", uart->rx_buf);
    }
    break;
    
    代码用的是开发板自带的wm_uart_demo.c
    我修改了下,运行得不到发送过来的1234
   

image.png

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览