Hi-
I have problem to re-enable the external crystal after resuming back from VLPR mode on my k20d50m custom board. The k20 is clocked by 8MHz crystal with two ends connected to ground via a capacitor valued 10pF (both boards with and w/o them populated are tested, same results).
The crystal has no problem to start after powering on but stops to oscillate on the way back to normal mode (via APIs of MQX4.1).
My IAR debugger hangs at
/* MCG_C1: CLKS=2,FRDIV=3,IREFS=0,IRCLKEN=0,IREFSTEN=0 */
MCG_C1 = (uint8_t)0x98U;
When the mode is changed from FBI to FBE and external clock is expected.
I traced the clock output of 8MHz crystal and found no oscillating there after
/* OSC0_CR: ERCLKEN=1,??=0,EREFSTEN=0,??=0,SC2P=0,SC4P=0,SC8P=0,SC16P=0 */
OSC0_CR = (uint8_t)0x80U;
in FBI mode. The only I can see is the voltage on XTAL0 jumps back to 3V from 0V.
The external clock is stopped on the way to VLPR which seems to be OK to me.
What is the reason to cause the crystal NOT to start again? it is the HW or SW problem?
Hi, Hui,
I suppose that you use internal reference clock when you put the K20 in VLPR mode. You would like to use external crystal of 8MHz after you put the K20 in Normal Run mode. I think this is the procedure of switching from FBI to FBE.
1)set the ERCLKEN=1 by code OSC0_CR = (uint8_t)0x80U;
2)polling the OSCINIT0 bit in MCG_S with code: while(!(MCG_S&OSCINIT0)) {}
3)set the MCG_C1 = (uint8_t)0x98U;
4)polling the CLKST bits of MCG_S, after the CLKST is zero, it is okay.
I suppose the OSCSEL bit is cleared as default setting in MCG_C7.
Hope it can help you.
BR
XiangJun Rong