Hi,
I have a hardware design where we use an external 32.768KHz crystal oscillator. The output looks like this, measured on the XTAL pin:
The problem is that i cannot get the MCU to switch over to FEE mode! It keeps waiting for MCGSC_OSCINIT, which will never set. Here's the code for clock init:
void initClock() { // BDIV = 0, HGO = 1, EREFS = Oscillator selected MCGC2 = 0x14; // CLKS = FLL mode, IREFS = External ref. clock MCGC1 = 0x00; // Wait until external oscillator has initialized while(!MCGSC_OSCINIT) { }; // DMX32 = 1, DRS = 1 => 39.85MHz CPU clock MCGC4 = 0x21; // Wait for FLL to acquire new lock while(!MCGSC_LOCK) { }; }
If i don't call the initClock, then my program will run jsut fine on the internal clock. Adding this routine makes the program stop at MCGSC_OSCINIT, waiting for it to be set, but this never happens!
What am i doing wrong here?
Regards, Kaare Mai
Solved! Go to Solution.
I finally found the solution! It never crossed my mind that the COP watchdog would timeout when i was waiting for the oscillator to lock.
I also didn't know that i had to write to SOPT and SOPT2 even though i would like to use the default settings. This is documented in the reference manual for MCF51AC section 5-2:
"Even if the application uses the default reset settings of COPE, COPCLKS, and COPT, the user must write to the write-once SOPT and SOPT2 registers during reset initialization to lock in the settings."
After disabling the COP or making the code in the OSCINIT wait loop reset the COP, i finally got it to switch to FEE mode.
I think you need to set ERCLKEN bit.
Try creating new Project and let Device Initialize or Processor Expert initialize MCG for you.
I don't think thats the case. According to figure 16-1 MCG block diagram, ERCLKEN only makes the external clock available as MCGERCLK.
Alos, i can't get processor expert to set the correct settings for DMX32 and DCO. One of them is just not available as a setting, i don't know why.
The device init / processor expert is complete rubbish.
I can't set BDIV, DMX32 and DCO.
Also, it does not change IREFS to 0 even tho i enable the external clock and set it to crystal.
According to the block diagram IREFS has to be 0 to gate the external clock to the FLL circuit.
I finally found the solution! It never crossed my mind that the COP watchdog would timeout when i was waiting for the oscillator to lock.
I also didn't know that i had to write to SOPT and SOPT2 even though i would like to use the default settings. This is documented in the reference manual for MCF51AC section 5-2:
"Even if the application uses the default reset settings of COPE, COPCLKS, and COPT, the user must write to the write-once SOPT and SOPT2 registers during reset initialization to lock in the settings."
After disabling the COP or making the code in the OSCINIT wait loop reset the COP, i finally got it to switch to FEE mode.