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: Handling UART data buffer

Part Number: CC2340R5

Tool/software:

Hi,

We are using UART with baud rate 9600, the host controller will send data of 1000-2000 bytes with the interval of 500ms.

The same data we have to transmit over the air with MTU of 247. 

If we are sending 1000 bytes with interval of 1sec then only we are able to see all the data properly, below 1sec we are observing packet mismatch/missing,

Below is our UART callback implementation.

#define UART_MAX_READ_SIZE	1000

uint8_t uartReadBuffer[UART_MAX_READ_SIZE];

void UARTCallback(UART2_Handle handle, void *buffer, size_t count, void *userArg, int_fast16_t status)
{
   
    uint8_t *idx = NULL;
    uint8_t *data = BLEAppUtil_malloc(count + 2); 
    idx = data;
    *idx = count;
    idx++;
    *idx = count >> 8;
    idx++;
    memcpy(idx, buffer, count);
    BLEAppUtil_invokeFunction(HandlingFunction, data);
    memset(uartReadBuffer,0,sizeof(uartReadBuffer));
    UART2_flushRx(handle);
}

void HandlingFunction(char *pData)
{
	//sending over the air
	UART2_read(uart, &uartReadBuffer, UART_MAX_READ_SIZE,0);
}

Here if host controller is sending more than 1000 bytes, we want to ignore the extra bytes, and want to handle new packet,

but what we are observing is old extra bytes are added in the next UART read along with new packet data.

Kindly suggest proper way of handling this scenario.

Regards, 

Vignesh.

  • Looks like baudrate 9600 is a little bit slow to send 1000-2000 bytes. I would suggest using higher baudrate.

  • Hi Vignesh,

    With a UART baud rate of 9600, you can get ~960 byte/s of throughput - see details here. You mentioned you want to transmit "1000-2000 bytes with the interval of 500ms", i.e. up to 4000 bytes/s. The baudrate selected is then too small. You should increase it. As the CC2340R5 supports UART baud rate up to 3 MBaud, it should not be an issue.

    Here, I would recommend to set the UART baudrate to 115200.

    I hope this will help,

    Best regards,