Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
abcminiuser
PostPosted: May 18, 2006 - 10:04 AM
Moderator


Joined: Jan 23, 2004
Posts: 6964
Location: Melbourne, Victoria, Australia

There are many ways to program AVR microcontrollers. Since many people ask about different ones at one time or another, I thought I'd outline them here so that their questions can be answered quickly and efficiently. Please forgive me if I miss a method or make an error.

METHOD 1: In System Programming (ISP)
Supported By: Vast majority of AVRs (see below posts)
Supported Programmers: AVRISP MKI/II, JTAG MKII, STK500, STK600, Dragon, AVRISP clones, AVR910 Programmers, AVRONE
    In System Programming is perhaps the most common method of programming the flash, EEPROM, fuse and lockbytes of the entire AVR line. ISP can program AVRs at extremely high clock rates (assuming the target AVR is running at a high frequency and the programmer supports it) and is the method of choice for almost all AVR hobbyists. There are many, many AVRISP clones and AVR910 programmers on the market in addition to simple do-it-yourself dongles which connect to your computer's parallel port.

    Recent new dongle designs may use the computer's serial port, however anecdotal evidence has said that this method is *extremely* slow due to technical limitations.

    ISP requires that the target AVR is running at a clock rate of at least four times that of the ISP clock. This is a common pitfall and a source of confusion to many new to AVRs.


METHOD 2: JTAG
Supported By: See AVRStudio Tools help for MKI and MKII device support
Supported Programmers: JTAG-ICE, JTAG-ICE MKII, Dragon, JTAG-ICE clones, AVRONE, STK600 (programming only)
    Technically JTAG is a debugging system, not a programming method. Still, the JTAG interface allows for the programming of an AVR which supports it.

    JTAG is an in-system debugging tool which allows you to manipulate and examine the status of a supported AVR while it is running in a circuit. JTAG allows the user to stop execution at any time, the manipulation of the AVR's internal registers and much more.

    The official JTAG-ICE units from ATMEL have been superseded by the JTAG-ICE MKII, which supports the newer and more widely supported across the AVR range DebugWire debugging protocol as well as programming via the ISP method (see above).

    JTAG-ICE clones are available for low prices, however their limited compatibility with only a handful of AVRs limits their usefulness. Regardless of this, if your AVR supports the JTAG interface the JTAG-ICE remains a very nice and effective debugging method and programmer.


METHOD 3: DebugWire
Supported By: Many smaller AVRs
Supported Programmers: JTAG-ICE MKII, Dragon, AVRONE
    Again DebugWire is a debugging rather than a programming interface, but can be used to load in programs into supported AVRs. The dW interface uses a single AVR pin (the /RESET line) for all communications, making it ideal for the low-pin count AVR devices.


METHOD 4: Bootloader
Supported By: Most newer AVRs
Supported Programmers: N/A
    Again technically not a programming method. A bootloader is a small AVR program which sits in a user-settable reserved section of the regular flash. Bootloaders make use of the flash self-modification features available in the newer AVRs to allow the AVR to program itself via program data loaded from an external source. Bootloaders may source their data from any location (eg external dataflash or SD card) however by far the most common type of Bootloader communicates with a PC via the AVR's RS-232 (serial) port.

    Bootloaders are limited in that they do consume flash space (limiting the size of the flash available to the AVR's application) and they are unable to change the AVRs fusebits.

    Bootloaders are widely available on the internet for download, but they suffer from a "chicken and egg" problem; you need another type of programmer listed here to program in the bootloader in the first place. This is usually solved by the construction of a simple parallel port dongle (See ISP section) or by the purchase of an AVR already preloaded with a bootloader (eg the AVRButterfly board).


METHOD 5: High Voltage Parallel Programming (HVPP)
Supported By: Most non-TINY AVRs (with exceptions)
Supported Programmers: STK500, STK600, Dragon, Homebrew Dongles, AVRONE
    High Voltage Parallel Programming is a method of programming which is rarely used, because of the hassle it requires to set up. Despite this, HVPP programming is commonly used to "resurrect" AVRs whose fusebits have been mis configured via another programming method.

    Both the STK500 and the Dragon supports HVPP. During HVPP, the target's /RESET pin is raised to the unusually high value of 12V which engages the internal parallel programming circuitry. The /RESET pin is the only pin of the AVR (on HVPP supported AVRs) which can be safely raised to this level.

    You can make your own HVPP dongle using online plans such as this one.


METHOD 6: High Voltage Serial Programming (HVSP)
Supported By: Many TINY AVRs (with exceptions)
Supported Programmers: STK500, STK600, Dragon, Homebrew Dongles, AVRONE
    HVSP is similar to HVPP, except the data transfer is performed serially rather than in parallel. This is the alternate programming method used on many TINY series AVRs who lack enough pins for HVPP.


METHOD 7: PDI
Supported By: XMEGA AVRs
Supported Programmers: STK600, AVRONE, JTAG MKII, Dragon, AVRISP MKII
    PDI is the new programming interface based on the debugWire protocol, for the XMEGA line of AVRs. It's not currently used on any other 8-bit AVR microcontrollers.


METHOD 8: TPI
Supported By: 6-Pin TINY AVRs (ATTINY10, etc.)
Supported Programmers: STK600, Dragon, AVRISP MKII
    TPI is a very tiny programming interface for the newer TINY line of AVRs with limited pins, like the 6 pin ATTINY10. Like dW, TPI uses the device's /RESET line as part of the communication interface, but there the similarity ends. Since the pint-sized TINY AVRs lack a on-chip debugging circuit, the TPI protocol uses a new programming interface of three pins, in a half-duplex protocol. Because the /RESET line needs to be raised to +12V for programming when the device's RSTDSB pin is set, this is currently only supported by the newer STK600 programming board.



Bonus FAQ Section!

1) Which is the best method?
There is no universal "best" method. ISP programming is simple and extremely popular, however all the above methods will work. The two high voltage programming modes (whichever is applicable to your device) are the most feature rich, as they allow for the repair of an AVR which has had its fuses misconfigured. However, those methods are a pain to set up, hence the reason most users go with with ISP.

2) I've made a parallel port dongle. Can I use it with AVRStudio?
I'm afraid not. AVRStudio cannot interface with any "dumb" dongles - it requires a smart programming device - containing a microcontroller itself - to decipher the communication protocol it sends. Simple dongles without a microcontroller must be "bit-banged" (ie. the appropriate signals simulated through the dongle via the computer) itself.

3) So my dongle's useless then?
No. You can still program through a home made dongle with a third party programming software tool. AVRDude is a good, known, free command line utility - and it comes included with the WinAVR package.

4) What are my options if I want my programmer to work with AVRStudio?
Choose a programmer that uses an AVRStudio-supported protocol. This can be the simple "AVR910" protocol (deprecated) or a custom implementation of the protocol used by the STK500/AVRISP. Note that these programmers require a micro controller in them, leading to a catch-22 situation. This may be solved by having the programmer's AVR pre-programmed at time of purchase with the appropriate firmware, or by having the AVR pre-programmed with a bootloader.

5) Ok, I want to use a bootloader. How do I get it in there in the first place?!
To use a bootloader in an AVR, you first have to have the bootloader programmed in. If you do not have an existing programmer (even a simple dumb dongle will suffice for the initial programming), you can alternatively purchase AVRs pre-programmed with a bootloader from several suppliers.

Atmel also manufactures the Butterfly demo board, whose MEGA169 AVR comes pre-loaded with an AVR-Studio compatible bootloader.

6) Help! I've messed with the fuses and knackered my AVR while using ISP!
The most common mistake is changing the clock selection fuses to an invalid setting. Try putting an external clock on the AVR's XTAL1 pin and see if that helps.

Failing that, if possible use one of the high-voltage methods. These will fix any misconfiguration, including ones involving the clock source as the high-voltage methods provides its own clock to the AVR for programming.

7) How do I interface with my programmer?
Which software you use to interface with your programmer depends on the type of programmer you are using.

Simple "dumb" dongles require third party software, such as PonyProg or AVRDude. These may be command line or GUI tools - look around on the web and you will fine one to fit your needs.

Programmers and bootloaders based on the AVR910 protocol can be used within AVRStudio. From the Tools menu, select the "AVRProg" option to open up a GUI screen to interface with your programmer. As an alternative, third party tools such as AVRDude are also AVR910 compatible.

Official tools are tightly integrated into AVRStudio, especially in the case of the debugging variants (JTAG/Dragon/etc). From the AVRStudio Tools menu, select the "Program AVR..." submenu and click the "Connect" item. From the new window, select your tool and its connection interface and click ok.

As is the case with the dumb dongles and AVR910 programmers, the official tools may also be used with third party programming software.

- Dean Twisted Evil

(C) Dean Camera, 2009. All rights reserved. Not for reproduction on any website other than AVRFreaks.net without prior explicit permission.

_________________



Last edited by abcminiuser on Dec 24, 2009 - 06:53 AM; edited 22 times in total
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
dimonlp
PostPosted: May 18, 2006 - 10:17 AM
Wannabe


Joined: Dec 02, 2005
Posts: 78
Location: UK

Ecxellent! Just add examples!
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
mikehg1
PostPosted: May 21, 2006 - 12:51 AM
Hangaround


Joined: Feb 12, 2006
Posts: 279
Location: Ohio, USA

Quote:

METHOD 3: Bootloader
Supported By: MEGA AVRs
Supported Programmers: N/A


Hi Dean,

I think it would be more accurate to say bootloaders are supported by most newer AVRs since there are Tinys that support bootloaders also.

Thanks!
Mike H.
 
 View user's profile Send private message  
Reply with quote Back to top
abcminiuser
PostPosted: May 21, 2006 - 01:23 AM
Moderator


Joined: Jan 23, 2004
Posts: 6964
Location: Melbourne, Victoria, Australia

mikehg1,

You're right - I wasn't sure about the new TINYs so I played it safe. I've fixed my post - cheers.

- Dean Twisted Evil

_________________

 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
lfmorrison
PostPosted: May 23, 2006 - 07:46 PM
Raving lunatic


Joined: Dec 08, 2004
Posts: 4493
Location: Nova Scotia, Canada

Nitpick #2:
The ISP programming method isn't available on two currently in-production AVR's:
-ATtiny28
-ATmega406 (According to preliminary datasheet)

As well as at least one "mature but still available" AVR:
-ATtiny11

These devices must use HVPP ('406 and '28) or HVSP ('11) or JTAGmkII ('406) or Bootloader ('406).
 
 View user's profile Send private message  
Reply with quote Back to top
torocar
PostPosted: May 31, 2006 - 09:20 PM
Rookie


Joined: Apr 24, 2006
Posts: 36
Location: Somewhere, out there

Thanks for this tutorial... I'm sure it will help many AVR programmers who are starting... (like me...).
 
 View user's profile Send private message  
Reply with quote Back to top
hooloovoo
PostPosted: Aug 12, 2006 - 11:42 PM
Rookie


Joined: Jun 16, 2006
Posts: 21


By "ISP clock" do you mean the clock on the SCK pin?
 
 View user's profile Send private message  
Reply with quote Back to top
abcminiuser
PostPosted: Aug 13, 2006 - 03:11 AM
Moderator


Joined: Jan 23, 2004
Posts: 6964
Location: Melbourne, Victoria, Australia

hooloovoo wrote:
By "ISP clock" do you mean the clock on the SCK pin?


Yes indeed. If your AVR is running at a speed of 1MHz, the maximum SPI speed (SCK) is one quarter of that, 250KHz.

- Dean Twisted Evil

_________________

 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
ciroque
PostPosted: Aug 13, 2006 - 03:28 AM
Hangaround


Joined: Jun 21, 2006
Posts: 239
Location: Seattle, WA

Good deal, thanks!

I was *comfortable* with all but the JTAG stuff, you have verified for me what I thought I knew and added the JTAG knowledge.

Thanks again!
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
ThanhTran
PostPosted: Sep 09, 2006 - 12:51 AM
Newbie


Joined: Apr 25, 2006
Posts: 18


Thank you for the excellent tutorial. I'm just starting out with AVR after working with Microchip PIC chips a little. I still have a question after reading your tutorial. Pardon me if it's been posted somewhere in these forums. Says if I pick the ISP method of programming, does the target AVR have to have power and xtal connected before it could be programmed? With some PIC's that I've been working with, I just need to connect a few wires (5) to the pins of the bare chip to program it. Power to the chip was taken from the programmer (serial JDM programmer). The PIC doenst need an Xtal. I wonder if its the case with AVR?


Thanks

Thanh
 
 View user's profile Send private message  
Reply with quote Back to top
abcminiuser
PostPosted: Sep 09, 2006 - 01:03 AM
Moderator


Joined: Jan 23, 2004
Posts: 6964
Location: Melbourne, Victoria, Australia

It depends. AVRs DO need both a clock source and a power source, but in the case of the former the more modern AVRs have an internal clock source which is enabled via default (making power the only external item to be connected other than the programmer).

Older 90S series AVRs do not have an internal clock source, and so will need an external crystal to run. If you're using an AVR with an internal clock, it is enabled via default (from the factory) and usually runs at about 1MHz - this means that you should try ISP programming at 250KHz or less to start with.

- Dean Twisted Evil

_________________

 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
ThanhTran
PostPosted: Sep 09, 2006 - 11:12 AM
Newbie


Joined: Apr 25, 2006
Posts: 18


Thanks very much for the information Dean!

Thanh
 
 View user's profile Send private message  
Reply with quote Back to top
jidan1
PostPosted: Sep 28, 2006 - 12:38 AM
Wannabe


Joined: May 21, 2006
Posts: 66


Great tutorial! Thank you...
 
 View user's profile Send private message  
Reply with quote Back to top
praveen_cpp
PostPosted: Nov 29, 2006 - 03:58 AM
Newbie


Joined: Apr 13, 2006
Posts: 9


thanks a lot.

praveen
 
 View user's profile Send private message  
Reply with quote Back to top
MR BLONDE
PostPosted: Nov 29, 2006 - 10:37 PM
Hangaround


Joined: May 13, 2004
Posts: 328
Location: north west uk

very useful information
thank you

mr blonde

_________________
Codevisionavr & Avrstudio 4.12
Easyavr4-STK500/200-Butterfly-ETbase128-Jtagicemk1

Two things stand between ignorance and knowledge ,time and dedication Wink
 
 View user's profile Send private message  
Reply with quote Back to top
jimbraden
PostPosted: Nov 30, 2006 - 08:27 PM
Newbie


Joined: Oct 01, 2003
Posts: 1


Good memo Dean.

It appears you have kept this information up to data because you included the newly released Dragon board.

A question I have had for several months now is how do you use the debug wire to program the AVR?

Regards,
Jim Braden
 
 View user's profile Send private message  
Reply with quote Back to top
abcminiuser
PostPosted: Dec 01, 2006 - 02:21 AM
Moderator


Joined: Jan 23, 2004
Posts: 6964
Location: Melbourne, Victoria, Australia

I appreciate all the above messages of thanks, it validates my work Smile.

jimbraden: I do indeed try to keep it updated. I should probably include dW as well, although it really is meant purely for debugging rather than for programming.

dW requires a JTAG-MKII, or a Dragon. To use dW, you first connect the JTAG to the target in a configuration that allows for normal ISP programming. Once done, you can then tell the IDE to send the commands via ISP to enable the DWEN (dW ENable) fuse to start the session.

One the session has started, you can program the device by starting a debug session. This will program the target and allow you to view the internal chip status at any point in time.

dW remains active until the session is closed by turning off the DWEN fuse. This means that you can program the AVR via a dW session, then close the session to leave the code in the target.

Leaving a dW session unclosed in a production device is VERY unwise, as it disables the /RESET pin functionality.

- Dean Twisted Evil

_________________

 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
lfmorrison
PostPosted: Dec 01, 2006 - 12:50 PM
Raving lunatic


Joined: Dec 08, 2004
Posts: 4493
Location: Nova Scotia, Canada

Another limitation of debugWire is that it prevents certain system clocks from ever being disabled, even if the part is placed into a deep sleep mode. That will increase power consumption. debugWire uses the same clock as the SPI module; if your software attempts to save power by disabling the SPI clock using PRR, then the debugWire interface will lock up. As well, I haven't seen any hard evidence about how effective the memory protection lock bits are while the debugWire interface is enabled.

I guess it's appropriate to mention debugWire as a programming interface. But it should always be included with a huge caveat: Its limitations make it inappropriate to use as a general-purpose programmer for production purposes!

In order to get the chip back into a fully functional state, you must disable the debugWire fuse; In order to disable the debugWire fuse, you must have a full-up ISP connection (reset/sck/mosi/miso); All ICE units which support debugWire (Dragon, JTAGICE mkII) can also be used as general-purpose ISP programmers; If you have the full-up ISP connection in place already, then you're better off using the ISP connection for the production programming in the first place because it is more reliable, probably faster, and allows modification of all fuse/lock bits.
 
 View user's profile Send private message  
Reply with quote Back to top
Giberish
PostPosted: Dec 31, 2006 - 12:47 AM
Newbie


Joined: Dec 25, 2006
Posts: 3


Hi. I have been searching for the longest time for a tutorial such as this to get me started. Thank you very much.

However, I have a question about the DB-25 connections. I have been looking at other websites and found that there are many different layouts as in which pins are used.

http://www.bsdhome.com/avrdude/
uses pin 7-10, 18

http://www.instructables.com/id/E5H5UDW ... /?ALLSTEPS
uses pin 1,2,11,16,18

http://elm-chan.org/works/avrx/report_e.html (while it was working which is just a few days ago)
uses pin 2-4,11,18

I am wondering which one will work with AVRStudio 4. Could someone help me out here?

Many thanks,
Ken
 
 View user's profile Send private message  
Reply with quote Back to top
abcminiuser
PostPosted: Dec 31, 2006 - 12:53 AM
Moderator


Joined: Jan 23, 2004
Posts: 6964
Location: Melbourne, Victoria, Australia

None of them.

AVRStudio does not support Parallel Programming dongles. It has limited support for serial "AVR910" programmers, but it's designed for the official Atmel AVRISP/Dragon/STK500/JTAG systems.

All the dongles are different since there are several IO lines in the parallel port connector, yet only a few are needed for the ISP signals. Whichever one you choose to make, you need to configure your third party programming software (eg AVRDude) up the same way for it to work.

EDIT: Added in a new FAQ section to the original post. If you want a question addressed in that FAQ, post it here!

- Dean Twisted Evil

_________________

 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits