You are here

Arduino on breadboard (ATMEGA328P 8MHz and 1MHz)

A one stop shop for using the ATMEGA328P standalone at 8MHz or 1MHz clock speed including compiled bootloader.  This is for use primarily on a breadboard, but also also directly on, say, a Uno R3.

Summary

I was unable to find any complete resources for configuring the AVR ATMEGA328P as an 8MHz Arduino.  Also I could find no resources at all to allow me to use the AVR ATMEGA328P microprocessor at 1MHz.  This frustration is shared by many.  Put the following files in your sketchbook to provide both 8MHz and 1MHz boards in the Arduino IDE which can be used for burning bootloaders or uploading sketches.  My sketchbook directory is /home/ewan/Arduino.  So put the hardware directory at /home/ewan/Arduino/hardware, etc.  Links to download all the required files are below.

breadboard/
breadboard/avr/
breadboard/avr/boards.txt
breadboard/avr/bootloaders/
breadboard/avr/bootloaders/atmega/
breadboard/avr/bootloaders/atmega/optiboot_atmega328_1MHz_4800.hex
breadboard/avr/bootloaders/atmega/optiboot_atmega328_pro_8MHz.hex

The fiddly stuff

I needed to build the 1MHz boot loader. To do this I modified the Makefile in the Arduino hardware bootloader directory /var/local/arduino-1.6.9/hardware/arduino/avr/bootloaders/optiboot:

atmega328_1: TARGET = atmega328
atmega328_1: MCU_TARGET = atmega328p
atmega328_1: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=4800'
atmega328_1: AVR_FREQ = 1000000L
atmega328_1: LDSECTIONS  = -Wl,--section-start=.text=0x7c00 -Wl,--section-start=.version=0x7ffe
atmega328_1: $(PROGRAM)_atmega328_1MHz_4800.hex
atmega328_1: $(PROGRAM)_atmega328_1MHz_4800.lst

The Arduino AVR binary directory was added to the path, then the bootloader built and copied to the Arduino sketchbook hardware directory.

PATH=/var/local/arduino-1.6.9/hardware/tools/avr/bin:$PATH
make atmega328_1
cp -p optiboot_atmega328_1MHz_4800.hex /home/ewan/Arduino/hardware/breadboard/avr/bootloaders/atmega

Note that my environment built a bootloader file that was slightly over 512 bytes in size. Hence I lowered the start address by 512 bytes and adjusted the fuses to allow for a 1kB bootloader.  Note that if you use the fuse calculator then all the bits are reversed (0 and 1)!  Always ensure that the high fuses are set to at least 0x80 to keep the reset pin enabled.

Setting up the atmega328p on the breadboard

The pin mapping is useful. Connect RESET Pin 1 via a 10 kOhm pull-up resistor to 5V. Provide power by connecting 5V to pin 7 and GND to pin 8. If you wish, connect PB5 pin 19 to the anode of a LED, via 150 Ohm resistor to GND. That really is all you need.

Burn bootloader (chip on Uno R3 board)

I used another Arduino Uno R3 prepared with the standard example ArduinoISP sketch loaded. Now, connect the ISP Arduino to the target Arduino (with the new chip) as normal, i.e. (ISP->Target Uno): 13->13, 12->12, 11->11, 10->RESET. Burn the bootloader using Arduino as ISP.

Burn bootloader (chip on breadboard)

Connect as follows (ISP->target chip pin): 13->19 (SCK), 12->18 (MISO), 11->17 (MOSI), 10->1 (RESET). Burn the bootloader using Arduino as ISP.

Upload sketch (chip on Uno R3 board)

Upload the sketch using the usual process in the IDE. This can take a considerable amount of time at 4800 baud when running at 1MHz.

Upload sketch (chip on breadboard)

If you need to visualise the serial activity then, for both pins 2 and 3 of the processor, wire to a LED cathode, via a current limiting resistor (say, 1k), to +5V. This way the LEDs will illuminate when Tx/Rx pins are grounded.

I use a CH340 USB to serial converter which does not have the ability to reset the micro processor. Connect CH340 5V to pin 7 (5V), GND to pin 8 (GND), Tx to pin 2 (Rx) and finally Rx to pin 3 (Tx). Now, short pin 1 (RESET) to GND. Click Upload in the Arduino IDE. When the progress bar fills all the way to the right, release the RESET from GND. That should synchronise the sketch upload with the reset of the boot loader.

Upload sketch using Arduino-Makefile (chip on breadboard)

To use Arduino-Makefile instead of the IDE, wire the serial port as above. For the correct timing, release RESET when you see the output show make reset. You will also need to change a couple of lines in the Makefile as appropriate, for example:

BOARDS_TXT=/home/ewan/Arduino/hardware/breadboard/avr/boards.txt
VARIANT=standard
BOARD_TAG=atmega328bb.menu.clock.1MHz
AVRDUDE_OPTS=""

Setting AVRDUDE_OPTS to blank reinstates the progress bar and the verification of the flash programming operation. These are useful options because the upload is slow and can be unreliable.

Classifications: 

Comments

Hi,

I have the .hex bootloader but I cannto find a way to add it to the bootloaders list on the Arduino IDE for Mac.
I thought I only needed to go to /Applications/Arduino.app/Contents/Java/hardware/arduino/avr and modify the boards.txt to all the new bootloader name bit it just wont appear. Any ideas? thanks!

Hi Martin, instead of updating the core files I would suggest you place the files in you local sketch book directory which I believe is ~/Documents/Arduino on the Mac. For example:

~/Documents/Arduino/hardware/breadboard/avr/boards.txt

and so on.

I did not build the 8 MHz bootloader, but downloaded it from the above link. I am not sure about the reliability at the higher BAUD rate so I will have to check the optiboot code and documentation when I have time.