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.

[FAQ] LP-EM-CC2340R5: Guide: Adding eventMask, and eventCallback support to uart2echo example

Part Number: LP-EM-CC2340R5
Other Parts Discussed in Thread: CC2340R5

The following details how to modify the uart2echo SDK example to enable the event Mask, and event Callback overrun on the LP-EM-CC2340R5.


By implementing the following code snippets into your uart2echo example you will be able to detect when an overrun event has occurred, track the total overrun events, and see a green LED toggle as the overrun events occur. 


  1. In CCS, import the uart2echo example located in your SDK ...\examples\rtos\LP_EM_CC2340R5\drivers.
  2. Go into uart2echo.syscfg and in TI Drivers click on GPIO and add CONFIG_GPIO_GLED; configure the hardware as LaunchPad LED Green to use the green LED on your board. 
  3. In uart2echo.c file define global variables for use later. 

/* Declare global variables */
uint32_t glostat = 0; //stat to check the total numver of overrun events 
uint32_t glostatnot = 0;
uint8_t uhOh = 0; //flag to check if overrun event has occurred 

       4. Setup the green LED config in a similar manner to the red LED 


        5. In the mainThread in the uartParams section (before UART is opened) define the eventCallback and eventMask.

    uartParams.eventCallback = eventcallbackFxn; 
    uartParams.eventMask     = UART2_EVENT_OVERRUN; 

        6. Setup the eventcallbackFxn, this function will occur when an overrun event has occurred and will toggle the green LED as well as tracking the current total number of overrun events by incrementing glostat; we will also change the state of the uhOh flag to indicate that an overrun event has occurred (to be used later). 

 * ======== eventcallbackFxn ========
void eventcallbackFxn(UART2_Handle handle, uint32_t event, uint32_t data, void *userArg)
    if (event == UART2_EVENT_OVERRUN) //check if the event is overrun event 
        uhOh = 1;
        GPIO_toggle(CONFIG_GPIO_GLED); //if its valid this should still work.


        7. In mainThread, in the while(1) loop add the following code, this code will clear the FIFO buffer when a certain number of bytes is read, or when an overrun event is detected (by the uhOh flag). 

 if(numBytesRead > 64)
    uhOh = 0;
    const char overrunPrompt[] = "\r\nOverrun Event Occurred, clearing RX buffer:\r\n";
    UART2_write(uart, overrunPrompt, sizeof(overrunPrompt), NULL);

        8. Build, load, and run the program, use PuTTY to connect to the device, and by entering too many characters you will see the overrun event execute, and see the green LED toggle on your board.   

This example was evaluated on the 7_40_00_64 SDK, on CCS 12.5.