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.

CC2340R5: UART2, callback mode continuous read

Part Number: CC2340R5
Other Parts Discussed in Thread: SYSCONFIG

Is it possible to use this driver for continuous data reception? The thing is that I can't buffer the entire frame due to lack of RAM. Currently, I use a small buffer for UART - 32B, in the rx callback I copy the data to the ring buffer and start data reception again from the callback. The problem is that sometimes 1 byte of data is lost.


Artur

  • Hello Artur Watala,

    If you have not referneced these already, we have some nice UART examples here: UART2.h File Reference.

    We could also try increasing the buffer to 33.

    Hoe limited on RAM are you?

    What base example did you start with for your project?

    Thanks,
    Akex F

  • static void init_function()
    {
    // Create a UART in CALLBACK read mode
    UART2_Params_init( &uartParams );
    uartParams.readMode = UART2_Mode_CALLBACK;
    uartParams.writeMode = UART2_Mode_CALLBACK;
    uartParams.readCallback = callbackFxnRx;
    uartParams.writeCallback = callbackFxnTx;
    uartParams.baudRate = baudRate;
    uartParams.userArg = NULL;

    uart = UART2_open( portIndex, &uartParams );

    if ( uart != NULL )
    {
    UART2_read( uart, dmaRxBuffer, UART_DMA_READ_BUF_SIZE, NULL ); // start DMA rx
    return true;
    }
    }


    static void callbackFxnRx( UART2_Handle handle, void *buffer, size_t count, void *userArg, int_fast16_t status )
    {
    if ( status != UART2_STATUS_SUCCESS )
    {
    /* RX error occured in UART2_read() */
    }

    if ( cbuffer_write( &cbuffer_rx, dmaRxBuffer, count ) < count )
    {
    /* cbuffer overflow */
    }

    UART2_read( uart, dmaRxBuffer, UART_DMA_READ_BUF_SIZE, NULL ); // start next DMA transfer
    }

    It looks something like this. It seems that if the buffer fills up during transmission, data is lost during DMA restart. But not always. Will increasing the buffer by 1 byte change anything?

  • Hello Artur 

    Did you set the return mode anywhere? 

    You could specifically define either FULL or PARTIAL depending on your application to see if the other setting may help fix your issue. 

    Did you try using Semaphores to protect the callback or data in order to let the buffer unfill correctly?

    Thanks,
    Alex F

  • Hello,

    Right, I forgot to set ReadReturMode parameter, but unfortunately that didn't solve the problem. I enclosed the buffer reading in the critical section, but that didn't help either. Using logic analyzer I can see that a byte sent while the program is in rx callback is lost. 

  • Hello Artur,

    I wanted to ask what you have set your RX Ring buffer size to in sysconfig, and if that could be the issue: 

    there are a few E2E posts that might be worth a read: 

    https://e2e.ti.com/f/1/t/1325156/

    https://e2e.ti.com/f/1/t/1275776/

    Thanks,
    Alex F