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, then a 0 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 it's 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.