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
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;
// tls_uart_dma_write(uart->rx_buf, len, uart_dma_done, TLS_UART_1);
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);
}
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
就是获取不到,请看下我的代码有什么问题
建议你先把 demo 跑成功了,再去修改,另外 tls_uart_read 后面的长度 已经写了len 之后,只需要调用一次就行了 ,还有 tls_uart_read(TLS_UART_1, rx_fifo_buf1[0], len); 本身就是错误的用法
源代码是这样的:
case DEMO_MSG_UART_RECEIVE_DATA: