NOTES ON PROGRAMMING ATMEGA328P CHIPS
10 APRIL 2025
This post is a step-by-step guide for wiring up ATmega328P ICs to run at 5 V
with a 16 MHz crystal and 3.3 V with an 8 MHz crystal. While the 5 V
configuration is common, the 3.3 V configuration can be advantageous in
low-power applications and when interfacing with parts that run at 3.3 V.
5 V - 16 MHz configuration
The steps that follow refer to the following pinout.
Pinout
Breadboard
- Connect pin 1 to 5 V via a 10 kΩ resistor.
- Connect a 16 MHz crystal oscillator across pins 9 and 10.
- Connect each pin of the crystal to ground via 22 pF capacitors.
- Connect pins 7, 20, and 21 to 5 V.
- Connect pins 8 and 22 to ground.
In addition to the connections described above, it’s a good idea to add 0.1 μF
decoupling capacitors between pins 7, 20, and 21 and ground.
Here’s a sample Makefile for avr-gcc and avrdude.
3.3 V - 8 MHz configuration
The following steps use Arduino Uno as an ISP and Arduino utilities to program
ATmega328P’s bootloader and the fuses (e.g., BOD level) for a 3.3 V supply.
- Upload the ‘ArduinoISP’ sketch to the Uno.
- Wire up the ATmega328P as described in the previous section. Replace the 5 V
supply with a 3.3 V supply and use an 8 MHz crystal instead of the 16 MHz
crystal.
- Connect the SPI ports (SCK, MISO, and MOSI) of the two MCUs.
- Connect Uno’s SS pin to the IC’s pin 1 (RESET).
- The IC can be powered by the Arduino Uno’s 5 V pin.
- Burn the bootloader to the ATmega328P:
- Select ‘ATmega328P (3.3 V, 8 MHz)’ from Tools > Processor.
- Select ‘Arduino as ISP’ from Tools > Programmer.
- Select Tools > Burn Bootloader.
The ATmega328P is now ready to run at 8 MHz with a 3.3 V power supply. You can
upload programs to the ATmega328P as you usually would using avrdude.
Here’s a sample Makefile with adjusted parameters (e.g., baud
rate) for an 8 MHz clock.
In both configurations, if you intend to use the ATmega328P’s analog-to-digital
converter with the internal 1.1 V or AVcc voltage as reference, do
not connect AREF (pin 21) to Vcc. Refer to section 23.5.2 ADC
Voltage Reference in the datasheet for more information.
This post is a step-by-step guide for wiring up ATmega328P ICs to run at 5 V with a 16 MHz crystal and 3.3 V with an 8 MHz crystal. While the 5 V configuration is common, the 3.3 V configuration can be advantageous in low-power applications and when interfacing with parts that run at 3.3 V.
5 V - 16 MHz configuration
The steps that follow refer to the following pinout.
Pinout |
Breadboard |
- Connect pin 1 to 5 V via a 10 kΩ resistor.
- Connect a 16 MHz crystal oscillator across pins 9 and 10.
- Connect each pin of the crystal to ground via 22 pF capacitors.
- Connect pins 7, 20, and 21 to 5 V.
- Connect pins 8 and 22 to ground.
In addition to the connections described above, it’s a good idea to add 0.1 μF decoupling capacitors between pins 7, 20, and 21 and ground. Here’s a sample Makefile for avr-gcc and avrdude.
3.3 V - 8 MHz configuration
The following steps use Arduino Uno as an ISP and Arduino utilities to program ATmega328P’s bootloader and the fuses (e.g., BOD level) for a 3.3 V supply.
- Upload the ‘ArduinoISP’ sketch to the Uno.
- Wire up the ATmega328P as described in the previous section. Replace the 5 V supply with a 3.3 V supply and use an 8 MHz crystal instead of the 16 MHz crystal.
- Connect the SPI ports (SCK, MISO, and MOSI) of the two MCUs.
- Connect Uno’s SS pin to the IC’s pin 1 (RESET).
- The IC can be powered by the Arduino Uno’s 5 V pin.
- Burn the bootloader to the ATmega328P:
- Select ‘ATmega328P (3.3 V, 8 MHz)’ from Tools > Processor.
- Select ‘Arduino as ISP’ from Tools > Programmer.
- Select Tools > Burn Bootloader.
The ATmega328P is now ready to run at 8 MHz with a 3.3 V power supply. You can upload programs to the ATmega328P as you usually would using avrdude. Here’s a sample Makefile with adjusted parameters (e.g., baud rate) for an 8 MHz clock.
In both configurations, if you intend to use the ATmega328P’s analog-to-digital converter with the internal 1.1 V or AVcc voltage as reference, do not connect AREF (pin 21) to Vcc. Refer to section 23.5.2 ADC Voltage Reference in the datasheet for more information.