The X2 pin doubles as GPIO18. At power-up, GPIO
mode is enabled and the on-chip crystal oscillator is powered off. The following
procedure can be used to switch the pin to 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 1023 (0x3FF).
- Wait for the X1 counter value in the X1CNT
register to reach 1023 (0x3FF).
- 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
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. 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 10 milliseconds, 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.