Just wanted to put up a small tut on how to put an Arduino bootloader on an ATmega88.
I very roughly followed:
http://www.ladyada.net/learn/avr/avrdude.html
And
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:
http://www.atmel.com/Images/2545s.pdf
First, put everything on a breadboard: (This took me a while… Thanks D.Mellis and M.Feldmeier!!)
(Fritzing is awesome)
Note:
- 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:
https://raw.github.com/royshil/ATmega88-bootloader/master/ATmegaBOOT_88.c
You can also just get the .hex file and burn right away!
https://raw.github.com/royshil/ATmega88-bootloader/master/ATmegaBOOT_88_m88.hex
To build it I also borrowed Arduino’s Makefile, but it also needed some tweakin’:
https://raw.github.com/royshil/ATmega88-bootloader/master/arduino_Makefile
(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
https://github.com/royshil/ATmega88-bootloader
To program via USB I use:
http://arduino.cc/en/Main/USBSerial
I used this guide roughly to setup Arduino app to “understand” ATmega88:
http://arduino.cc/en/Hacking/Programmer
This is also helpful:
http://arduino.cc/en/Hacking/Bootloader
(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,
Roy.
10 replies on “Bootloading an ATmega88 for Arduino [w/ code]”
Hi,
I got pretty far: bootloader is on the Atmega88, changed code in arduino-devices, Arduino finds the board “Atmega88”. But when I try to program, it says my serial-port ttyACM0 is already in use. That can’t be true.. Any Idea?
Cool project anyway 🙂
Hey you definetely got the Tx and Rx lines wrong, maybe more. Looks like, you placed the Atmega upside down..
avrdude: Expected signature for ATMEGA88 is 1E 93 0A
Double check chip, or use -F to override this check.
This error ?
Hi! i’m trying to do this with an Atmega88-pa.
Do you have any .hex for this mcu?
I’m using a FTDI chip to link my mcu with my win pc, is there any code diference?
Thanks
Agreed with earlier – the chip is the wrong way round. Also, no current limiting resistor on the LED
avrdude: stk500_paged_write(): (a) protocol error, expect=0x14, resp=0xfc
avrdude: stk500_cmd(): protocol error
atmega88V
?!
[…] 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 […]
Hi !
There is an error in your boards.txt extension …
If you set the efuse to 00h this results in a boot size of 1024 WORDS – not 1024 Bytes.
The mega88 has 8k Flash = 8192 Bytes.
So this line is def. wrong:
atmega88.upload.maximum_size=7168
Change the line to
atmega88.upload.maximum_size=6144
Now the bootloader wont override the flash … I hade this several times and wonder why my sketch won´t run. The drawback is that you have 1k less flash. Now my mega88 is to small for my sketch …
Anyway. You should fix this !
Dominik
[…] el ATmega88PA, el proceso es similar. En este enlace tenéis toda la información en este enlace: https://www.morethantechnical.com/2012/04/04/bootloading-an-atmega88-for-arduino-w-code/. En este caso tenemos un bootloader para este microcontrolador, basado en el bootloader del […]
Either things have changed since this post was originally made, or the author got a couple things wrong. I managed to get the bootloader burned to the ATMEGA 88, but I had to do a lot of trial and error as well as some revising of the boards.txt code. There are some extra bits required for the Arduino IDE to be able to upload code to the 88. You need to add the upload tool, and the burn tool, and a few other things. Look at some of the other boards listed in the boards.txt to see what is missing. Also, make sure to do the burn via the command line and not through the IDE so you can use verbose mode and modify the parameters of the burn.