Skip to content

Programming an ATMega With No Bootloader Using the USBtinyISP

2011 August 14

The title says it all: for my “Deconspectrum” installation, I am burning a program onto a bunch of ATMega328 chips using a USBtinyISP (In-System Programmer).  At first I was running into a perplexing problem: the program was running much slower than it should have been.  I could tell immediately because I had a short POST (Power-On Self Test) at the beginning of the program that flashes the LED Red-Green-Blue, and it was going far slower than it should have been.

My first thought was that there was a problem with the ATMega “fuses,” which are just settings for various esoteric details of the chip’s functioning, including clock rate.  But I had never had to bother with them before.  Then I made a further discovery that the only time the program ran correctly was if I installed the Arduino bootloader first and uploaded the program using it.  What gives?

Thanks to the plucky denizens of the ITP Physical Computing list, I learned that indeed, it was a matter of fuses—the Arduino IDE apparently only sets the correct fuses when burning the bootloader, not when burning a program directly using an ISP.

The solution: use avrdude, the program that Arduino uses to actually program the chip behind the scenes, directly.  This turned out to not only solve my problem, but to make the programming process much faster and simpler.  Avrdude takes a “hex” file as an input to transfer to the chip, which is the compiled bytecode that the ATMega actually runs.  This way, I only have to compile the program once, and burn it directly—and since I’m programming about 40 chips, this makes things far faster.

All you need to do is get the AVR “CrossPack” installed (for OSX; for Windows you can use AVR Studio or a number of other packages) and then find your hex file.  In the Arduino IDE, hold Shift while pressing the “Verify” button to produce a verbose debug output.  In there you’ll see a path like this:

/var/folders/9t/7qf1680d2pqgd0hy6qbfkqsr0000gn/T/build5025172614724793636.tmp/myProgram.cpp.hex

You can then copy that file to your project directory:

cp /var/folders/.../myProgram.cpp.hex ~/Projects/myProject/myProgram.cpp.hex

And program your chip like so:

avrdude -c usbtiny -p m328p -b 57600 -U flash:w:myProgram.cpp.hex:i -U efuse:w:0x05:m -U hfuse:w:0xde:m -U lfuse:w:0xff:m

Those settings are for the ATMega328; for the 168 use:

-p m168

To get a list of parts, type:

avrdude -c avrisp

And there you have it! You’ll find that this saves a lot of time if you have to program lots of chips. Besides, not using the Arduino bootloader will save a little space on your chip 😉

Related Posts:


3 Responses leave one →
  1. Anandopaul permalink
    February 15, 2012

    Can you please tell me how to program atmega32a using avrdude -c usbtiny ….. what should be the -p option input ? m32 not working … any suggestion ? 

    • Ted Hayes permalink
      February 15, 2012

      Hm, if -p m32 doesn’t work (nor, presumably, m32a), then I’m really not sure; I’m not familiar with that part…

Trackbacks and Pingbacks

  1. Writing AtMegas without bootloader | Yet Another Technology Blog

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS