Pi AVR Programmer HAT Hookup Guide

Pages
Contributors: QCPete
Favorited Favorite 4

ISP Programming: Command Line

In this section, we are going to program the Target AVR IC (Redboard) using calls to avrdude in the command line. This will require a monitor, keyboard and mouse hooked up to your Pi

Download the bootloader hex file for the RedBoard here:

Save it in the correct directory (i.e. /home/pi/):

Directory

Sanity Check -- Device Signature Verification

Before we get into any actual programming, it's a good idea to ensure our connections are all correct and avrdude is working properly. To do this, we are going to simply call avrdude and ping for the device ID.

The Pi AVR Programmer HAT has an isolation switch between the raspi GPIO pins and the target. This serves as both protection of your rapsi and as a means to "free up" your target once you're done programming. You can use some handy Python modules to quickly set this switch: enable_switch.py and disable_switch.py. For easy access, it's a good idea to save them in the /home/pi directory.

Make sure to enable the programming switch by running a quick python module named enable_switch.py.

language:bash
sudo python enable_switch.py

Then run your avrdude command. Here is our first call to avrdude to check the device ID.

language:bash
sudo avrdude -p atmega328p -C /home/pi/avrdude_gpio.conf -c linuxspi -P /dev/spidev0.0 -b 125000 -v

Your readout should look like this:

Device Signature Verification in Terminal Window

Click the image for a closer look.

This basic command defines the programmer type you're using and the AVR it's talking to. AVRDUDE will attempt to read the Device Signature from your AVR, which is different for each AVR type out there. Every ATmega328P should have a device signature of 0x1E950F.

Flash Programming

Now that you've verified that everything is in working order, you can do all sorts of memory reading and writing with AVRDUDE. The main piece of memory you probably want to write is flash -- the non-volatile memory where the programs are stored.

This command will perform a basic write to flash (using this HEX file as an example):

language:bash
sudo avrdude -p atmega328p -C /home/pi/avrdude_gpio.conf -c linuxspi -P /dev/spidev0.0 -b 2000000 -D -v -u -U flash:w:blink.hex:i

Writing to flash can sometimes take a little longer than a device ID ping. With the built-in ISP hardware pins and the Pi AVR Programmer HAT, you can use up to 2MHz reliably. For blink.hex, it only takes 0.09 seconds! You'll see a text status bar scroll by as the device is read, written to, and verified.

Terminal Output After Flashing Arduino Bootloader

Click the image for a closer look.

The -U option command handles all of the memory reads and writes. We tell it we want to work with flash memory, do a write with w, and then tell it the location of the hex file we want to write.

Useful Options

Here are just a few last AVRDUDE tips and tricks before we turn you loose on the AVR world.

Specify AVR Device

Two options required for using AVRDUDE are the programmer type and AVR device specification. The programmer definition, assuming you're using the Pi AVR Programmer HAT, will be -c linuxspi. Note that you will also need to specify the port (because there are two SPI ports on the raspi. This is done with the -P /dev/spidev0.0 portion of the call. If you need to use a different programmer check out this page and CTRL + F to "-c programmer-id".

The AVR device type is defined with the -p option. We've shown a few examples with the ATmega328P, but what if you're using an ATtiny85? In that case, you'll want to put -p t85 instead. Check out the top of this page for an exhaustive list of compatible AVR device types.

Verbose Output

Adding one or more -v's to your AVRDUDE command will enable various levels of verbosity to the action. This is handy if you need a summary of your configuration options, or an in-depth view into what data is being sent to your AVR.


There's plenty more where that came from. Check out the AVRDUDE Option Documentation for the entire list of commands.