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.

LAUNCHXL-CC3235SF: UART2 Partial Receive Issue on CC3235SF using UART2_Mode_CALLBACK

Part Number: LAUNCHXL-CC3235SF
Other Parts Discussed in Thread: CC3235SF

Tool/software:

  • Hello,

    I’m currently developing on the CC3235SF using the SimpleLink SDK version 7.10.00.13, with a custom board.
    I'm encountering an issue with UART2 receive behavior when using UART2_Mode_CALLBACK and UART2_ReadReturnMode_PARTIAL.

    Problem Description

    • I’m receiving incomplete UART data during communication with a slave device over Modbus RTU protocol.

    • I have confirmed via oscilloscope that the Rx waveform is complete, but my firmware only receives partial data (e.g., only the first few bytes of a longer response).

    • The issue happens consistently when multiple frames are received consecutively.

    System Setup

    • MCU: CC3235SF

    • SDK: simplelink_cc32xx_sdk_7_10_00_13

    • UART mode: UART2_Mode_CALLBACK

    • Baud rate: 115200

    • Read return mode: UART2_ReadReturnMode_PARTIAL

    • No flow control (Rx/Tx only)

    • Callback re-initiates read of full buffer (256 bytes)

    Code Overview

    In my callback:

    #define UART_RX_BUFFER_SIZE 256
    static uint8_t rxBuffer[UART_RX_BUFFER_SIZE];
    static UART2_Handle uart2Handle;
    static volatile size_t rxBytesReceived = 0;
    
    
    void UART2_readCallback(UART2_Handle handle, void *buf, size_t count, void *userArg, int_fast16_t status)
    {
        if (status == UART2_STATUS_SUCCESS) {
            if ((rxBytesReceived + count) <= UART_RX_BUFFER_SIZE) {
                memcpy(&rxBuffer[rxBytesReceived], buf, count);
                rxBytesReceived += count;
            }
        }
        /* Re-initiate the read to continuously receive data */
        UART2_read(handle, rxBuffer, UART_RX_BUFFER_SIZE, NULL);
    }
    
    size_t UART_getRxData(uint8_t *buffer, size_t bufferSize)
    {
        size_t bytesToCopy = 0;
        if (rxBytesReceived > 0 && buffer != NULL) {
            bytesToCopy = (rxBytesReceived < bufferSize) ? rxBytesReceived : bufferSize;
            memcpy(buffer, rxBuffer, bytesToCopy);
            rxBytesReceived = 0;
            memset(rxBuffer, 0, UART_RX_BUFFER_SIZE);
        }
        return bytesToCopy;
    }
    
    void uartRxInit(void)
    {
        UART2_Params uart2Params;
        int_fast16_t status;
    
        /* Configure UART2 parameters */
        UART2_Params_init(&uart2Params);
        uart2Params.baudRate = 115200;
        uart2Params.readMode = UART2_Mode_CALLBACK;
        uart2Params.writeMode = UART2_Mode_BLOCKING;
        uart2Params.readCallback = UART2_readCallback;
        uart2Params.readReturnMode = UART2_ReadReturnMode_PARTIAL; /* Allow partial reads with timeout */
        uart2Params.userArg = NULL; /* No user argument needed for this example */
    
        /* Open UART2 */
        uart2Handle = UART2_open(CONFIG_UART2_1, &uart2Params);
    
        if (uart2Handle == NULL) {
            /* UART2_open() failed */
            UART_PRINT("Error: UART2_open failed for CONFIG_UART2_1\r\n");
            while (1);
        }
    
        UART_PRINT("UART2 Initialized on CONFIG_UART2_1 (Callback Mode)...\r\n");
    
        /* Initiate the first read operation */
        status = UART2_read(uart2Handle, rxBuffer, UART_RX_BUFFER_SIZE, NULL);
        if (status != UART2_STATUS_SUCCESS) {
            UART_PRINT("Error: Initial UART2_read failed! Status: %d\r\n", status);
        }
    }
    • The callback receives partial chunks of the Modbus RTU packet.

    • In the main thread, I check rxBytesReceived > 0 and copy the data. But often only 5–10 bytes are received when 20–30 were expected.

    • I also tried using 1-byte reads in the callback, same result.

    Things I Have Verified:

    • The UART RX signal is present and clean at the pin.

    • Callback is triggered.

    • Rx buffer isn’t full (256 bytes, Modbus packets are <64 bytes).

    • There’s no memory corruption or task starvation.

    Questions:

    1. Is there any known issue with UART2_ReadReturnMode_PARTIAL not returning all available data?

    2. Is it correct to re-issue a full buffer read (256 bytes) in the callback each time?

    3. Could data loss happen between reads, or should the UART driver handle queuing internally?

    4. Do you have recommendations for reliably receiving complete Modbus RTU frames using UART2_Mode_CALLBACK?

    Thank you for your support

  • Hi Ryan,

    Thanks for sharing the code snippet and details. Can you try this in your UART2_readCallback()? 

    Instead of just checking for status "if (status == UART2_STATUS_SUCCESS)"

    try: "if ((status == UART2_STATUS_SUCCESS) && (count >0))"


    There are no known issues with 'UART2_ReadReturnMode_PARTIAL' mode. In fact, this is the default parameter for UART2.