Programming an Arduino with the AVR Dragon

avrdragon_connections

Programming the Arduino with the AVR Dragon (an Atmel programming/development board) was something I had to accomplish this week.  In the image  above the right-hand board is our Firstbot prototype.  The Firstbot is an Arduino compatible board.  Simply put that means it runs the Arduino bootloader and can be programmed using the Arduino software interface.  Hardware connections match the Arduino Uno, and the Atmel chip we used is the ATmega328-AU that matches the Arduino Pro (5V 16MHz version).  We’ve added a couple of motor controllers to the board (Freescale MC33926) so that it can easily be used to create a robot running Arduino code.  The board on the left is Atmel’s AVR Dragon, a fairly cheap debugger and programmer (PN: ATAVRDRAGON, about $50US).

Using the AVR Dragon to load the Arduino bootloader into our design was pretty straightforward.  But I thought a tutorial might be useful to anyone else trying to accomplish the same thing with a custom board, or just trying to get an Arduino reprogrammed with the correct bootloader file.

Preparation: There are a few things to take note of while preparing to program and Arduino with the AVR Dragon.  I downloaded/installed Atmel Studio 6.0 to use as the IDE(integrated development environment) for the AVR Dragon.   Future iterations of this IDE, or earlier version, will look a little different, so the software pictures below might change.  Your board will also need to be connected to the AVR Dragon via the 6 pin in-circuit serial programming header (ICSP).  The pinout should connect to your Atmel IC pins with matching names.  Pin numbers will differ depending on the IC package and chip part number.  The AVR Dragon and Arduino Uno 6 pin headers will match these connections.  I used a 2×5 (10 pin) ribbon cable to make this connection (grey cable above) because it was handy.  Only 6 connections (2×3) are required.

1 – MISO (master in slave out)
2 – VCC (system voltage)
3 – SCK (serial clock)
4 – MOSI (master out slave in)
5 – RST (reset)
6 – GROUND (ground return)

Your Arduino or compatible board should be powered separately from the AVR Dragon.

For clarification, the AVR Dragon is used to program a bootloader into the Arduino compatible board.  A different connection is used to program the Arduino compatible board with the code it will run as its application.  For the Arduino Uno this is done with a USB connection.  On our board we used an RS232 interface.  You can see the jumper wires connected to the back side of our Firstbot board.  These connect to the RS232 cable that we used to program the board

Step 1:

Power both boards (AVR Dragon powers through the USB connection, and your Arduino or Arduino compatible board will need to be powered separately.  After launching Atmel Studio select Tool/Device Programming from the menu (screen not shown).   A new programming window will open (shown below).  In this window select AVR Dragon as the tool, select the IC on your board (ATmega328 for our design), and select ISP as the interface.  We used the ATmega328, but many Arduinos use the ATmega328P.  When these items are selected press the “Apply” button.  I also found that the ISP clock on my board needed to be set below the 1MHz default setting.  250KHz worked for me.  If you have issues with communication you can try adjusting the ISP clock setting.

avrdragon_after_press_apply

Step 2:
Press the read button next to the “Device signature” text box.   If the AVR Dragon and your Arduino are correctly connected you should get a hex value back associated with the IC you’re using.  You’ll also see  a voltage reading for the board about to be programmed.  In our case it is 5V.

avrdragon_after_device_read

Step 3:

Prior to programming of the bootloader you’ll need to program the fuses for the Atmel IC to operate correctly.  Select  the “Fuses” section on the left hand side of the software window.  Type in the appropriate fuse value for the Arduino you are programming, or the hardware you are duplicating if it is a custom design.  Once entered, hit “Program”.  For the Arduino Pro 5V 16MHz the settings are…

EXTENDED – 0x05 HIGH – 0xDA LOW – 0xFF

Your settings may be different.  I ran across a lot of warnings on the internet not to program in the wrong values.  Since this is a flash part I assume you can always erase the device and start from scratch if you make a mistake.   I ran across a web page, Coding with Cody, that had a ton of the fuse settings for various Arduino models.  I can’t vouch for all the settings, but the one I used for the Arduino Pro 5V 16MHz did work.
avrdragon_after_fuses

Step 4:

In the “Memories” section selected on the left side of the software window use the browse button (the “…” button right of the Flash text box) navigate to the Arduino bootloader file location.  Select the appropriate bootloader file for your application and hit “Program”.

avrdragon_after_programming

I found the bootloader I needed in the Arduino folder under hardware/arduino/bootloaders/Atmega.

avrdragon_bootloader_location

Step 5:

If everything worked your board should start blinking the LED connected to pin 13 (assuming your board has an LED there).  That’s a good indicator that the bootloader was loaded into the IC correctly.  You’re almost done.  Now you can attempt to load an application into your board using the Arduino software interface.  A quick test is to modify the example LED blinking code found under File/Examples/Basic/Blink.  Just cut the delay numbers in half, and if programming is successful the LED connected to pin 13 will blink twice as fast.

To load the software connect your USB (or other interface) to the Arduino compatible board.  Select the appropriate communications port under Tools/Serial Port.  Then make sure you pick the right Arduino board model to program.  Since we used the ATmega328-AU, and programmed our board with the fuses associated with the Arduino Pro 5V 16Mhz, we needed to select the board type associated with that hardware (shown below).

After these steps it was a simple process to test our connection and make sure we could load our Arduino programs into our own hardware.  Pretty cool.
avrdragon_select_board_type

Comments

  1. Hi,

    Thank you very much for your very interesting post 🙂

    I’m new on the development Arduino, I have just installed my development environment with Eclipse + AVR plugin. On my Arduino board there is an ATMega328P. Everything works perfectly (compilation, program upload to the board).

    Now, I would like to debug my code (breakpoints using, check variables, registers, stack, memory, etc.); so is it possible to use the AVR Dragon like in your post ? And with Eclipse+AVR Plugin it will be fine ?

    Thank you very much for your answers!

    Anthony

    • Good morning Anthony,

      I used the compiled Arduino bootloader file (hex file) with the AVR dragon. So basically I only used the AVR as a programmer. You’d have to have an un-compiled version of the Arduino bootloader with whatever associated libraries and sub-files are used in order to debug it in a development environment. I’m not sure the folks at Arduino provide those files.

      An alternative is to use the Arduino’s serial monitor as your debugger. This is a little more clunky, but can still get the job done.

      Lon

  2. Hi!
    Maybe it’s too late, because last comment was in 2013, but I will try..

    I have made all steps with Arduino Mega 2560 and AVR Dragon, and the LED started blinking. But, when I try to upload another code (or the same Blink code with less delay between digitalWrites), Arduino IDE says there was a problem uploading the code…

    I blocked the Mega trying to work with the watchdog, and I can’t restore it to the default state.. 🙁

Speak Your Mind

*