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 on hardware interrupts

Part Number: CC2640R2F


Tool/software: TI-RTOS

Hi,

I had a quick question about the how the UART driver works.

As I understand it, when using the UART driver, Hardware interrupt is automatically enabled. But how do I get the HWI to point to my function where I process the data?

my code:

In a task:

         uint8_t buffer[20];
         UART_Handle uart;
         UART_Params uartParams;

         // Initialize the UART driver.
         UART_init();

         // Create a UART with data processing off.
         UART_Params_init(&uartParams);
         uartParams.readMode = UART_MODE_BLOCKING;
         uartParams.readCallback = UartRxFxn;
         uartParams.writeDataMode = UART_DATA_BINARY;
         uartParams.readDataMode = UART_DATA_BINARY;
         uartParams.readReturnMode = UART_RETURN_FULL;
         uartParams.readEcho = UART_ECHO_OFF;
         uartParams.baudRate = 9600;

uart = UART_open(Board_UART0, &uartParams);

static void UartRxFxn(UART_Handle handle, void *buf, size_t count){
    System_printf("task firing\n");
    System_flush();
    Semaphore_post(uartSem);
}

Reading and Writing to UART works fine by calling UART_read() and UART_write(). But how do I get the hardware interrupt to point to "UartRxFxn"?

The application locks up in UART_open() if I try to define the HWI myself(interrupt vector 21).

Any ideas? :-)

  • Hi Viggo,

    The UART driver has 2 modes of operation which can be set in the params (this can be configured independently for read & write operations): blocking & callback.  When in blocking mode the task which calls the read/write operation is blocked (execution is halted) until all data is sent/received.  In callback mode the task which calls the read/write operation continues execution & when the driver finished sending/receiving all of the data it calls the respective callback function (these must be set in the params).

    From your code snips above it seems like you want to register your own callback function for read.  It looks mostly good, you need only change:

    uartParams.readMode = UART_MODE_CALLBACK

    Hope this helps,

    -- Emmanuel