Designing a PCB with the ATmega32U4
The ATmega32U4 is Microchip's 8-bit AVR microcontroller with a built-in USB 2.0 full-speed device controller, 32 KB of flash and 2.5 KB of SRAM, running from 2.7 V to 5.5 V. Because it talks USB itself, a board needs no USB-to-serial bridge: just 22 Ω resistors on D+ and D−, 1 µF on UCAP, 10 µF on VBUS and an 8 or 16 MHz crystal for the USB clock.
- Core
- 8-bit AVR, up to 16 MIPS at 16 MHz
- Memory
- 32 KB flash, 2.5 KB SRAM, 1 KB EEPROM
- Supply
- 2.7 V to 5.5 V (8 MHz at 2.7 V, 16 MHz at 4.5 V)
- USB
- USB 2.0 full-speed (12 Mbit/s) and low-speed device, internal regulator for the USB pads
- USB clock
- PLL fed from an 8 or 16 MHz crystal; crystal-less only in low-speed mode
- ADC
- 12 channels, 10-bit
- Packages
- 44-lead TQFP (10 × 10 mm), 44-lead QFN (7 × 7 mm)
How do I power the ATmega32U4 for USB?
The USB pads run from an internal regulator fed by UVCC, with its output on UCAP, which needs a 1 µF ±10 % capacitor to ground. The datasheet gives two supply windows for USB: 3.4 V to 5.5 V with the internal regulator on, or 3.0 V to 3.6 V with the regulator bypassed. On a bus-powered 5 V board, VBUS feeds VCC, UVCC and AVCC directly, and Microchip strongly recommends a 10 µF capacitor on the VBUS line. Give every VCC/GND pair its own 100 nF decoupling capacitor, as Microchip's AN2519 asks. AVCC must connect to VCC even if the ADC is unused, and through a low-pass filter if it is used.
The clock limit follows the supply: 8 MHz is guaranteed at 2.7 V and 16 MHz at 4.5 V, with the limit rising linearly in between, so a 3.3 V board should use an 8 MHz crystal.
Which crystal does the ATmega32U4 need for USB?
Full-speed USB needs an external crystal or clock; the internal RC oscillator is only good enough for low-speed USB, and only between 0 and 40 °C. The USB PLL takes an 8 MHz input, divided from an 8 MHz or 16 MHz crystal by the PINDIV bit, so those are the two useful crystal values. For quartz crystals, the datasheet recommends equal load capacitors of 12 to 22 pF. AN2519 asks for the crystal as close to XTAL1/XTAL2 as possible, surrounded by ground.
How should D+ and D− be routed?
Each data line gets a 22 Ω ±5 % series resistor between the connector and the D+ and D− pads. Keep the run from the receptacle short and route it as a differential pair: equal lengths, close together and with as few vias as possible. Microchip suggests transient or ESD protection at the connector so the USB pads survive cable discharges. Connect VBUS to the VBUS pin so the chip can detect the host.
How do reset, HWB and the bootloader work?
Parts ordered for an external crystal come with a USB bootloader already programmed. With the HWBE fuse enabled, the chip samples PE2 (HWB) on the rising edge of reset: if the pin is low, it jumps to the bootloader; otherwise it runs your code. Give PE2 a defined high level and a way to pull it low, such as a button or jumper. RESET has a 30 to 60 kΩ internal pull-up, and AN2519's recommended circuit adds 4.7 kΩ and 100 nF. Fuses and flash can also be written over ISP on PB1 (SCLK), PB2 (MOSI) and PB3 (MISO) with RESET, or over JTAG.
Common ATmega32U4 mistakes
- Expecting PF4 to PF7 (ADC4 to ADC7) to work as normal pins: the chip ships with the JTAGEN fuse programmed, so they are JTAG pins until the fuse is cleared or firmware sets the JTD bit.
- UCAP left open or fitted with the wrong value: the USB pad regulator needs 1 µF ±10 %.
- Leaving out the 22 Ω series resistors on D+ and D−.
- A 16 MHz crystal on a 3.3 V supply, above the speed limit for that voltage.
- Leaving HWB floating with HWBE enabled, so the level sampled at reset is undefined and the board can start in the bootloader.
Checking an ATmega32U4 board
A missing UCAP capacitor or an open AVCC pin shows up in the netlist before layout. Cuprio checks the schematic with electrical rule checks.
Sources
- Microchip (Atmel): ATmega16U4/ATmega32U4 Datasheet 7766Jww1.microchip.com
Memory, supply range and speed limits, USB controller, UCAP and VBUS capacitors, 22 Ω resistors, routing rules, crystal-less range, PINDIV, crystal capacitors, AVCC, HWB/HWBE, default bootloader, JTAGEN, reset pull-up, packages
- Microchip: AN2519 AVR Microcontroller Hardware Design Considerations (DS00002519B)ww1.microchip.com
Decoupling per supply pair, reset circuit values, crystal placement
