To initialize a clock source as the main clock, these steps need to be followed:

  1. 1.Optional: Force the clock to always run by writing the Run Standby (RUNSTDBY) bit in the respective clock source CTRLA register to ‘1’.
  2. 2.Configure the clock source as needed in the corresponding clock source CTRLA register and, if applicable, enable the clock source by writing a ‘1’ to the Enable bit.
  3. 3.Optional: If RUNSTDBY is ‘1’, wait for the clock source to stabilize by polling the respective status bit in CLKCTRL.MCLKSTATUS.
  4. 4.The following sub-steps need to be performed in an order such that the main clock frequency never exceeds the allowed maximum clock frequency. Refer to the Electrical Characteristics section for further information.
    1. a.If required, divide the clock source frequency by writing to the Prescaler Division (PDIV) bit field and enable the main clock prescaler by writing a ‘1’ to the Prescaler Enable (PEN) bit in CLKCTRL.MCLKCTRLB.
    2. b.Select the configured clock source as the main clock in the Clock Select (CLKSEL) bit field in CLKCTRL.MCLKCTRLA.
  5. 5.Wait for the main clock to change by polling the Main Clock Oscillator Changing (SOSC) bit in the Main Clock Status (CLKCTRL.MCLKSTATUS) register.
  6. 6.Optional: Clear the RUNSTDBY bit in the clock source CTRLA register.