Atmega328P bootloader. etc.

I'm just collecting together the info I needed to successfully burn an Arduino bootloader onto a 328, which (for those who don't know) gives me twice the RAM, Flash, and EEPROM of an Atmega168. Getting my setup working wasn't easy, and I had a lot of false starts.

  1. Get and install the latest version of the Arduino IDE, which as I write is 0014.
    http://arduino.cc/en/Main/Software
  2. Get the latest copy of AVRdude. I'm working on Windows so I got WinAVR. I actually got the latest release candidate, which is 20090306rc1. You can pick it up here:
    WinAVR - Browse Files at SourceForge.net
  3. Inside the Arduino installation folders is this location:
    NAME_OF_ARDUINO_FOLDER\hardware\tools\avr.
    I replaced everything in there with the freshest copy of WinAVR.
  4. In NAME_OF_ARDUINO_FOLDER\hardware\tools\avr\etc is a file called avrdude.conf. I replaced it with the copy I picked up here:
    http://wolfpaulus.com/sys/arduino/avrdude.conf
  5. I have an ICSP programming board made from a cheap Olimex board I bought from Sparkfun.com. I used a serial ICSP connection on COM2 to burn the bootloader found here:
    http://wolfpaulus.com/sys/arduino/AT328.hex
    using this command-line command launched from within the WinAVR folder (where I'd put a copy of AT328.hex).

avrdude -F -pm328p -cponyser -Pcom2 -b56000 -u -v -Uflash:w:AT328.hex

that worked. I then did something I don't fully understand to the fuses:

avrdude -F -pm328p -b56000 -Pcom2 -cponyser -V -U lock:w:0xCF:m

I took the Atmega328 out and popped it into an Arduino NG board, set the IDE to Arduino Duemilenove w/ Atmega328, hit reset on the board (unnecessary on more modern boards) and successfully uploaded a sketch.

Twice the Flash means twice the awesomeness! There were things that had been impossible that now are quite possible.

Eeek!
Can't you just burn it with the IDE by setting Board to "Arduino w/ Atmega328", hooking up the programmer and using Burn Bootloader ?

If not, I thank you for your very good step by step instructions.
(I was hoping to do it as I just described though.)

i tried the easy way and it kept NOT working. this was partly due to the fact that WinAVR as shipped in Arduino IDE 0014 does not have any references to the Atmega328, so it can't possibly burn a bootloader. at the minimum you're going to need the latest copy of WinAVR (or whatever AVRdude works in your environment).

with the setup i'm describing, i'm guessing you could use other methods to burn a bootloader, including perhaps the parallel burner.

I see. Then I really thank you for documenting your procedure and saving lots of frustration.

(You'd think with the 328 becoming the defacto, this will get easier.)
I'll be using a parallel programmer that has worked well for the 168 so I hope I'm OK with that.

BTW, You'll have to change your logo now.

Can i know whether there is an arduino bootloader available forATmega16L .
i have a icsp ( programmer) and i use the latest avrstudio4 and winavr..I have a duemilanove board also.
Please guide me to burn the bootloader into this Uc.
If the bootloader gets burned is it possible to erase it at a later stage or does it become permanent.
Since it is being written in the flash so i guess it can be erased..Please help me out as soon as possible.

I also tried to take the atmega168 out of the duemilanove and test the blinking led function in the bread board.it didnt work.i guess this is because i wasn't using an external crystal osc.(16MHz in this case).would it work if i place an external crystal oscillator in the bread board .

For #2, yes it requires a external crystal or resonator and a pull-up resistor for the reset pin.

Lefty

Actually i burn all my 328 with the IDE and a serial AVR ISP?

there's definitely something not quite right about Atmega328 support in the stock Arduino 0014 IDE or in my experimentally-modified version. I suspect there is something subtly wrong with the bootloader (and I've tried several at this point). I can write the bootloaders okay, but 328s with these bootloaders are not plug-in compatible with Atmega168s in an Arduino board (the board I am using is an old NG modified with a 0.1 microfarad capacitor to act like a Diecimila). In the IDE I change the board settings to Duemilanove with Atmega328 and try to upload a sketch and it almost never works. It worked precisely once, causing me to start this thread, but it seems now this success was a fluke. Does the Diecimila board (or the modified NG board I'm using) not support the atmega328 with bootloader? Has the auto-reset timing been changed with the Duemilanove?

They are pin compatible and will work in those boards. It sounds as if you didn't set the lock bits correctly. There is a thread detailing how they should be set somewhere around here. I know they are different than the 8/168.

@bigfun, burn the bootloader again and if it works again only once, then you are erasing the bootloader while uploading the sketch.

hmm, well i think you're right nkcelectronics because i have tried several bootloader/sketch upload cycles, and i can reliably get the sketch to upload precisely once, immediately after uploading a new bootloader. you've seen the fuses i tried setting. looking around, i've also found the following fuse settings on http://wolfpaulus.com/journal/embedded/arduino4.html:

UNLOCK
avrdude -p m328p -b56000 -Pcom2 -cponyser -V -e -U lock:w:0x3F:m -U hfuse:w:0xD8:m

LOCK 328
avrdude -p m328p -b56000 -Pcom2 -cponyser -V -U lock:w:0x0F:m

but i'm still getting the same results. does anyone know the proper AVRdude commands for setting the fuses correctly? i don't really care to know what the various fuse bits mean (everyone seems to want to talk about this but it just makes my eyes glaze over), i just want the setup that leads to a functional Arduino.

My notes are in the "bootloader" application hint at
http://tinyurl.com/5rfmrz

The avrdude command line is in the Makefile. I burned the bootloader
and then tested it with the arduino-0012. I have not checked the fuse values
against the datasheet but I was able to successfully load and run sketches.

(* jcl *)

hmm, well i think you're right nkcelectronics because i have tried several bootloader/sketch upload cycles, and i can reliably get the sketch to upload precisely once, immediately after uploading a new bootloader. you've seen the fuses i tried setting. looking around, i've also found the following fuse settings on http://wolfpaulus.com/journal/embedded/arduino4.html:

UNLOCK
avrdude -p m328p -b56000 -Pcom2 -cponyser -V -e -U lock:w:0x3F:m -U hfuse:w:0xD8:m

LOCK 328
avrdude -p m328p -b56000 -Pcom2 -cponyser -V -U lock:w:0x0F:m

but i'm still getting the same results. does anyone know the proper AVRdude commands for setting the fuses correctly? i don't really care to know what the various fuse bits mean (everyone seems to want to talk about this but it just makes my eyes glaze over), i just want the setup that leads to a functional Arduino.

It is documented in boards.txt in your Arduino IDE installation.

atmega328.bootloader.low_fuses=0xFF
atmega328.bootloader.high_fuses=0xDA
atmega328.bootloader.extended_fuses=0x05
atmega328.bootloader.path=atmega168
atmega328.bootloader.file=ATmegaBOOT_168_atmega328.hex
atmega328.bootloader.unlock_bits=0x3F
atmega328.bootloader.lock_bits=0x0F

Maybe you have a faulty ATmega328P? or some HV erase is needed...