Starting Out On AVR Programming

OK, so I'm starting out on AVR programming and I have a question about programming a standalone ATmega328p. I'm confused about bootloaders :sweat_smile:

I've already got an arduino uno and I'm planning to use it to upload AVR (hex) code on to the IC. The ATmega328p I'm planning to buy already has an arduino bootloader in it. Does this mean that I can't upload AVR code on to the standalone chip? If so, what do I need to do so that it can accept AVR code?

It means you will have to supply an external clock. When the Arduino bootloader is installed the configuration fuses on the chip are set to expect an external 16 MHz crystal or resonator. The chip can't accept serial programing without a system clock so you have to provide one.

You could provide the target ATmega with a 16 MHz crystal (and load capacitors) or resonator. Alternatively, there are versions of the ArduinoISP sketch that can provide an 8 MHz clock on one of the Arduino output pins. You can connect that clock to the target ATmega's XTL1 pin to act as the required external clock.

I found a tutorial Installing an Arduino Bootloader - SparkFun Learn which tells me how to to use an arduino to program an AVR. But the introduction seems to imply that the Atmega chip they're using does not have an arduino bootloader in it.

So if I follow what you said and provide the ATmega32p with a 16MHz crystal then follow the sparkfun tutorial I linked above, I should be able to upload hex code to the AVR right?

I don't need to remove the arduino bootloader?

Also, that tutorial is for an Arduino Duemilanove. I can do the same thing on an Arduino UNO R3 (which contains another 328p) right?

Hi

You have choices - you can leave the bootloader on there, and use it to help you get the program onto the chip via serial. That's the way the IDE does it for your Arduino, and the bootloader is left in place on the chip ready to load further hex files ongoing. Or you can overwrite the bootloader in the way that Sparkfun tutorial did and program the microcontroller that way. The bootloader way is convenient if you use the IDE as your programming environment, and using the serial interface allows easy comms back to your PC for debugging and other output via FTDI whereas the other way gives you more flash to store your program in as there's no bootloader there taking up space and your program will start without the bootloader's small delay.

Buying bare ATMega chips is typically cheaper than buying them with the bootloader, and there are lots of sketches out there to load a bootloader on the bare uC too.

Here's some more good reading which includes some more background to this:
This one on loading and using the bootloader on a bare uC
And this one on updating a bootloader on another Arduino

Basically, there's no right or wrong way - it really is your choice. HTH
Geoff

If so, what do I need to do so that it can accept AVR code?

I would get a standalone programmer. They are so cheap now and provide you with the flexibility to move up to a new world without arduino.

Someone was listening. The latest episode of The Ben Heck Show (youtube) explains the difference between ICSP and serial bootloader programming before he launches into the day's project.

dhenry:

If so, what do I need to do so that it can accept AVR code?

I would get a standalone programmer. They are so cheap now and provide you with the flexibility to move up to a new world without arduino.

I really would like to get a standalone programmer but my budget is a bit tight (college student studying electronics :P) and since I already have an arduino I thought I might as well use it. I searched through the forums a bit more today and found this thread: Arduino Uno R3 as a true ISP programmer for any AVR - #21 by simplex - Microcontrollers - Arduino Forum which I think is similar. The guy who started the thread mentions that his Atmega chip has an arduino bootloader. So I think I should be fine if I follow that procedure. (Hopefully)

strykeroz:
Someone was listening. The latest episode of The Ben Heck Show (youtube) explains the difference between ICSP and serial bootloader programming before he launches into the day's project.

Thanks for that! That channel is really useful!

I made one here (which strykeroz mentioned):

More recently I freed up my Uno by making a dedicated one using the "Evil Mad Scientist" prototyping board. That's the chip, the crystal, a couple of caps, and the SD card reader.

Even so, the parts probably cost somewhat more than the $10 you can get a dedicated programmer from, on eBay.