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.

TM4C123GH6PM: Tivaware UART configuration

Part Number: TM4C123GH6PM


Hi,

Reading the tivaware library documentation and some example code, I see that the uart clock passed to the UARTConfigSetExpClk function is the value returned by SysCtlClockGet(), but in my case that doesn't work and I wonder why.

I configure the system clock as:

    /* Set system clock */
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

Then, in the uart configuration steps, I have to set the uart clock manually to 16000000 for it to work:

    ROM_UARTConfigSetExpClk(UART0_BASE, 16000000, 115200,
                            (UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE |UART_CONFIG_WLEN_8));

Because if I use SysCtlClockGet() instead of 16000000 the baudrate is not set properly and I receive garbage through the serial port

    ROM_UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
                            (UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE |UART_CONFIG_WLEN_8));  // THIS DOESN'T SEEM TO SET THE BAUDRATE PROPERLY

Can someone explain me why, if I use SysCtlClockGet()  (that is actually returning 40000000), it doesn't work? I thought that the uart peripheral clock was the same as the system clock.

Thanks

  • Hello Javi,

    In your first ROM_UARTConfigSetExpClk API you are saying the System Clock is running at 16 MHz manually, which is incorrect. Your clock setting is 40 MHz.

    Your API for configuration for UART looks fine. I suspect something else is going on. Either you don't have the send and/or receive setup right, or your terminal program isn't set for the right baud rates.

    I tested uart_echo from TivaWare using your system clock divider, it is as 115200 baud example as well, and it worked just fine.
  • Hello Ralph,

    thanks for your answer. Reviewing the code I see that I am using the internal 16MHz clock for the UART... that explains why it only works when I configure the uart clock to 16MHz, so silly, sorry for that.

    This is how I configure the UART:

    void UART0_Init(void)
    {
        //
        // Enable the GPIO Peripheral used by the UART.
        //
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    
        //
        // Enable UART0
        //
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
        // Wait for the UART0 module to be ready
        while(!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_UART0))
        {
        }
    
        //
        // Configure GPIO Pins for UART mode.
        //
        ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
        ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
        ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
        //
        // Use the internal 16MHz oscillator as the UART clock source.  -> here it is!
        //
        UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
    
        //
        // Configure the UART for 115,200, 8-N-1 operation.
        //
        ROM_UARTConfigSetExpClk(UART0_BASE, 16000000, 115200,
                                (UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE |UART_CONFIG_WLEN_8));
    
        //
        // Enable the UART operation.
        //
        ROM_UARTEnable(UART0_BASE);
    
        //
        // Enable the UART RX interrupt.
        //
        ROM_IntEnable(INT_UART0);
        ROM_UARTIntEnable(UART0_BASE, UART_INT_RX);
    
    
        UART0_LCRH_R &= ~(1U << 4); /* disable fifo */
    }


    I guess I will have to use UART_CLOCK_SYSTEM in UARTClockSourceSet

    Thanks!

    Javi