This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LP-CC2652RB: Uart2 缓存如何清空

Part Number: LP-CC2652RB
Other Parts Discussed in Thread: SYSCONFIG

Hi Ti,

我在使用串口时遇到两个问题,串口配置为 read callback 模式:

void uart_read_cb(UART_Handle handle, void *buf, size_t count)
{
    Display_printf(display, 0, 0, "recv data(%d): %s", count, (char*)buf);
    // uint8_t tmpBuf[255]; RSBUS_PACK_MAX_LENGTH = 255;
    memset(tmpBuf, 0, RSBUS_PACK_MAX_LENGTH);
    UART2_read(uartHandle, tmpBuf, RSBUS_PACK_MAX_LENGTH, &recvCnt);
}

int8_t rsbus_init(void)
{
    UART2_Params uartParams2;

    /* Create a UART where the default read and write mode is BLOCKING */
    UART2_Params_init(&uartParams2);
    uartParams2.baudRate = RSBUS_BAUDRATE;      // RSBUS_BAUDRATE = 2000000
    uartParams2.readCallback = (UART2_Callback)uart_read_cb;
    uartParams2.readMode = UART2_Mode_CALLBACK;
    uartParams2.readReturnMode = UART2_ReadReturnMode_PARTIAL;

    uartHandle = UART2_open(CONFIG_UART2_0, &uartParams2);
    if (uartHandle == NULL) {
        /* UART2_open() failed */
        Display_printf(display, 0, 0, "UART2_open failed");
        return FALSE;
    }
    
    // uint8_t tmpBuf[255]; RSBUS_PACK_MAX_LENGTH = 255;
    memset(tmpBuf, 0, RSBUS_PACK_MAX_LENGTH); 
	UART2_read(uartHandle, tmpBuf, RSBUS_PACK_MAX_LENGTH, &recvCnt);
	
    return TRUE;
}

问题一:

按上面的配置,我的 main() 里初始化后只有一个空的 while(1) 循环.

我通过其他串口工具发送数据,每次发生100个字符,出现下面的结果:这个程序只能接受到 255 (100+100+55) 个字节,和上面 sysconfig 配置的一样,然后程序就卡死了,必须上电才能 重新运行。

只是因为缓冲区没有清空吗?但是我也调用了 memcpy() 清内存啊。。。是否还需要其他函数清空内部缓存呢?

问题二:

当我发送的数据长度超过 136 个字符时,串口只接收了 136 字节,并卡死。这个又是什么原因呢?

总结一下以上的现象:当发送的总字符数超过 sysconfig 设置的 Rx Ring Buffer size ,或者 单次发送超过 136 个字符后,程序都会卡死。(我试过将 Rx Ring Buffer size 换其他值,现象是一致的

谢谢!

  • 每次都应在缓冲区满之前再次使用read操作,否则就会溢出

    可在SDK查看uart2的使用说明C:/ti/simplelink_cc13x2_26x2_sdk_5_20_00_52/docs/drivers/doxygen/html/_u_a_r_t2_8h.html

  • 我在 read callback 函数里每次都有重新 read 呢,而且我还试着把 read 放在主函数内,现象也是这样。

    这个文档我已经看过了,我还试着加了 readCancel(),结果还是不行

  • 我在 read callback 函数里每次都有重新 read 呢,而且我还试着把 read 放在主函数内,现象也是这样。

    这个文档我已经看过了,我还试着加了 readCancel(),结果还是不行

    今天还在测试这个程序,问题依旧,请问还有什么建议吗?

    谢谢!

  • 你可以通过逻辑分析仪监控所发送或接收的字节数,看实际发送了多少

    下面有两个相关的帖子,你可以看一下

    https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/1021136/cc1312r-how-to-read-uart2_read-data

    https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/994971/cc2642r-uart2-rx-buffer-fragmented