TM4C123GH6PM: Serial event handling on the TM4C123GH6PM

Part Number: TM4C123GH6PM
Other Parts Discussed in Thread: EK-TM4C123GXL

Tool/software:

Hello,

I initialize the serial port as below:

void init_serial(void) {                    
    MAP_GPIOPinConfigure(GPIO_PA0_U0RX);
    MAP_GPIOPinConfigure(GPIO_PA1_U0TX);
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    MAP_UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);   // UART_CLOCK_PIOSC or UART_CLOCK_SYSTEM
    MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTStdioConfig(0, 230400, 16000000);
}

I want to process nmea data coming from a gps.while doing other things. Is there an example on doing serial handling as the data comes in? Equivalent to:

while(Serial.available()) {

c=Serial.read();

// do stuff with c

}

Best Regards,

C.

  • Hi Can,

      Below is a snippet of code to read from UART and echo it out on the same UART.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    //
    // Enter a loop to read characters from the UART, and write them back
    // (echo). When a line end is received, the loop terminates.
    //
    do
    {
    //
    // Read a character using the blocking read function. This function
    // will not return until a character is available.
    //
    cThisChar = UARTCharGet(UART0_BASE);
    //
    // Write the same character using the blocking write function. This
    // function will not return until there was space in the FIFO and
    // the character is written.
    //
    UARTCharPut(UART0_BASE, cThisChar);
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    You can find UART examples in:

    C:\ti\TivaWare_C_Series-2.2.0.295\examples\peripherals\uart 

    C:\ti\TivaWare_C_Series-2.2.0.295\examples\boards\ek-tm4c123gxl\uart_echo

  • Hi Charles,

    I was using usb-cdc, with ControlHandler, TxHandler, and RxHandler. Is there anyway to use the regular uart in this fashion, I actually just need rx handler, so I guess the example at uart_echo can be modified to suit my needs.

    Another thing I am curious about is how to use the circular ring after  

    cThisChar = UARTCharGet(UART0_BASE);

    Best regards,

    C.

  • I was using usb-cdc, with ControlHandler, TxHandler, and RxHandler. Is there anyway to use the regular uart in this fashion, I actually just need rx handler, so I guess the example at uart_echo can be modified to suit my needs.

    Hi Can,

      I'm not quite following you here. Below is the RXHandler for USB-CDC. What do you mean you want to the regular uart in this fashion? The type of message event (e.g. USB_EVENT_RX_AVAILABLE, USB_EVENT_DATA_REMAINING) that is passed to the RXHandler is specific to the USB CDC class. There is no parameter to pass to a UART ISR. You can use UARTSpaceAvail() to mimic USB_EVENT_DATA_REMAINING and UARTCharGet() to mimic USB_EVENT_RX_AVAILABLE. 

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    uint32_t
    RxHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue,
    void *pvMsgData)
    {
    uint32_t ui32Count;
    //
    // Which event are we being sent?
    //
    switch(ui32Event)
    {
    //
    // A new packet has been received.
    //
    case USB_EVENT_RX_AVAILABLE:
    {
    //
    // Feed some characters into the UART TX FIFO and enable the
    // interrupt so we are told when there is more space.
    //
    USBUARTPrimeTransmit(USB_UART_BASE);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hello Charles,

    What I meant was: The usb-cdc example, along with many other datastructures, uses an interrupt handler so when a packet is received RxHandler gets called. The non-cdc uart examples, do work by polling in a loop to detect incoming data. Am I wrong? Or behind the code usb-cdc examples too work by polling?

    Best Regards,

    Can

  • Hi Can,

      For UART, you can also use the interrupt mode. Check out the C:\ti\TivaWare_C_Series-2.2.0.295\examples\boards\ek-tm4c123gxl\uart_echo example where interrupt is used to receive UART stream and process the data inside the ISR. For USB, the callback is used (e.g. RxHandler), no polling is used.