Arduino Bootloader

Arduino among others has a really nice feature… The bootloader. Once you burn it on the chip you can upload your code without the need of an external programmer.

I have started using it for my AVR projects but i came across on some issues so i compiled a COMPLETE list of what you need to do it, in order not to search again for the obvious…

Programmer used AVR910 (or compatible) with avrdude. In the avrdude commands I assume that the
programmer is AVR910, COM port=COM3 and baud rate=115200. Adjust to your programmer.

Have in mind that you might use also -x devcode=0×35 for AVR910

ATMEGA8

The default fuses of ATMega8 are (pdf and locally tested):
High Fuse:      0xd9
Low Fuse:       0xe1
Lock:           0x3f

Programming the bootloader. Chip erase (-e maybe needed in some cases)

  • Unlock the bootloader (TEST: try with -e)

avrdude -c avr910 -P com3 -b 115200 -p atmega8 -U lock:w:0xff:m
(fails with avrdude: verification error, first mismatch at byte 0×0000 0xff != 0x3f)

  • Program the fuses

avrdude -c avr910 -P com3 -b 115200 -p atmega8 -U hfuse:w:0xca:m -U lfuse:w:0xdf:m

  • Burn the bootloader (TEST: try with -D disable auto erase)

avrdude -c avr910 -P com3 -b 115200 -p atmega8 -U flash:w:ATmegaBOOT.hex

  • Lock the bootloader

avrdude -c avr910 -P com3 -b 115200 -p atmega8 -U lock:w:0xcf:m
(fails with avrdude: verification error, first mismatch at byte 0×0000 0xcf != 0x0f)

But it works….

ATMEGA168

The default fuses of ATMega168 are (pdf and locally tested):
High Fuse:      0xd9
Low Fuse:       0xe1
Lock:           0x3f

Programming the bootloader. Chip erase (-e maybe needed in some cases)

  • Unlock the bootloader

avrdude -c avr910 -P com3 -b 115200 -p atmega168 -U lock:w:0x3f:m

  • Program the fuses

avrdude -c avr910 -P com3 -b 115200 -p atmega168 -U hfuse:w:0xdd:m -U lfuse:w:0xff:m -U efuse:w:0x00:m

  • Burn the bootloader

avrdude -c avr910 -P com3 -b 115200 -p atmega168 -U flash:w:ATmegaBOOT_168_ng.hex

  • Lock the bootloader

avrdude -c avr910 -P com3 -b 115200 -p atmega168 -U lock:w:0x0f:m

And now the good part:

Once you burn the bootloader to a chip you can use this excellent program to upload any hex file to your ATmega with Arduino uploader

References

Updated: April 2012

  1. geertbarents
    November 13th, 2009 at 23:11 | #1

    the only thing i get is ”initialization failed, rc=-1

    please help

    Grtz, Geert

  2. November 13th, 2009 at 23:41 | #2

    What is the exact command that is failing ? Linux or Windows ?

  3. geertbarents
    November 14th, 2009 at 03:16 | #3

    @billy

    windows.
    and the command is:
    1. avrdude -p atmega8 -c usbtiny -b 115200 -U lock:w:0xff:m
    2. avrdude -p atmega8 -c usbtiny -b 115200 -U hfuse:w:0xca:m -U lfuse:w:0xdf:m
    3. avrdude -p atmega8 -c usbtiny -b 115200 -U flash:w:ATmegaBOOT.hex
    4. avrdude -p atmega8 -c usbtiny -b 115200 -U lock:w:0xcf:m

    Grtz. Geert

  4. geertbarents
    November 14th, 2009 at 03:24 | #4

    i made a test board for this

    connections:
    icsp atmega8 -16pu
    1 –> MISO
    2 –> none
    3 –> SCK
    4 –> MOSI
    5 –> RESET
    6 –> none

    and then for the atmega8 -16pu:
    pin 7 VCC and pin 20 AVCC to 4,5 v
    pin 8 GND and pin 22 GND to GND

  5. December 20th, 2009 at 18:33 | #5

    Wiring looks correct. But you are missing 6->GND

    Do you want me to send you a programmed atmega8 ?

  6. June 24th, 2010 at 13:01 | #6

    I try to upload Arduino to ATMega328 with AVR910 programmer, but not success. Anyone can suggest me what software that support AVR910 and ATMega328?

  7. Prashanth
    March 13th, 2011 at 17:00 | #7

    Hey,
    Brilliant tutorial… Very easy to follow and straight forward..Thank you so much..i spent days on this..