【求助】TuyaOS 8720CF ,关于串口收发的问题

Wi-Fi 设备、Wi-Fi 低功耗设备、Wi-Fi BLE 双模设备、Ethernet设备、Ethernet+Wi-Fi设备等
Post Reply
Daan
Posts: 79

//串口接收回调函数
STATIC void uart_receive_task(VOID_T *arg)
{
UINT32_T op_ret;
UINT8_T uart0_rx_buf[BUFFER_SIZE];
for (;;)
{
op_ret = tal_uart_read(TUYA_UART_NUM_0, uart0_rx_buf, strlen(uart0_rx_buf));
//TAL_PR_DEBUG("op_ret:%d", op_ret);
if (op_ret > 0)
{
TAL_PR_DEBUG("op_ret:%d", op_ret);
if(uart0_rx_buf[0] == 0x01)
{
TAL_PR_DEBUG("uart0_rx_buf[0]:%d, uart0_rx_buf[1]:%d", uart0_rx_buf[0],uart0_rx_buf[1]);
tal_uart_write(TUYA_UART_NUM_0, uart0_rx_buf, strlen(uart0_rx_buf));
}
}
}
}

//创建串口接收线程
STATIC void uart_receive_thread_create(void)
{
THREAD_CFG_T thread_cfg = {
.thrdname = "uart_receive",
.stackDepth = 1024*4,
.priority = THREAD_PRIO_3,//优先级
};
tal_thread_create_and_start(&uart_receive_thrd, NULL, NULL, uart_receive_task, NULL, &thread_cfg);
}
我这边写了以测试程序,大概就是收到啥,如果判断第一个数据是01,就发出什么。但是收到的和发出来的都是不对的。op_ret 这个数字打出来的也不对,烦请大佬们帮忙看一下,串口能否这么用?附件是.c程序 和日志

Attachments
new 1.txt
(391 Bytes) Downloaded 58 times
tuya_app_main.c
(12.08 KiB) Downloaded 32 times
yingtao_33
Posts: 229

Re: 【求助】TuyaOS 8720CF ,关于串口收发的问题

op_ret = tal_uart_read(TUYA_UART_NUM_0, uart0_rx_buf, strlen(uart0_rx_buf));
应该是
op_ret = tal_uart_read(TUYA_UART_NUM_0, uart0_rx_buf, sizeof(uart0_rx_buf));

Post Reply