Hello everybody ! :smileygrin:
I'm starting to use the Freedom Board KL-26Z and I would like to manually initiate the clock (without the help of PE). To do that, I follow the step by step example 1 from the KL26Z reference manual (p.416 : "24.5.3.1 Example 1: Moving from FEI to PEE mode: External Crystal = 4 MHz, MCGOUTCLK frequency = 48 MHz"). For my application, the external crystal run at 8MHz.
But I'm stuck at step 1.d : "loop until IREFST = 0". When I start debugging IREFST bit from MCG status register is alway set and never clear.
Am I missing something ?
the actual code :
int main(void)
{
//init MCU OSC
MCG_C2 = 0x2C;
MCG_C1 = 0x98;
while(!MCG_S_OSCINIT0_MASK);
while(MCG_S_IREFST_MASK); // <-- I'm Stuck here !!:smileyconfused:
while(!(MCG_S_CLKST_MASK == 0x2));
MCG_C5 = 0x02;
MCG_C2 |= 0x02; // LP=1,FBE -> BLPE mode
MCG_C6 = 0x40;
MCG_C2 &= 0xFD; // LP=0,BLPE -> PBE mode
while(!MCG_S_PLLST_MASK);
while(!MCG_S_LOCK0_MASK);
MCG_C1 = 0x18;
while(!(MCG_S_CLKST_MASK == 0x3));
printf("end of init");
return 0;
}
Why not taking the helping hand of PE? Because it will show/generate you the code sequence needed.
Then you can copy-paste that code into your application. Using PE does not mean that have to do everything with it. But it saves you a lot of time solving the kind of problems you are facing here?
Erich
Maxime
Try MCG_C2 = 0x24;
0x2c is setting the high gain mode for the crystal oscillator and the FRDM-KL26Z doesn't (usually) have any loading capacitors so the oscillator won't start. If you set low gain mode it will.
As reference, these are the register writes that I use on the FRDM-KL26Z (maybe slightly different route) to get to 48MHz.
C2 = 0x94;
C1 = 0x98;
C5 = 0x03;
C6 = 0x58;
C1 = 0x28;
There are of course various waits on status flags in the sequence.
Regards
Mark