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.

RTOS/CC2640R2F: UART issue using POWER_SAVING mode on BLE projects (CC26XX)

Part Number: CC2640R2F

Tool/software: TI-RTOS

Dear TI,

I am currently having some UART connection problems and came across this relevant post. I am using SDK 1.50.00.58 with the CC2640R2. I am using the POWER_SAVING define in the simple_peripheral_cc2640r2lp_oad_offchip example and have added some UART function calls with a proprietary peripheral device. Concretely I am doing the following in a task context:

/* Write some data */
UART_write(uartHandle, buf_send, buf_ptr);
/* Read some data */
while (UART_read(uartHandle, &buf, 1)) {
    /* Do something with buf */
}

Unfortunately this does not always perform as I would expect. Our peripheral device sends correct data (sniffed with logic analyzer) but it is not always received by the CC2640R2 in the while loop. When I turn off POWER_SAVING there seem to be no problems. Also when I disable all other tasks this seems to go fine. Do you have any advice for me when trying to integrate the UART with POWER_SAVING mode? Or should this work as intended? 

I am using drivers in MODE_CALLBACK with a read timeout of 2000. I have tried to set power constraints before writing and after the while loop, but I am not sure if this is the route to go. Any advice regarding power_saving and uart would be appreciated. 

Best regards,

Mattia

  • Hi Mattia,

    When you receive your UART message Queue it then process the message. This way the device will not go to Standby Mode.

    -kel
  • Hi Kel,

    Thanks for your response, but I do not understand the solution you propose. Are you suggesting I should enqueue the received bytes into a queue, do a context switch and then process the message? I do not see how this would solve the problem as I am not receiving all bytes correctly in the first place. 

  • Hi Mattia,

        See uart doxygen documentation at "file:///C:/ti/simplelink_cc2640r2_sdk_1_50_00_58/docs/tidrivers/doxygen/html/_u_a_r_t_c_c26_x_x_8h.html". Here below is code snippet for receive continuously in UART_MODE_CALLBACK.

    #define MAX_NUM_RX_BYTES    1000   // Maximum RX bytes to receive in one go
    #define MAX_NUM_TX_BYTES    1000   // Maximum TX bytes to send in one go
    uint32_t wantedRxBytes;            // Number of bytes received so far
    uint8_t rxBuf[MAX_NUM_RX_BYTES];   // Receive buffer
    uint8_t txBuf[MAX_NUM_TX_BYTES];   // Transmit buffer
    // Callback function
    static void readCallback(UART_Handle handle, void *rxBuf, size_t size)
    {
        // Make sure we received all expected bytes
        if (size == wantedRxBytes) {
            // Copy bytes from RX buffer to TX buffer
           for(size_t i = 0; i < size; i++)
               txBuf[i] = ((uint8_t*)rxBuf)[i];
           // Echo the bytes received back to transmitter
           UART_write(handle, txBuf, size);
           // Start another read, with size the same as it was during first call to
           // UART_read()
           UART_read(handle, rxBuf, wantedRxBytes);
        }
        else {
            // Handle error or call to UART_readCancel()
        }
    }
    static void taskFxn(uintptr_t a0, uintptr_t a1)
    {
        UART_Handle handle;
        UART_Params params;
        // Init UART and specify non-default parameters
        UART_Params_init(&params);
        params.baudRate      = 9600;
        params.writeDataMode = UART_DATA_BINARY;
        params.readMode      = UART_MODE_CALLBACK;
        params.readDataMode  = UART_DATA_BINARY;
        params.readCallback  = readCallback;
        // Open the UART and initiate the first read
        handle = UART_open(Board_UART, &params);
        wantedRxBytes = 16;
        int rxBytes = UART_read(handle, rxBuf, wantedRxBytes);
        while(true); // Wait forever
    }

    The echoing of characters back is just for demo. In some implementation it will cause problems.

    As you can see in this implementation it will continuously receive characters. You can wait for a terminating character example \r then Queue the message to main task. Queue using SimpleBLEPeripheral_enqueueMsg().

    -kel

    Another tip at SDK v1.40 The UART_close() does not close the UART port and will still consume current.