In preparation of the quest to build my own wireless sensor network I spent some time in getting a minimal Arduino up and running based on the ATmega8 chip. It was not before I finally succeeded that I realized it would be of no use in this case, because the ATmega8 lacks the ability to trigger an interrupt handler through its watchdog timer. So, I wouldn’t be able to use its power down sleep mode.
I then found a couple of ATmega88 chips in my stockpile, which aren’t subject to this limitation. Fortunately, setting this one up as a minimal Arduino turned out to be much the same. I mostly followed an existing guide, but added the Optiboot bootloader to the mix.
I first needed to compile the bootloader for the use with the internal osciallator at 8Mhz. So I added the following lines to arduino-1.0.5-r2/hardware/arduino/bootloaders/optiboot/Makefile
:
atmega88_8: TARGET = atmega88 atmega88_8: MCU_TARGET = atmega88 atmega88_8: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=19200' atmega88_8: AVR_FREQ = 8000000L atmega88_8: LDSECTIONS = -Wl,--section-start=.text=0x1e00 -Wl,--section-start=.version=0x1ffe atmega88_8: $(PROGRAM)_atmega88_8.hex atmega88_8: $(PROGRAM)_atmega88_8.lst
I limited the baud rate to 19200 as greater values turned out to be less reliable in my setup. For this to work, I had to explicitly disable SOFT_UART
in optiboot.c
:
/* Switch in soft UART for hard baud rates */ #if (F_CPU/BAUD_RATE) > 280 // > 57600 for 16MHz #ifndef SOFT_UART //#define SOFT_UART #endif #endif
With that you can build the bootloader by running make atmega88_8
or omake.bat atmega88_8
on Windows in that same directory.
Next, I added the new Arduino type to arduino-1.0.5-r2/hardware/arduino/boards.txt
. It should have been possible to add the board definition to a boards.txt
file below the sketchbook directory but that did not work for me and the current version of my Arduino IDE.
atmega88_8.name=ATmega88 Optiboot (8MHz internal OSC) atmega88_8.upload.protocol=arduino atmega88_8.upload.maximum_size=7680 atmega88_8.upload.speed=19200 atmega88_8.bootloader.low_fuses=0xe2 atmega88_8.bootloader.high_fuses=0xdf atmega88_8.bootloader.extended_fuses=0x00 atmega88_8.bootloader.path=optiboot atmega88_8.bootloader.file=optiboot_atmega88_8.hex atmega88_8.bootloader.unlock_bits=0x3F atmega88_8.bootloader.lock_bits=0x0F atmega88_8.build.mcu=atmega88 atmega88_8.build.f_cpu=8000000L atmega88_8.build.core=arduino atmega88_8.build.variant=standard
Finally, with the ISP connected, I installed the new bootloader using the Aduino IDE and can now upload sketched through the serial connection.
There seems to be one annoying issue left though. When the compiled sketch size is getting close to the limit of 7680 bytes the upload will fail with an error message. If anyone can shed some light on what I might have missed here, please leave me a comment.
Hi !
Fist of all thx for this stuff. I had some mega88, too 🙂
Ok I think there is a little mistake in your story. extended_fuses=0x00
This is wrong. It must be extended_fuses=0x02.
Check this page:
http://www.engbedded.com/fusecalc/
If you select mega88 and set efuse to 00 you will get a bootloader size = 1024 pages. But you only need 512.
You can doublecheck it by opening the compiled HEX file for the mega88 Bootloader. It starts with the address 0xE000 in the first line. And that is the boot start address when using efuse = 02 🙂
Best regards
Dominik
I am from Bangladesh..Thank you so much… i can compile my code for atmega88 according to your instruction …
i can;t burn the bootloader…says
avrdude: can’t open input file C:\Program Files\Arduino\hardware\arduino\bootloaders\optiboot\optiboot_atmega88_8.hex: No such file or directory
avrdude: read from file ‘C:\Program Files\Arduino\hardware\arduino\bootloaders\optiboot\optiboot_atmega88_8.hex’ failed
how should i do??
@shahadat: Have you compiled the bootloader successfully? Have you copied the resulting .hex to your Arduino path? With your current config, you need to place it in “C:\Program Files\Arduino\hardware\arduino\bootloaders\optiboot\” and you need to name it “optiboot_atmega88_8.hex”.