How to program an Atmega328P with the Bus Pirate via Arduino IDE

Many people have asked the question… How do I program an Atmega328P through the Arduino environment if it does not have a bootloader installed?  What if I want to upgrade the bootloader? There are many devices available to do this, either commercially available or home-brewed.  These devices fall in 3 main categories, JTAG, ICSP and High Voltage Parallel Programmer.  We will be focusing on the In Circuit Serial Programmer or ICSP using the Bus Pirate.

Using the latest version of AVRDUDE there is no need to make any modifications to the Bus Pirate for it to act like an ICSP.  The latest version of AVRDUDE has built in support for it.

Unfortunately the Arduino IDE (Arduino 0018) does not ship with the latest version of AVRDUDE, so it must be upgraded. Also the Arduino IDE does not know about the Bus Pirate so the configuration file must be edited to include support for the Bus Pirate.

We will start by upgrading AVRDUDE.  I will focus on the Windows environment for this.  The process for Linux is very similar, but will vary between distros and may even require building the latest version of AVRDUDE from source.

WinAVR is a suite available for Windows that includes the latest version of AVRDUDE.  You can download the latest version from their SourceForge repository located here http://sourceforge.net/projects/winavr/files/

Once you have downloaded and installed the latest version of WinAVR, its folder that you installed it to will include all the files required for upgrading Arduino to the latest version of AVRDUDE.

You can now browse to the folder you have installed or extracted the Arduino IDE to.  You did already download and install Arduino didn’t you? If not, go do that now… http://arduino.cc/en/Main/Software

Once in your local Arduino folder you want to look for… “hardware/tools/avr”

Delete all the files in the “avr” directory.

Now go to the directory you installed WinAVR to and copy all those files into the “ARDUINO/hardware/tools/avr” directory.

Within the “ARDUINO/hardware/tools/avr” folder, create another folder and call it “etc”.  You must copy the “avrdude.conf” file from the “ARDUINO/hardware/tools/avr/bin” to this “etc” folder.  This is where the Arduino IDE tells AVRDUDE to look for this configuration file.

You have now successfully upgraded Arduino to the latest AVRDUDE.

Now that you have the latest version of AVRDUDE, we can update the Arduino config files to let it know of the Bus Pirate’s existence.

Browse to your “ARDUINO/hardware/arduino” folder.  You will notice 2 files there… “boards.txt” and “programmers.txt”  We will modify both of them.

First the “boards.txt”

This file tells the Arduino IDE about all the different Arduino compatible boards and how they are programmed.  Open this file with a text editor.  I would advise against using “notepad.exe”, there are many free text editors available on the internet.

At the end of this file you need to add the following code.

#############

jkdBP32816.name=Bus Pirate Atmega328 16MHz

jkdBP32816.upload.using=buspirate
jkdBP32816.upload.maximum_size=30720

jkdBP32816.bootloader.low_fuses=0xFF
jkdBP32816.bootloader.high_fuses=0xDA
jkdBP32816.bootloader.extended_fuses=0x05
jkdBP32816.bootloader.path=atmega
jkdBP32816.bootloader.file=ATmegaBOOT_168_atmega328.hex
jkdBP32816.bootloader.unlock_bits=0x3F
jkdBP32816.bootloader.lock_bits=0x0F

jkdBP32816.build.mcu=atmega328p
jkdBP32816.build.f_cpu=16000000L
jkdBP32816.build.core=arduino
#############

############
jkdBP32808.name=Bus Pirate Atmega328 8MHz

jkdBP32816.upload.using=buspirate
jkdBP32808.upload.maximum_size=30720

jkdBP32808.bootloader.low_fuses=0xFF
jkdBP32808.bootloader.high_fuses=0xDA
jkdBP32808.bootloader.extended_fuses=0x05
jkdBP32808.bootloader.path=atmega
jkdBP32808.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex
jkdBP32808.bootloader.unlock_bits=0x3F
jkdBP32808.bootloader.lock_bits=0x0F

jkdBP32808.build.mcu=atmega328p
jkdBP32808.build.f_cpu=8000000L
jkdBP32808.build.core=arduino
#############

Now the the “programmers.txt” file.

At the end of this file add the following.

 

############
buspirate.name=Bus Pirate Real
buspirate.communication=serial
buspirate.protocol=buspirate

 

############

You will now have 2 new options in your boards selection in the Arduino IDE.  Select the correct one and you can send your program directly to an Atmega328 connected to the Bus Pirate.

Leave a Reply

Your email address will not be published. Required fields are marked *