Clock configuration trouble - Xmega32A4

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Trying to bring up an Xmega32A4 board of my own design. Got PORT D to flash, but the clock configuration code I added next disappoints. Based on the forum posts on this topic I whittled it down to what you see here. The problems are:

1. CLK.CTRL = 0x02; has no effect, so the chip never switches from 2 MHz to 32 MHz.

2. Nothing I try turns off the 2 MHz internal oscillator. Not a huge problem, but just curious why I'm not able to. May be related to 1., above; the chip may prevent me from disabling a clock source if another one isn't selected.

I'm using ICCAVR, AVR Studio 4, and JTAGICE Mk II, however I've duplicated the problem in AVR-GCC.

Thanks for any suggestions.

#include 
#include 

void ClockConfig(void)
{
    OSC.CTRL |= 0x02;          // Enable 32MHz internal oscillator
    while (!( OSC.STATUS & 0x02));  // Wait for oscillator to stabilize
    CLK.CTRL = 0x02;     // Select 32MHz internal oscillator
    OSC.CTRL &= 0x02;  // Turn off 2MHz internal oscillator
}

int main(void)
{
    char x = 0;
    ClockConfig();

    // Insert code

    PORTD.DIR=0xff;
    PORTD.OUTSET = 0xff;
    while (1)
    {
        PORTD.OUTTGL = 0xff;
    }

    return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You have not assigned the security key required when any clock-thingy is modified. See chapter 3.12 "Configuration Change Protection" of the XMEGA A Manual.

I also suggest that you look at the Config32MHzClock() function found on many XMega examples (I got some from BostonAndroid web site).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, itai. That was partly it. I removed that code during my simplification, thinking it was optional. However, another mistake was CLK.CTRL = 0x02 should be CLK.CTRL = 0x01; that mistake came from substituting the wrong number for a bitmask, again to "simplify." ;-) Anyway, problem solved.