The X1 and X2 pins double as GPIO19 and GPIO18. At
power-up, these pins are in GPIO mode and the on-chip crystal oscillator is powered off. The
following procedure can be used to switch the pins to X1 and X2 mode and enable the
oscillator:
- Clear the XTALCR.OSCOFF bit.
- Wait for the crystal to power up. 1ms
is the typical wait time but this depends on the crystal that is being used.
- Clear the X1 counter by writing a 1 to
X1CNT.CLR and keep clearing until the X1 counter value in the X1CNT register is no
longer saturated 2047 (0x7FF).
- Wait for the X1 counter value in the
X1CNT register to reach 2047 (0x7FF).
- Repeat steps 3-4 three additional
times.
- Select XTAL as the OSCCLK source by
writing a 1 to CLKSRCCTL1.OSCCLKSRCSEL.
- Check the MCLKSTS bit in the MCDCR
register. If the bit is set, the oscillator has not finished powering up, and more time
is required:
- Clear the missing clock status by
writing a 1 to MCDCR.MCLKCLR.
- Repeat steps 2-7. Do not reset the
device, as doing so powers down the oscillator, which requires the procedure to be
restarted from step 1.
- If the oscillator has not finished
powering up in 10ms, there is a real clock failure.
- If MCDCR.MCLKSTS is clear, the
oscillator startup is a success. The system clock is now derived from XTAL.