Apr 04 2012

Bootloading an ATmega88 for Arduino [w/ code]

Published by at 9:25 am under electronics,programming,Recommended,Solutions,tips,Website

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.

Share

7 responses so far

7 Responses to “Bootloading an ATmega88 for Arduino [w/ code]”

  1. moonyon 27 Oct 2012 at 6:45 pm

    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 :)

  2. moonyon 28 Oct 2012 at 6:40 pm

    Hey you definetely got the Tx and Rx lines wrong, maybe more. Looks like, you placed the Atmega upside down..

  3. Hasanon 04 Nov 2012 at 9:09 pm

    avrdude: Expected signature for ATMEGA88 is 1E 93 0A
    Double check chip, or use -F to override this check.

    This error ?

  4. lucason 22 Apr 2013 at 6:30 pm

    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

  5. Mikeon 12 Jun 2013 at 3:21 pm

    Agreed with earlier - the chip is the wrong way round. Also, no current limiting resistor on the LED

  6. Eugeneon 18 May 2014 at 4:30 pm

    avrdude: stk500_paged_write(): (a) protocol error, expect=0x14, resp=0xfc
    avrdude: stk500_cmd(): protocol error

    atmega88V

    ?!

  7. […] 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 […]

Trackback URI | Comments RSS

Leave a Reply