32.5.6 Switching Main Clock Between the RC Oscillator and the Crystal Oscillator
When switching the source of the Main clock between the RC oscillator and the crystal oscillator, both oscillators must be enabled. After completion of the switch, the unused oscillator can be disabled.
If switching to the crystal oscillator, a check must be carried out to ensure that the oscillator is present and that its frequency is valid. Follow the sequence below:
- Enable the crystal oscillator by setting CKGR_MOR.MOSCXTEN. Configure the CKGR_MOR. MOSCXTST field with the crystal oscillator start-up time as defined in the section “Electrical Characteristics”.
- Wait for PMC_SR.MOSCXTS flag to rise, indicating the end of a start-up period of the crystal oscillator.
- Select the crystal oscillator as the source clock of the frequency meter by setting CKGR_MCFR.CCSS
- Initiate a frequency measurement by setting CKGR_MCFR.RCMEAS.
- Read CKGR_MCFR.MAINFRDY until its value equals 1.
-
Read CKGR_MCFR.MAINF and compute the value of the crystal frequency.
- If the MAINF value is valid, the Main clock can be switched to the crystal oscillator.