ATMega8

I have just implemented the optiboot on both ATMega8 with 16Mhz, and ATMega8L with 8Mhz.

The optiboot bootloader is faster, you get to upload your sketches vey fast, speed up 115K, and more important, it is smaller in size, so you get more space for your sketches.

First you need to download the source code as it is updated with the fix for the ATMega8, but wait a second, it is not so straight forward like you thought.

 

You need to download and install the Mercurial software.

Once it is installed, open command prompt, and type "hg clone https://optiboot.googlecode.com/hg/ optiboot" This command will create a folder named optiboot , and download the source files in it.

One more step, still in the command prompt, type "cd optiboot\optiboot\bootloaders\optiboot" to go to the bootloader folder, and type "make atmega8" it will create a new file named "optiboot_atmega8.hex".

OK all done here, we continue with the normal process below, making sure to put the file we just created in the appropriate folder in the arduino installation folder under hardware\arduino, and change the ".upload.speed=19200" to ".upload.speed=115200", and the ".bootloader.file=ATmegaBOOT.hex" to ".bootloader.file=optiboot_atmega8.hex", and ".upload.maximum_size=7168" to ".upload.maximum_size=7680" which is the reason besides speed to make this bootloader, the rest should work without a change.

Another change that might be of interest, is, if you want to use your atmega8 with a 8Mhz Crystal or the internal clock, you have to make a little change to the Makefile, just add:

 

# ATmega8_8Mhz
#
ATmega8_8Mhz: TARGET = atmega8
ATmega8_8Mhz: MCU_TARGET = atmega8
ATmega8_8Mhz: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
ATmega8_8Mhz: AVR_FREQ = 8000000L
ATmega8_8Mhz: LDSECTION  = --section-start=.text=0x1e00
ATmega8_8Mhz: $(PROGRAM)_atmega8_8Mhz.hex
ATmega8_8Mhz: $(PROGRAM)_atmega8_8Mhz.lst
ATmega8_8Mhz_isp: atmega8
ATmega8_8Mhz_isp: TARGET = atmega8
ATmega8_8Mhz_isp: MCU_TARGET = atmega8
# 2.7V brownout
ATmega8_8Mhz_isp: HFUSE = DC
# Low power xtal (16MHz) 16KCK/14CK+65ms
ATmega8_8Mhz_isp: LFUSE = BF
ATmega8_8Mhz_isp: isp

 

and type make atmega8_8mhz, this will compile the bootloader for the atmega8 with 8Mhz, and also remember to change the fuse settings, f_cpu, and file name appropriately.

Now that we have our bootloaders ready, the first thing to make a standalone ATMega8 AVR work with Arduino, is to edit the Arduino boards.txt file, found in the arduino installation folder under hardware\arduino.

We need to add a new custom board, so we add this to the end of the file:

 

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

opti8.name=Arduino Optiboot8
opti8.upload.protocol=stk500
opti8.upload.maximum_size=7680
opti8.upload.speed=115200
opti8.bootloader.low_fuses=0xff
opti8.bootloader.high_fuses=0xc8
opti8.bootloader.path=optiboot
opti8.bootloader.file=optiboot_atmega8.hex
opti8.bootloader.unlock_bits=0x3F
opti8.bootloader.lock_bits=0x0F
opti8.build.mcu=atmega8
opti8.build.f_cpu=16000000L
opti8.build.core=arduino

 

make sure the path to the bootloader is in the correct folder, hardware\arduino\bootloaders, note also that this setting is for atmega8 with 16Mhz external crystal, and I even tested it on both the atmega8 and atmega8L, although the atmega8L is overclocked, and it is outside the limits in the data sheet, but it works fine on 5V., yet , it is not recommended, specially in a production environment.

OK, we are ready now, connect your programmer as you always do, and select the correct board, and serial port from the tools menu, and then burn the bootloader using your preferred programmer.

I have used an arduino duemilanove board, as ISP, the last selection in the picture below.

To see how to use your arduino as ISP programmer check this tutorial.

 

It will take some time to program, and then you're done.

Congratulations, now you can use a very simple MAX232 chip to connect to your atmega8 using serial USART and program it with the arduino IDE, but remember, you have to reset the chip right after you click on the upload button, if you have an LED on pin 13, which is PB5, or pin 19 in the atmega8 chip, it will blink fast bursts, announcing that the bootloader is waiting for the data, otherwise, it will just go directly to execute the sketch, so you must reset it to be able to upload.