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.

TM4C129ENCPDT: UART example, wrong baud only when using xtal 25MHz w/o PLL

Part Number: TM4C129ENCPDT


Hi. I'm doing the UART example, supposed to be 115200 baud and it is when I use internal osc but when I use the external 25MHz crystal I'm actually getting 74184 baud. (using TivaWare_C_Series-2.1.4.178)

I measured external xtal and it's running at 25MHz exact.

    ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN |
                                       SYSCTL_USE_OSC), 25000000);

I verified with debugger that ui32SysClock is set to 25000000.

...

    MAP_UARTConfigSetExpClk(UART0_BASE, ui32SysClock, 115200,
                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));

Alternatively when I use internal osc, as shown below, then the baudrate is actually 115200 (and ui32SysClock will be set to 16000000 this time).

    ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_16MHZ | SYSCTL_OSC_INT |
                                       SYSCTL_USE_OSC), 16000000);

I'm just curious what could be the cause.

I also tried the PLL like so:

    ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN |
                                       SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);

System is running much faster of course but the baudrate is actually correct, 115200 and ui32SysClock is set to 120000000.

  • Hello Pgib,

    Even for 25MHz you can use the PLL. Can you try these settings and see if that works?

        g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                                 SYSCTL_OSC_MAIN |
                                                 SYSCTL_USE_PLL |
                                                 SYSCTL_CFG_VCO_480), 25000000);

    There was a whole thread about the setup of MOSC with a 25MHz crystal you may want to read through: https://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/515364

    If the PLL config at 25MHz works for you, that should be a good solution, otherwise I'd suggesting read the details of the thread and trying to check your SysClk output like R Sexton did (he found his was not at 25MHz) - and if you get the same behavior then follow the thread to find the resolution for your application.

  • Hi Ralph.

    So I tried your clock settings, those also did work, and by working I mean that the UART baudrate is what it is supposed to be (115200).

    With your settings g_ui32SysClock (aka ui32SysClock) was set to 24MHz, which is understandable since the PLL is 480MHz.

    I also went ahead with your other suggestion to look at a clock output. The best thing I found for that was DIVCLK, I'm not sure if that is what you had in mind.

    I configured it like so:

        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOQ);
        while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOQ));
        MAP_GPIOPinConfigure(GPIO_PQ4_DIVSCLK);
        GPIODirModeSet(GPIO_PORTQ_BASE, GPIO_PIN_4, GPIO_DIR_MODE_HW);
        GPIOPadConfigSet(GPIO_PORTQ_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
        HWREG(0x400fe148) = 0x80000000;
    

    Maybe this makes perfect sense but not at all what I was expecting because the output signal from that pin (102) was 750KHz. Not sure what to make of that.

    Anyways, so far this isn't a real issue for me because the baudrate is correct when I use the PLL and I'm going to be running this with the PLL anyways.

    I also previously came across the issue from the errata but since I'm using the latest and greatest driverlib (2.1.4.178) I figured that this didn't apply to me.

    Interestingly enough I'm also working on the bootloader, which is totally a separate CCS project and here too I'm getting a bad baudrate, this one is at 74074 baud. That doesn't stop me from doing my work, I just set LM Flash Loader to this and carry on. However if you are curious about this then I'd be willing to try other things that come to mind.

    Kind regards,

    Pascal