We have built a custom board that has a MK61FN1M0CAA12 chip. We want to use the OSC0 external crystal (32 MHz) as the reference for the system clocks and we are using the example outlined in section 25.5.3.1 of the K61 reference manual (rev 2), "Example 1: Moving from FEI to PEE Mode with OSCO..." as a guide. The code is below-
// Enable the external oscillator, and give it an 8pF load
OSC_CR = 0xA2;
// Select the external oscillator as the reference, and set it to
// Very high frequency range oscillator and high gain.
MCG_C2 = 0x2C;
// Wait for the crystal to finish initializing
while ((MCG_S & 0x02) == 0);
// Select crystal as source for MCGOUTCLK and FLL, divide it by 1024 to get it to 32 kHz
MCG_C1 = 0xA8;
// Wait for the FLL to use the external clock
while ((MCG_S & 0x10) != 0);
It hangs at this point. I have verified that the oscillator is running at 32 MHz, as expected. Am I doing something wrong in the code?
Solved! Go to Solution.
The problem turned out to be the high-gain setting for the external crystal. I changed the MCG_C2 setting to 0x24, and that fixed the problem.
We have a 1 MOhm load resistor which I thought made it so that you were supposed to use the high-gain setting, but I guess not.
The problem turned out to be the high-gain setting for the external crystal. I changed the MCG_C2 setting to 0x24, and that fixed the problem.
We have a 1 MOhm load resistor which I thought made it so that you were supposed to use the high-gain setting, but I guess not.