Programming Arduino Bootloader on Mega8 using an Arduino

While building a couple of arduinos, I found out that I had a few Mega8 chips left. I thought I might use them as Arduino and wanted to program them with arduino firmware. Tried researching about arduino as ISP and burning the boot-loader using arduino GUI but it was for Mega328. The process miserably failed because the device signatures didn't match. Anyways, came up with a combination of arduino isp and avrdude for rescue. First convert a working arduino into AVRISP programmer and then use it to program a blank AVR.

For this I used

Prerequsites:

  1. Ubuntu 10.04LTS machine or VM
  2. Install arduino gui from arduino.cc. I downloaded arduino v22 so I installed it in ~/arduino-0022
  3. Download and unzip Mega-ISP sketch from http://code.google.com/p/mega-isp/downloads/list. I downloaded version .04 (latest at the time of writing)
  4. A fully functional arduino board setup will be required. This will act as the ISP programmer.
  5. Target arduino board with blank ATMega8 chip.


Here is the procedure:

  1.  Wire up the arduino boards using the instructions at: http://arduino.cc/en/Tutorial/ArduinoISP. If you have a non standard pinout arduino clone, connect following pins of source to target
    Source Arduino PinTarget Arduino Pin
    1313
    1212
    1111
    10RST
    +5v+5v
    gndgnd
  2.  Install avrdude on the operating system:
sudo apt-get install avrdude

3. Load your Programmer Arduino baord with Mega-ISP sketch. Make sure that sketch is written properly to the board.

4. copy ATMegaboot from arduino installation (in my case ~/arduino-0022)
cp ~/arduino-0022/hardware/arduino/bootloaders/atmega8/ATmegaBOOT.hex ./

5. Copy and paste the following code on your linux shell prompt. This will create a file flash.sh and will make it executable:
echo '#!/bin/bash
cmd="`which avrdude`"
chip="atmega8"
options="avrdude -p $chip -c avrisp -P /dev/ttyUSB0 -b 19200"

# Erase chip write lock and fuses
$cmd $options -e -U lock:w:0x3f:m -U lfuse:w:0xdf:m -U hfuse:w:0xca:m

# Upload bootloader code
$cmd $options -D -U flash:w:ATmegaBOOT.hex:i

# Lock boot section
$cmd $options -U lock:w:0x0f:m
' > flash.sh; chmod u+x flash.sh


6. Check your wiring again and execute
./flash.sh

7. If things go well you will see successful avrdude messages and your Mega8 will be programmed with arduino boot. This procedure can be used to flash other hex files as well.

I have built a small ISP pcb that I plug my arduino into if I need ISP capabilities to program other AVRs, just use the right AVR device with avrdude options.

Comments