Just wanted to put up a small tut on how to put an Arduino bootloader on an ATmega88.
I very roughly followed:
http://itp.nyu.edu/physcomp/Tutorials/ArduinoBreadboard (Although they make it way too complicated)
And ATMEL’s datasheet for ATmega88 is also very good to have open at all times:
First, put everything on a breadboard: (This took me a while… Thanks D.Mellis and M.Feldmeier!!)
(Fritzing is awesome)
- when programming with the AVR ISP mkII, disconnect the LED because it shorts to ground.
- Make sure you remember the pullup resistor on the RESET so that the signal is pulled nice and high (Thanks B.Melton!),
- and also the 0.1uF capacitor for the USB FTDI programmer so that the short burst of RESET becomes a good long signal so the chip will be happy.
Now, we need to understand the fuses on the chip so it will:
- Fire the bootloader after RESET (BOOTRST fuse)
- Set the bootloader section size to 1024 words (2048 bytes), because the compiled bootloader is ~1400 bytes (BOOTSZ0 & BOOTSZ1)
- Enable SPI programming, of course, we don’t want to brick the chip (SPIEN)
- Set the clock to the internal 8Mhz clock, since wee don’t use an external one
To get values for the fuses: http://www.engbedded.com/fusecalc/
I ended up using:
EFUSE = 0x00 LFUSE = 0xe2 HFUSE = 0xdf
Rewriting and burning the bootloader
Next step is to write the bootloader code. I borrowed Arduino 1.0’s ATmegaBOOT_168.c, which has all the setup already in there, but it doesn’t support ATmega88… some changes were needed.
But you guys can get the final product:
You can also just get the .hex file and burn right away!
To build it I also borrowed Arduino’s Makefile, but it also needed some tweakin’:
(Take a special look at “LDSECTION = –section-start=.text=0x1800” because it holds the key to putting the bootloader in the right spot on the flash memory. I worked according to the datasheet, look under Table 26-9 page 281)
But then – a moment came where something started working… the AVR ISP mkII was no longer complaining it can’t talk to the chip and burned the bootloader!!
Making Arduino happy
OK bootloader is burnt on the chip, now I had to configure Arduino to work nicely with ATmega88.
I tweaked $(ARDUINO)/hardware/arduino/boards.txt to add this:
atmega88.name=ATmega88 atmega88.upload.protocol=arduino atmega88.upload.maximum_size=7168 atmega88.upload.speed=19200 atmega88.bootloader.low_fuses=0xe2 atmega88.bootloader.high_fuses=0xdf atmega88.bootloader.extended_fuses=0x00 atmega88.bootloader.path=atmega88 atmega88.bootloader.file=ATmegaBOOT_88_m88.hex atmega88.bootloader.unlock_bits=0x3F atmega88.bootloader.lock_bits=0x0F atmega88.build.mcu=atmega88 atmega88.build.f_cpu=8000000L atmega88.build.core=arduino atmega88.build.variant=standard
Now Arduino sees it under Tools -> Board -> ATmega88
Also, remember to put the bootloader hex file under: $(ARDUINO)/hardware/arduino/bootloaders/atmega88/ATmegaBOOT_88_m88.hex
At this point you should be able to upload Arduino sketches to your ATmega88 chip.
The first sketch that uploaded successfully – was like a wonderful mermaid song to me 🙂
Get all the code
To program via USB I use:
I used this guide roughly to setup Arduino app to “understand” ATmega88:
This is also helpful:
(We have a new category now in MTT – “electronics”! I hope to share some interesting stuff in it soon…)
Keep hacking, and share your knowledge,