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.

EK-TM4C123GXL: Clock Initialization and Configuration

Part Number: EK-TM4C123GXL

I'm trying to configure my Launchpad to run at 80MHz.

I'm not using TivaWare for this.

I'm following the instrauctions as for  page 231 5.3 Initialization and Configuration
but I'm not having success as the clock clearly is not running at 80MHz.

This is what I'm doing as first thing in main function.

Maybe someone can spot the error! Thx.

void clockSetup(){
    // Run-Mode Clock Configuration(RCC) reset value  0x078E3AD1 

    // Get Values
    unsigned int RCC_i = SYSCTL->RCC;
    unsigned int RCC2_i = SYSCTL->RCC2;
    unsigned int MOSCCTL = SYSCTL->MOSCCTL;

    SYSCTL->RCC = 0x078E3AD1U; // Reset the register
    unsigned int RCC_r = SYSCTL->RCC; // Should read 0x078E3AD1U

    SYSCTL->RCC &= ~(0x01U << 11); // PLL Bypass (0x0 use PLL)

    // Main Oscillator Disable (MOSCDIS)
    // 0 enabled (default), 1 disabled 

    SYSCTL->RCC |= (0x01U << 22); // Enable System Clock Divider
    SYSCTL->RCC |= (0x15U << 6); // Set XTAL value 16Mhz

    unsigned int RCC_c = SYSCTL->RCC;

    // Run-Mode Clock Configuration 2(RCC2)reset value  0x07C06810 
    SYSCTL->RCC2 = 0x07C06810; // reset register

    unsigned int RCC2_r = SYSCTL->RCC;

    SYSCTL->RCC2 |= (0x01U << 31); // Use RCC2
    SYSCTL->RCC2 |= (0x01U << 30); // Divide PLL as 400 MHz
    SYSCTL->RCC2 &= ~(0x01U << 13);// Power-Down PLL (overrides RCC)
    SYSCTL->RCC2 &= ~(0x01U << 11);// PLL Bypass (overrides RCC)
    SYSCTL->RCC2 &= ~(0x07U << 4); // Oscillator Source (overrides RCC) select Main Oscillator (MOSC)
    SYSCTL->RCC2 |= (0x02U << 23); // System Clock Divisor         |
    SYSCTL->RCC2 &= ~(0x01U << 22);// Additional LSB for SYSDIV2   | 80Mhz

    unsigned int RCC2_c = SYSCTL->RCC2;
    unsigned int RCC_f = SYSCTL->RCC;
    unsigned int RCC2_f = SYSCTL->RCC2;


   // wait for 16ms is deferred to the caller

}

  • Michele Gavazzeni said:
    I'm not using TivaWare for this.

    Michele,

    You may be bombed by criticism on this post, for the reason above.

    Don't waste your valuable time doing things the wrong way. You will not learn anything useful from that exercise, will tire out your mind, and add unnecessary complexity to your code. Simply use the proper TivaWare configuration for a TM4C123:

    SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);

    Should you prefer to insist on that route, then enjoy the consequences and go figure out the problem yourself - because one of the uses of Tivaware is EXACTLY to avoid wasting time looking for register configuration mistakes or typos!

    Now, if you'd like to study the different clock configurations (such as using PLL or not, and others), that can be interesting - but still, stick to Tivaware drivers. You can always look at the register values in your IDE to see what happened!

    Cheers

    Bruno

  • Hi Bruno,

    Thank you. Fully agreed. TivaWare exists to avoid these issues, please leverage it Michele.
  • While "not" bombing - may this serve as Vote #3 for the advice of posters Bruno & Ralph? And while "banned for now" - TWO "LIKES" have been entered for each gentleman.

    Some claim is made for "deeper learning" via Direct Register. Yet - inevitably - such "learning" is confined to, "DRM is time & effort EATING" and most always results in, "Does NOT Work!"

    You may - if you must - always review the Register Manipulations - done properly - via vendor's (excellent) API.

    (aside to vendor's Ralph: - Firm/I have long noted that the MCU manuals "NEVER" make mention of the API - in fact the few code examples therein - are (drumbeat) via "DRM."    We may not be as "innocent" as we believe - by "blocking" any/all mention of the API - w/in the defining MCU document...    Surely this is NOT your doing - yet its curious - and not helpful - don't you agree?)