Datasheet
36
7766E–AVR–04/10
ATmega16U4/ATmega32U4
6.8.2 Switch from RC clock to external clock
if (Usb_wake_up_detected()) // if (UDINT.WAKEUPI == 1)
{
Usb_ack_wake_up(); // UDINT.WAKEUPI = 0;
Enable_external_clock(); // CKSEL0.EXTE = 1;
while (!External_clock_ready()); // while (CLKSTA.EXTON != 1);
Select_external_clock(); // CLKSEL0.CLKS = 1;
Enable_pll(); // PLLCSR.PLLE = 1;
Disable_RC_clock(); // CLKSEL0.RCE = 0;
while (!Pll_ready()); // while (PLLCSR.PLOCK != 1);
Usb_unfreeze_clock(); // USBCON.FRZCLK = 0;
}
6.8.3 CLKSEL0 – Clock Selection Register 0
• Bit 7-6 – RCSUT[1:0]: SUT for RC oscillator
These 2 bits are the SUT value for the RC Oscillator. If the RC oscillator is selected by fuse bits,
the SUT fuse are copied into these bits. A firmware change will not have any effect because this
additional start-up time is only used after a reset and not after a clock switch.
• Bit 5-4 – EXSUT[1:0]: SUT for External Clock/ Low Power Crystal Oscillator
These 2 bits are the SUT value for the External Clock / Low Power Crystal Oscillator. If the
External Clock / Low Power Crystal Oscillator is selected by fuse bits, the SUT fuses are copied
into these bits. The firmware can modify these bits by writing a new value. This value will be
used at the next start of the External Clock / Low Power Crystal Oscillator.
• Bit 3 – RCE: Enable RC Oscillator
The RCE bit must be written to logic one to enable the RC Oscillator. The RCE bit must be writ-
ten to logic zero to disable the RC Oscillator.
• Bit 2 – EXTE: Enable External Clock / Low Power Crystal Oscillator
The OSCE bit must be written to logic one to enable External Clock / Low Power Crystal Oscilla-
tor. The OSCE bit must be written to logic zero to disable the External Clock / Low Power Crystal
Oscillator.
• Bit 0 – CLKS: Clock Selector
The CLKS bit must be written to logic one to select the External Clock / Low Power Crystal Oscil-
lator as CPU clock. The CLKS bit must be written to logic zero to select the RC Oscillator as
CPU clock. After a reset, the CLKS bit is set by hardware if the External Clock / Low Power Crys-
tal Oscillator is selected by the fuse bits configuration.
The firmware has to check if the clock is correctly started before selected it.
6.8.4 CLKSEL1 – Clock Selection Register 1
Bit 7 6 5 4 3210
RCSUT1 RCSUT0 EXSUT1 EXSUT0 RCE EXTE - CLKS CLKSEL0
Read/Write R/W R/W R/W R/W R/W R/W R R/W
Initial Value 0 0 0 0 See Bit Description
Bit 7 6543210
RCCKS
EL3
RCCKS
EL2
RCCKS
EL1
RCCKS
EL0
EXCKS
EL3
EXCKS
EL2
EXCKS
EL1
EXCKS
EL0
CLKSEL1
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 1 0 0 0 0 0