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.

CC2652RB: How to clear the RxRingBuffer of UART2

Part Number: CC2652RB

Hi Ti,

My SDK version is simplelink_cc13x2_26x2_sdk_4_30_00_54, and I was use UART2 in Rx callback mode.

I find that the Rx callback function will be called each time the RxRingBuffer is full, but that's NOT what I expected.

So I want to know is there has some method can clear the RxRingBuffer?

  • Hi junde,

    Have you tried UART2_flushRx?  Are you basing your code from uart2callback and can you provide any code excerpt that demonstrates the issue?

    Regards,
    Ryan

  • Hi Ti,

    I already try UART2_flushRx, but no influence. My code as following:

    /*
     * CODE IN INIT
     */
    int8_t uart2_init(void)
    {
        UART2_Params uartParams2;
        
        /* Create a UART: write in BLOCKING mode, and read in callback mode*/
        UART2_Params_init(&uartParams2);
        uartParams2.baudRate = RSBUS_BAUDRATE;
        uartParams2.readMode = UART2_Mode_CALLBACK;
        uartParams2.readCallback = UART2_read_callback;
        uartParams2.readReturnMode = UART2_ReadReturnMode_PARTIAL;
        
        uartHandle = UART2_open(CONFIG_UART2_RSBUS, &uartParams2);
        if (uartHandle == NULL) {
            /* UART2_open() failed */
            Display_printf(display, 0, 0, "UART2_open failed");
            return FALSE;
        }
    }
    
    /*
     * CallBack for uart2 read
     */
    void UART2_read_callback(UART2_Handle handle, void *buf, size_t count, void *userArg, int_fast16_t status)
    {
        rxBufLen = count;
        sem_post(&get_uart2_cmd);
    }
    
    /*
     * Code in main loop
     */
    while(1)
    {
        static int i = 0, total_len = 0;
    
        // UART2_flushRx(uartHandle);
    
        rsbus_send(sendDataBuf, 6);
    
        do{
            // TODO: the RxRingBuffer must be clear, HOW TO DO?
            UART2_read(uartHandle, rsbusRxBuf, RSBUS_PACK_MAX_LENGTH, NULL);
            sem_wait(&get_uart2_cmd);
    
            if(rxBufLen > 9 && !memcmp(&rsbusRxBuf[1], addr, 6))
                break;
            else
            {
                int i, len = rxBufLen;
                Display_printf(display, 0, 0, "len(%d <= 9), keep recv", len);
                for(i = 0; i < len; i++)
                    Display_printf(display, 0, 0, "0x%02x", rsbusRxBuf[i]);
            }
    
        } while(1);
    
        total_len += rxBufLen;
        if(rxBufLen > 9 && rxBufLen < 255)
        {
    //      int cnt;
    //      Display_printf(display, 0, 0, "recv len: %d, total_len: %d", rxBufLen, total_len);
    //      for(cnt = 0; cnt < rxBufLen; cnt++)
    //      {
    //          Display_printf(display, 0, 0, "%d", rsbusRxBuf[cnt]);
    //      }
    
            Display_printf(display, 0, 0, "HOST recv len: %d, total_len: %d, crc: 0x%02x 0x%02x", rxBufLen, total_len, rsbusRxBuf[rxBufLen-2], rsbusRxBuf[rxBufLen-1]);
        }
    
        Task_sleep(5000000 / Clock_tickPeriod);
    }
    

  • It appears that you are trying to clear out the buffer before receiving the expected data.  You could utilize UART2_rxDisable -> UART2_getRxCount -> UART2_read -> UART2_rxEnable to accomplish this.  Or, you can use packet sequencing to recognize unwanted sections of the received data to filter out.

    Regards,
    Ryan