How to Program Arduino with AVR ISP Programmer

If you have been using Arduino to develop your code but want to move on to develop your own AVR based circuit or want to program your Arduino board with an external programmer to give more code space, you will need to understand how to use an AVR ISP or In System Programmer. This post covers the information you need

Step 1 – Find your Hex file
The ISP needs a hex file (.hex), also called output binary in Arduino speak. This is hidden by the Arduino IDE in temporary folders in your user folders, typically something like this:

C:\Documents and Settings\your_username\Local Settings\Temp\build3526495849735274299.tmp.

You need to find the latest folder and hex file for the programmer. You can change Arduino settings to make this more sensible as shown in How to find Arduino Hex files.

Step 2 – Connect your AVR ISP
Arduino boards and circuits use a standard Atmel 6-way ISP header to connect the programmer but it doesn’t have any labels or key way for orientation. All AVR ISP leads have a keyway, which is shown on this picture next to Arduino ISP header.

Connecting 6-way ISP to Arduino Board

Connecting 6-way ISP to Arduino Board

Make sure the key way on your programmer matches the orientation in the picture.

Step 3 – AVR Fuse Settings
There are lots of fuses that set how the AVR microcontroller will run. The important ones for Arduino are these

  • CLKSEL – Clock select fuses should be set to 1111
  • CLKDIV8 – Should be unset to disable clock divide by 8
  • BOOTRST – Bootrst should be unprogrammed, to use Reset Vector

New AVR devices have a default clock of 8MHz Internal RC and Clock divide by 8 fuse set giving a clock speed of 1MHz regardless of the clock on the board. To make the Arduino board run from its external 16MHz crystal, CLKDIV8 should be off and CLKSEL fuses should be set to 1111 : Low Power Crystal Oscillator 8.0 – 16.0 MHz.

The standard Arduino uses a bootloader for programming but as we are not going to use that, we can remove it by clearing BOOTRST fuse. This means that the device will start from the beginning of code space instead of saving the bootloader.

The default fuse values are now

  • Low Fuse 0xFF (B11111111)
  • High fuse = 0xDA (B11011110)
  • Extended fuse = 0x05 (B00000101)

All ISP display fuses a bit differently, here they are in Kanda AVR ISP

Arduino Fuses Required

Arduino Fuses Required

CLKSEL is set to 1111, all options are Off (unchecked), Brownout is set to 2.7V as an ATmega32P will run at 16MHz at this voltage but we want it to reset if it drops lower. SUT fuses are set to slowest startup time.

Lockbits and Boot Block for Arduino

Lockbits and Boot Block for Arduino

Lock bits protect the code from being written or read. Leave as default unless you want to stop your code from being read. The Reset Vector should be set to Application so that code will run from the start of memory. This would be set to run from Boot Block if a bootloader is required. Boot Size can just be left at default – 2KB or 4 pages of 256 words each.

Step 4 – Programming your AVR

Now we connect the AVR ISP to the target Arduino. If it can’t find a voltage, switch on Power Target in Setup dialog or power your Arduino board. We have already set the fuses to the correct values, so we just need to load the Hex file (File -> Load -> Flash) and an EEPROM (.eep) file if your sketch uses EEPROM data (File -> Load -> EEPROM) from our Arduino output folder described in Step 1.

The easiest way to carry out all the steps need to program the AVR is to use Auto Program function. Most ISP have this feature, here is the Kanda setup, found in Device -> Auto Program Options.

Auto Program Options

Auto Program Options

  • Reload Files – if changed, loads last version
  • Erase – AVR MUST be erased before reprogramming
  • Program Flash Memory – programs code memory
  • Verify Flash – checks code has programmed OK
  • Program Fuses – programs and verifies fuse settings
  • Run – free AVR from reset so it will run code

Having set up the options, just press F5 to program the AVR.  Job Done.

Related Links

How to Find Arduino Hex Files

AVR Clock Fuses

Low Cost USB AVR ISP

Leave a Reply

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