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/LAUNCHXL-CC1310: UART RX Interrupt

Part Number: LAUNCHXL-CC1310

Tool/software: TI-RTOS

Hello,

I'm trying to setup an RX interrupt to gets fired when a byte is received.

With a little help through this forum I found I have to setup a callback routine.
Unfortunately my code does not seem to work.

I could use some help to figure out what I missed in the code below.
All my code so far is based on rfEasyLinkNp example

My code worked in blocking mode without the call back routine. Tx and Rx both work fine.

static UART_Handle uartHdl;

void com_port_init(void)
{
    UART_Params uartParams;

    /* Create a UART with data processing off. */
    UART_Params_init(&uartParams);
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.readDataMode = UART_DATA_BINARY;
    uartParams.dataLength = UART_LEN_8;
    uartParams.stopBits = UART_STOP_ONE;
    uartParams.readReturnMode = UART_RETURN_FULL;
    uartParams.readMode = UART_MODE_CALLBACK;
    uartParams.readCallback = uart_call_back_routine;
    //uartParams.readTimeout = UART_WAIT_FOREVER; //(10000 / Clock_tickPeriod); //return after blocking for 10ms
    uartParams.readEcho = UART_ECHO_ON;
    uartParams.baudRate = 115200;
    uartHdl = UART_open(Board_UART0, &uartParams);

    if (uartHdl == NULL)
    {
        System_abort("Error opening the UART");
    }
}

void com_port_send_string(const char *str_data)
{
    if (*str_data==0)
        return;
    uint32_t len = strlen(str_data);
    UART_write(uartHdl, str_data, len);
}


static int32_t com_port_get_byte(uint8_t * b)
{
    uint32_t bytes = 0;
    bytes = UART_read(uartHdl, b, 1);
    return bytes;
}

void com_port_send_byte(uint8_t b)
{
    UART_write(uartHdl, &b, 1);
}

static void uart_call_back_routine(UART_Handle handle, void *buf, size_t count)
{
    com_port_send_byte('A');
}

I would expect to see the A character to be printed in screen every time I hit a key from my keyboard, but it isn't.
Did I do something wrong here?

  • Hi Get,

    Did you call the driver init function UART_init()?

    You can see the Uart Echo driver project if you want a starting point for your project.
  • I tried to modify the uart echo example using the same pattern, but didn't work. Any advice?

  • Hi Get,

    What do you mean by "modify using the same pattern"?

    Also, can you describe a little more in detail what you mean by "it didn't work". Is the application running? Did you use a breakpoint to check the uart buffers after you have written your character?
  • Yes, the application is running but when I add the callback function in order to read byte nothing seems to be read.
    By the "same patter" I meant that I just opened the example uartecho and added a callback routine.
  • Hi Get,

    You should check the size of received data in the callback. Can you try using the suggested callback function from the Drivers API description?

    // 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()
        }
    }
    

  • GeT,

    Can you share how you implement your functions shared above?

    Warning: Do not call UART_read() from its own callback function when in UART_MODE_CALLBACK.

    Derrick