I've wrote a small program that runs on an XMEGA :
#include <avr/io.h>
#include <stdio.h>
#ifndef F_CPU
#define F_CPU 32000000UL
#endif
void system_clock_init(void){
CCP = CCP_IOREG_gc; /* allow changing CLK.CTRL */
OSC.CTRL = OSC_RC32MEN_bm; /* Enabling the 32MHz RC oscillator */
while (!(OSC.STATUS & OSC_RC32MRDY_bm)); /* wait for ready */
CCP = CCP_IOREG_gc;/* allow changing CLK.CTRL */
CLK.CTRL = CLK_SCLKSEL_RC32M_gc ;/* system clock is internal 32MHz RC */
}
int main (void)
{
// Insert system clock initialization code here (sysclk_init()).
system_clock_init();
PORTR.DIR = 0x02;
while(1) {
PORTR.OUTTGL = PIN1_bm;
}
}
the program should toggle an LED, but when I use the scope I measure a signal of 2ms , which mean that uC clock is : 1 MHz ?? which wonders me because I think that the program is correct ?
and idea what am I missing here ?