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.

CC2642R: The UART_read buffer displays data from the UART_write buffer. How to fix it?

Part Number: CC2642R

Hello,

I am using a CC2642R microcontroller to exchange UART messages with another microcontroller. The UART configuration is shown below:

    UART_Params_init(&Uparams);
    
    Uparams.writeDataMode   = UART_DATA_BINARY;
    Uparams.readDataMode   = UART_DATA_BINARY;
    Uparams.readMode          = UART_MODE_BLOCKING;
    Uparams.readEcho           = UART_ECHO_OFF;
    Uparams.readTimeout      = 2000000;             
    Uparams.baudRate           = 9600;             

    Uhandle = UART_open(0, &Uparams);
    UART_control(Uhandle, UARTCC26XX_CMD_RETURN_PARTIAL_ENABLE, NULL);

I make a UART_write () command and immediately after sending I expect a response from another microcontroller and call the UART_read () command. But instead of a response from another microcontroller in the UART_read () buffer, I observe my sending from the UART_write () buffer. I have to restart the UART-read () command several times to get the package.

    UART_write(Uhandle, buf, 15);

    while ( (buf1[2] != '>') || (buf1[3] != '>') || (buf1[4]  != ' ') ||
            (buf1[5] != 'v') || (buf1[6] != '1') || (buf1[7]  != '.') ||
            (buf1[8] != '6') || (buf1[9] != '.') || (buf1[10] != '5')  )
    {
        UART_read(Uhandle, buf1, 11);
        lpcnt++;
        if(lpcnt>10) break;
    }


Maybe there is a way to get by with one read request?

Best regards, Maxim

  • Hello Egor,

    Please refer to the UART TI Driver API for further usage information.  I suggest that you do not set the readTimeout as this is most likely what is causing the UART_read to exit prematurely with the write buffer data.  You should be able to check the UART_STATUS_ERROR return value to confirm this.  Using UART_DATA_TEXT would help determine the reception of all data as indicated by a newline character (UART_RETURN_NEWLINE) if the other microcontroller can be programmed for such functionality.  You could also use UART_MODE_CALLBACK unless you intend to pause operation until the UART data is read from the microcontroller.

    Regards,
    Ryan