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.

CC2652R: UART read taking too long

Part Number: CC2652R

I'm using CC2652R development kit to communicate a modem via UART interface.

This is the UART configuration i'm using:

UART_Params uart_params;
UART_Params_init(&uart_params);
uart_params.writeDataMode  = UART_DATA_BINARY;
uart_params.writeMode      = UART_MODE_BLOCKING;
uart_params.readDataMode   = UART_DATA_BINARY;
uart_params.readReturnMode = UART_RETURN_NEWLINE;
uart_params.readEcho       = UART_ECHO_OFF;
uart_params.readMode       = UART_MODE_BLOCKING;
uart_params.readTimeout    = msecs2Tick(ME310G1_READ_TIMEOUT); //5 seconds waiting for modem answer
uart_params.baudRate       = ME310G1_READ_BAUDRATE;

Since reading in mode 'UART_RETURN_NEWLINE' doesn't work, i'm waiting 5 seconds for every write and read operations - waiting for read timeout to end.

This mechanism works fine for me, except it's taking too much time.

I tried to implement different read method using read mode 'UART_MODE_CALLBACK' (and a callback) in order to speed up read process like this:

read(void * destination, size_t size)
{
    size_t receive = 0;
    uint8_t * dst = (uint8_t *)destination;
    int result = 0;
    while(size > 0 && result != UART_STATUS_ERROR)
    {
          //Read single byte
          char dummy;
          result = UART_read(g_uart_handle, &dummy, 1);
          if(result != UART_STATUS_ERROR)
          {
              dst[receive] = dummy;
              receive++;
              size--;
          }
    }
}

The problem with this implementation is that i'm reading zeros bytes since the modem doesn't answer back fast enough.

If i'm inserting a small delay after every byte read, i manage to read appropriately part of the responds from the modem.

Is there something i can do in order to solve this issue ?

I can supply further information if needed.

Thx,

Dekel

  • Hi Dekel,

    Please refer to UART.h from the TI Drivers Runtime API.  If the modem cannot provide a newline and you would like to process incoming bytes immediately then I recommend you set readDataMode = UART_DATA_BINARY and readReturnMode = UART_RETURN_FULL to process bytes individually in your application.

    Regards,
    Ryan

  • Thanks for replaying !

    The modem can provide a new line but i read at the forums that the option 'UART_RETURN_NEWLINE' isn't support by the driver, and it didn't work for me when i tried to use it.

    Basically i came up with a solution but I'm not sure if it's going to work all the time.

    It looks like:

    size_t me310g1_read(void * destination, size_t size)
    {
        size_t receive = 0;
    
        if (g_uart_handle)
        {
            //We are trying to read few times since the modem might not answer fast enough
            int retries = 10;
            while(receive < 10 && retries > 0)
            {
                receive = UART_read(g_uart_handle, destination, size);
                retries--;
            }
        }
    
         return receive;
    }

    I split the reads to ten attempts and each one of them is half a second. Besides that, I changed my UART configurations to:

    uart_params.writeDataMode  = UART_DATA_BINARY;
    uart_params.writeMode      = UART_MODE_BLOCKING;
    uart_params.readDataMode   = UART_DATA_BINARY;
    uart_params.readReturnMode = UART_RETURN_FULL;
    uart_params.readEcho       = UART_ECHO_OFF;
    uart_params.readMode       = UART_MODE_BLOCKING;
    uart_params.readTimeout    = msecs2Tick(500);
    uart_params.baudRate       = ME310G1_READ_BAUDRATE;

    If you come up with a different solution i would be happy to read it

    Thanks,

    Dekel

  • UART_RETURN_NEWLINE is supported and is the default value for UART_Params_init.  There could be a misinterpretation of the driver or settings that is causing it not to operate as expected.  I would still encourage you to consider callbacks, there is a uart2callback example which you can reference and port to the UART driver.  Here is a relevant E2E post (and another one) as well.

    Regards,
    Ryan