XMega external oscillator

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

Just in case anyone else is having problems... I couldn't get the sysclk_driver example code to start-up an external crystal oscillator. I didn't try to track down where the problem is (driver or includes or me using the driver).

Anyway, the following works to get a 7.3728Mhz crystal running with a system clock of 29.4912Mhz:

cli();

// 2-9 Mhz, 256 clk
//0 1 0 0  0 0 1 1
OSC.XOSCCTRL = 0x43;

//enable external oscillator
OSC.CTRL = (1<<3);

//wait for stable
while( ! (OSC.STATUS & (1<<3)) );

CLKSYS_Prescalers_Config( CLK_PSADIV_1_gc, CLK_PSBCDIV_1_1_gc );

//select external osc
CLK.CTRL = 0x03;

sei();

//scale up by 4x  for 29.4912Mhz
CLKSYS_PLL_Config( OSC_PLLSRC_XOSC_gc, 4 );
CLKSYS_Enable( OSC_PLLEN_bm );

do {} while ( CLKSYS_IsReady( OSC_PLLRDY_bm ) == 0 );
CLKSYS_Main_ClockSource_Select( CLK_SCLKSEL_PLL_gc );
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is gonna make us non-Xmega-users' heads hurt--it looks quite similar to stuSan's example.
https://www.avrfreaks.net/index.p...
but seems to be quite different than ganzziani:
https://www.avrfreaks.net/index.p...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.