Using an Arduino as an AVR-ISP

The Arduino platform requires a bootloader to be burnt into the chip before it can be used. This allows for the chip to be programmed using only TTL serial connections, as found in the FTDI chip on the board itself.

Atmega8 Pinout

(click for larger)

To burn the Arduino bootloader to allow a new Atmega chip to be used on the board itself or in a new circuit an in system programmer is the easiet method accomplish this goal. These programmers can be built utilizing a PC’s printer (LPT) port, via bit-banging over serial akin to the MiniPov3, purchased outright, or with some crafty Arduino sketches can be done with a normal Arduino!

Most of the hard work is already done as AVR-ISP has been ported over to the Arduino platform by help of MEGA-ISP. To convert your Arduino into an AVR-ISP programmer its as easy as visiting the MEGA-ISP google-code project page, opening the .pde file and uploading it to your Arduino. Provided you are able to get this far, your Arduino will now respond to AVR-Dude!

Under normal circumstances ISP (or In Circuit Serial Programming) requires the programmer to be powered by the target circuit, however for this application power for the target will be generated by the 5V+ out of the Arduino. All that is required is the target chip, a breadboard, an Arduino and some breadboard wires.

As pictured above, the following pins need to be connected:

Arduino Atmega
Pin 10 Pin 1 - Reset
Pin 11 Pin 17 - MOSI
Pin 12 Pin 18 - MISO
Pin 13 Pin 19 - SCK
VCC (+5V) Pin 7 & 20
Ground Pin 8 & 22

Once these pins are connected, that’s it!

If you have not downloaded and installed AVR-DUDE, do so now and add its executables to your windows path.

To test your configuration is working correctly, issue the following command in the command prompt (Start->Run->CMD)

C:\>avrdude -p atmega8 -P com3 -c avrisp -b 19200

I’m using com3 on my machine, and my target AVR is an Atmega8. The output of this command should look similar to this:

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.14s

avrdude: Device signature = 0×1e9307

avrdude: safemode: Fuses OK

avrdude done. Thank you.

In this instance, I know the device signature for the Atmega8 is 0×1e9307. If you receive a null value (0×00000 or 0xFFFFFF), recheck your wiring, com port and try again. If you have selected the wrong value for the -p command option for AVR-DUDE, a proper device signature will be recieved but will fail the last check.

If you have an Atmega168, from here you can just select “Burn Bootloader w/ AVRISP mkII” from the Arduino Tools menu. This will program the new chip with the Arduino bootloader. At this point you will be able to pop the old Atmega from the Arduino board, place the new chip in and be able to program straight away!

If like myself, you are caught with more Atmega8’s then you know what to do with, fear not. There is a modified version of the Arduino bootloader adapted to the Atmega8’s internal clock. This allows us to create custom circuits that run on the Arduino software requiring only power (no external caps or crystals).

Download the file from todbot’s blog and unzip to the hardware/bootloaders directory of your Arduino install.

I prefer to use AVR-DUDE from the command line to burn my .hex files, however the option can be added to the Arduino menu as per the instructions here.

To load the .hex file, open a command prompt and navigate to the folder you unziped to, and run the following command:

avrdude -p atmega8 -P com3 -c avrisp -b 19200 -U flash:w:ATmegaBOOT.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.14s

avrdude: Device signature = 0×1e9307

avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed

To disable this feature, specify the -D option.

avrdude: erasing chip

avrdude: reading input file “ATmegaBOOT.hex”

avrdude: input file ATmegaBOOT.hex auto detected as Intel Hex

avrdude: writing flash (8150 bytes):

Writing | ################################################## | 100% 2.42s

avrdude: 8150 bytes of flash written

avrdude: verifying flash memory against ATmegaBOOT.hex:

avrdude: load data flash data from input file ATmegaBOOT.hex:

avrdude: input file ATmegaBOOT.hex auto detected as Intel Hex

avrdude: input file ATmegaBOOT.hex contains 8150 bytes

avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 14.75s

avrdude: verifying …

avrdude: 8150 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done. Thank you.

From here the Atmega8 has been programmed with the modified Arduino bootloader. To ensure all compiled sketches comply to the new chip’s clock and other features, the following append must be made to the hardware/boards.txt file in your Arduino directory:

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

atmega8noxtal.name=ATmega8-noxtal @8MHz

atmega8noxtal.upload.protocol=stk500

atmega8noxtal.upload.maximum_size=7168

atmega8noxtal.upload.speed=38400

atmega8noxtal.bootloader.low_fuses=0xdf

atmega8noxtal.bootloader.high_fuses=0xc4

atmega8noxtal.bootloader.path=atmega8_noxtal

atmega8noxtal.bootloader.file=ATmegaBOOT.hex

atmega8noxtal.bootloader.unlock_bits=0×3F

atmega8noxtal.bootloader.lock_bits=0×0F

atmega8noxtal.build.mcu=atmega8

atmega8noxtal.build.f_cpu=8000000L

atmega8noxtal.build.core=arduino

From here, the Atmega8-noxtal will be available in the Tools-Boards menu.

If you have left your Atmega8 in your Arduino board you should be able to upload via the IDE with all your old .pde sketches.

Moving forward, you can start looking at your own circuits to move your newly programmed chip to!

Add A Comment