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.

CC2640R2L: Serial port "partial return" function, question about return method

Part Number: CC2640R2L

Hi Team,

When using the 2640 serial port, configure the callback mode and turn on the partial return function to receive an undetermined string,

normally the 2640 serial port receives a string that can be received as a packet.

However, when the sender sends a slightly larger delay between characters, the 2640 receive is subcontracted, which should be due to the partial return function. 

I want to know what the default time for this serial port return function is and how it is configured.

// Callback function
static void UartreadCallback(UART_Handle handle, void *rxBuf, size_t size)
{

    //UserUART_config[0].fxnTablePtr->writeFxn(Uarthandle,rxBuf,size);
    UartReceiveDataProcess(rxBuf,size);
    UserUART_config[0].fxnTablePtr->readFxn(Uarthandle,UserrxBuf,wantedRxBytes);

}


void UserUartInit(void)
{
    // Initialize the UART driver.
    UART_init();

    // Create a UART with data processing off.
    UART_Params_init(&Uartparams);                                //初始化是赋予一个默认值
    Uartparams.baudRate      = 9600;
    Uartparams.writeDataMode = UART_DATA_BINARY;                  //可以选择二进制格式还是10进制格式
    Uartparams.readMode      = UART_MODE_CALLBACK;
    Uartparams.readDataMode  = UART_DATA_BINARY;
    Uartparams.readCallback  = UartreadCallback;

    Uarthandle = UART_open(Board_UART0, &Uartparams);
    if (Uarthandle == NULL)
    {
        // UART_open() failed
        while (1)
            ;
    }
    UserUART_config[0].fxnTablePtr->controlFxn(Uarthandle, UARTCC26XX_CMD_RETURN_PARTIAL_ENABLE, NULL);

    wantedRxBytes = 100;
    UserUART_config[0].fxnTablePtr->readFxn(Uarthandle, UserrxBuf, wantedRxBytes);
}

Best Regards,

Galaxy

  • Hello Galaxy,

    I hope you are doing well. If you need to measure the latency of the program, you could use a GPIO pin (high/low) with a logic analyzer to read the highs and lows at specific points in the program as needed. 

    -Are you using UART to receive character data from something like PuTTY? 

    -What SDK version, and baseline example did you use? 

    Thanks,
    Alex F

  • Hi Alex,

    Another MCU is used to send data regularly through a timer.

    The SDK version is simplelink_cc2640r2_sdk_1_40_00_45 and the benchmark example is simple_peripheral

    The purpose is not to measure the program delay, but to know the principle and detailed information of the "partial return" of the serial port in callback mode, including under what conditions a partial return can be triggered. If there is no data for a certain period of time, a partial return will be triggered, so how to configure this time?

    The problem I am encountering now is: configure the serial port in callback mode and enable the partial return function. When the interval between received bytes is <4ms, these bytes will be considered as a packet of data and returned through the callback. When the interval between received bytes is >5ms, each of these bytes will trigger an independent callback and become a separate byte. I don’t want this phenomenon to occur. I hope that when the interval between each byte is <10ms, it can be considered as a packet and returned. , how can I achieve?

    Best Regards,

    Galaxy

  • Hello Galaxy,

    Thank you for explaining your problem in detail. I think there are a few ways we can achieve a solution, first is by using certain UART parameters, like the ReturnMode field, which can be configured to execute callback when the buffer is full or when a newline character is received. This way the program can either wait till the buffer is complete or a newline is entered. 

    If you do use the ReturnMode you will also need to change the DataMode, as described in the notes below. 

    You may be able to use a semaphore and a delay to allow the buffer to receive more data as well. 

    Thanks,
    Alex F

  • Hi Alex F, 

    He needs to use callback mode, and because it is variable-length data, he cannot use RETURN_FULL, and his data is streaming data, not text, and he cannot use NEW_Line. He hopes you focus on his question: "Returning to the serial port part "Explanation of function, conditions for partial return, adjustment of partial return duration", instead of transferring the question. He thinks what he consult is a fairly detailed and clear question, if you are keen on refactoring his function, he can submit his code, please help him implement it in other ways.

    From the customer:

    The question should be how to configure the partial return function so that data <10ms is not subpackaged. I hope to realize my function by adjusting the partial return function, because I have reasons to use callback mode and partial return, so please pay attention the question itself.

    Best Regards,

    Galaxy

  • Hi Alex F, 

    From the customer:

    I've found a description of the "Partial Return Timeout Mechanism" as follows (note the comments section):

    /*!
     * @brief Command used by UART_control to enable partial return
     *
     * Enabling this command allows UART_read to return partial data if data
     * reception is inactive for a given 32-bit period.  With this command @b arg
     * is @a don't @a care and it returns UART_STATUS_SUCCESS.
     */
    #define UARTCC26XX_CMD_RETURN_PARTIAL_ENABLE    UART_CMD_RESERVED + 0

    At 9600 baud, one bit is transmitted at 0.104 ms, and 32 cycles is 3.32 ms
    This is consistent with my current testing.
    Now my question is, can this 32 bit be modified or configured? I want to wait a longer period.

    Best Regards,

    Galaxy

  • Hello Galaxy, 

    The 32-bit inactive period is not user modifiable as it is set by the HW itself. 

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

    You could configure readTimeout and writeTimeout to work for your use case, as the period fields are modifiable. (Note that UART_Params.readTimeout is not in use when using UART_MODE_CALLBACK mode, so you may have to create your own callback/task to handle the data). 

    UARTCC26XX.h File Reference (ti.com)

    Thanks,
    Alex F

  • Hi Alex F,

    Thanks for your support !

    It's useful for us.

    Thanks~

    Best Regards,

    Galaxy