Pages: [1]   Go Down
Author Topic: Starting Out On AVR Programming  (Read 861 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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?
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8842
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I found a tutorial http://www.sparkfun.com/tutorials/200 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?

Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1122
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1122
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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 smiley-razz) 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: http://arduino.cc/forum/index.php/topic,125248.msg947938.html#msg947938 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)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 484
Posts: 18767
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I made one here (which strykeroz mentioned):

http://www.gammon.com.au/forum/?id=11638

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.



Logged


Pages: [1]   Go Up
Jump to: