AVR Programming 02: The Hardware

You may be able to write the most eloquent code in the history of embedded systems but without a way to run it on the hardware it will be worthless. In this installment of the tutorial series we will:

  • Look at some of the available AVR programmer options
  • Place the microcontroller on a breadboard and connect it to a power supply and a programmer.
  • Use programming software to send some example code to the microcontroller

If you missed Part 1 take a few minutes to review that portion of the tutorial and then join us after the break.

Series roadmap:

Programmers

As I said before, if you want to get it on the chip you’ve got to have a programmer. There are a huge number of options, but I’ll cover a few of the easiest and least expensive. We are focusing on In-System Programming (ISP) which means that you can program the chip without removing it from the circuit.

DAPA Cable

A Direct AVR Parallel Access, or DAPA cable, is an incredibly simple and cheap programming method. You can build one very quickly for a few bucks worth of parts, but the convenience comes with a few gotchas. The first is that you must have a parallel port on your computer; something that modern laptop and some modern desktops don’t have. But if you’ve got an old PC around that has one this will get you up and programming in no time.

In fact, the first AVR prototyping I did was with one of these cables. That is, until I discovered another gotcha. This will only program low-speed chips. If you try to run the chip’s clock at full speed (by changing fuse settings… more in Part 3) you won’t be able to use a DAPA cable to talk to it any longer. There’s also the possibility of damaging your parallel port or worse if you do something wrong. But if you want to go for it anyway, here’s how I built mine.

It connects to a computer using a DB25 connector. As you can see in the schematic, I’ve used 1 kilo Ohm resistors on the Reset, SCK, MISO, and MOSI pins for current protection. I did not use a resistor on the ground pin. I used a piece of ribbon cable, soldering one end to each of the five signal lines shown in the schematic. On the other end of the ribbon cable I used a connector housing with six slots, filling one of them with a blank so that I could keep track of the signals. This is easy to plug into a pin header or connect to jumper wires as shown above. In retrospect it may have been a better choice to use a 2×3 IDC connector and route the signals using the AVR ISP standard (from AVR: In-System Programming PDF). If you go this route chances are you’ll upgrade before long so don’t agonize of the design details.

Arduino


I would be remiss to skip over using an Arduino as a programmer. They’re ubiquitous with the embedded systems crowd and if you don’t already own one, you can try to find someone to lend you theirs for a little while. All that is required is to write an AVR programmer sketch to the Arduino and make the programming connections. We’ll take a look at this method later in the post.

USBtinyISP


The USBtinyISP is an In-System-Programmer based around an ATtiny2313 that uses a USB connection (see where the name comes from?). It isn’t a bad choice for your first programmer. If you are confident in your skills you can build the circuit circuit yourself and use a DAPA cable to get the programming firmware onto the chip. Or you can just buy it from Adafruit Industries. But if you think you’re going to be serious about AVR development, you should consider shelling out the extra bucks for a professional programmer.

Professional programmers


The Ateml programmers are the gold standard. They offer something that none of the other hardware we’ve covered has, the ability to recover a chip that you’ve messed up. If you want to use the reset pin as I/O, you will need to use High Voltage Parallel Programming to talk to your chip. Even if you don’t decide to do that, at some point you’re going to screw up and you’ll need to recover a process, which helps offset the extra cost of a professional programmer. It is possible to use an Arduino for High Voltage Parallel Programming to recover your AVR, but that’s another hack in itself.

We use an AVR Dragon for pretty much everything. But the STK500 is a very popular board even though you need a serial port to use it. It has chip sockets, buttons, and LEDs for on-board prototyping. The Dragon leaves options open with unpopulated socket footprints, and it uses a USB connection.

If you’re in this for the long haul there’s no substitute for one of these choices.

We should at least mention the MKII, a programmer that offers ISP in the same way that the USBtinyISP does, but also provides JTAG, debug wire, and few others. We have no experience with this unit so you’ll have to do your own research if you’d like to know more. As for the other programmers out there, use Google or check the comments to this post as people usually don’t like to keep their preferred programmer choice a secret.

Bootloader

A bootloader is not really a programmer, but a way to get around using one. A bootloader is a set of code already on your microprocessor. It handles basic input and output neccessary to write your code into the chip’s memory. The bad news is that they do take up programming space, but you won’t have to buy a hardware programmer.

Programming a chip with a bootloader on it is beyond the scope of this tutorial. But it’s not hard to learn to do. In fact, this is how it is possible to program an Arduino without a separate hardware programmer.

Setting up our test circuit

Enough talk, let’s build something! We need four things: A microcontroller, something to power it, some way to program it, and something to show us it’s working.

Hardware:

  • Solderless breadboard
  • Jumper wires
  • ATmega168 microcontroller
  • 78L05 voltage regulator
  • 100uf electrolytic capacitor
  • 10uf electrolytic capacitor
  • LED
  • 180 Ohm resistor (any resistor between 180 and 330 Ohms will work fine)
  • A programmer (we’ll show both a DAPA and an Arduino)

What we’re doing

In a  nutshell, we’re going to blink an LED as our first embedded program.  This takes a few components: a power supply, the microcontroller itself, and the LED and its current limiting resistor.

The power supply consists of a voltage regulator which will take an input voltage above 7v and output a constant voltage of 5V. In order to work correctly, this circuit requires two filtering capacitors. The capacitors act like storage tanks, absorbing small fluctuations on the power rail to provide a steady source of electricity to keep our microcontroller safe and happy.

As an output we are going to use an LED. We must include a resistor to limit the amount of current that will flow when the software lights it up. Without this current limiting resistor, current would flow at levels that are unsafe for the LED, the microcontroller, or both.

The circuit schematic

Above is the circuit we are using as an example. The a simple 5v regulator circuit using an LM7805 linear regulator and two filtering capacitors is on the left, separated from the rest by a dotted box. If you already have some type of regulated 5v supply save yourself some time and use that.

You may also notice that the chip in the schematic is labelled AVR-MEGA8. The ATmega168 that we’re using is pin-compatible with at ATmega8. That means that you can swap one for the other and all 28 pins will be where they’re supposed to be, so this will cause no issue.

It is a good practice to add a few components not seen here. There should be two 0.1 uF capacitors for decoupling; they filter out fluctuations on the power rails called noise. One between VCC and GND, the other between AVCC and AGND (as close as possible to the pins). There should also be a pull-up resistor on the reset pin with lets an incredibly small amount of current trickle into the pin at a 5V level. This the chip from resetting by accident when it’s floating (not connected so there’s no clear 0 or 5V value). I’ve omitted these parts for simplicity and it shouldn’t be an issue with this simple project. But as your projects get more complicated, neglecting these considerations will come back to bite you.

The circuit built on a breadboard

I started building the circuit by adding the voltage regulator to the breadboard. Then connect the ground leg to the ground rail on top of your breadboard, and the output leg to the voltage rail of your breadboard. I have also added two wires that I will eventually connect to the positive and negative terminals of a 9V battery.

It is important to read the datasheet for your voltage regulator (example: LM7805) to figure out which lead is input, ground, and output. Your regulator may look different from mine as they do come in different packages. In the image above, the input lead is on the left, the ground is in the middle, and the output lead is to the right.

Now I’ve completed the power supply by adding the 100 uF capacitor between the input leg and ground leg of the regulator, and the 10 uF capacitor between the output leg and ground leg. Pay careful attention to these capacitors, one lead should be marked as negative (a band with a minus sign) on the case of each capacitor. Before adding the microcontroller it would be a good idea to check the voltage output using a multimeter. Too much juice can destroy your new chip.

After checking to make sure I had a steady 5V source, then disconnecting the battery, I added the ATmega168 microcontroller to the board. Note that the dimple is pointing to the left. This is important, as the standard orientation and lead numbering of a DIP package shows that pin 1 is now on the lower left, letting us easily find the other pins that we need.

Power and ground have been connected to the chip as well. Pin 7 (VCC) and Pin 20 (AVCC) have been connected to 5V. Pin 8 (GND) and Pin 22 (AGND) have both been connected to ground.

The final step is to connect the LED to output 0 on Port D. Our schematic tell us that we want to connect the positive lead of the LED to Pin 2 on the ATmega168, and the negative lead should go to an unoccupied row on the breadboard (make sure you don’t attach it to Pin 1). LEDs usually have a small notch flattened on one side of the plastic case to denote the negative leg of the device. The final piece of the puzzle is to connect the negative side of the LED to ground by using our resistor.

In the image above I’ve hooked up a 9V battery , but nothing happened. That’s because there’s no firmware on the chip to make the LED blink yet. We’ll need to fix that in the next step.

Programming our test circuit

Check all of your connections one more time and let’s get ready to program the microcontroller.

Connecting to a programmer

You only need to make six connections in order to program our chip:

  • Voltage
  • Ground
  • Master In Slave Out (MISO)
  • Master Out Slave In (MOSI)
  • Reset (RST)
  • Slave Clock (SCK)

This is true for any programmer that is using In-System Programming. There’s even a standardized 6-pin header that I design into most of my circuits so that you can easily reconnect your programmer to a circuit board and update the firmware down the line. But for this example we’ll just use some jumper wires to make the connections. One thing to keep in the back of your mind is to only use one voltage source when programming. You should either disconnect the power to your circuit while programming, or do not make a connection to the voltage line on your programmer.

Connecting an Arduino as a programmer

Using your Arduino as a programmer is super easy. The first thing you’ll want to do is open up the Arduino IDE, and then open the example software: ArduinoISP.pde (in the examples/ArduinoISP folder). Flash it to your Arduino in the normal fashion. Now follow the directions for targeting an AVR on a breadboard (bottom of that page). Important: Choose one power source. That is to say, either connect the voltage on the Arduino board to your breadboard, OR connect the battery to the power supply we wired up. Doing both has the potential to damage your hardware.

Here’s how mine looked once I had it hooked up.

Now that everything is ready to go, jump to the next section: Flashing firmware with AVRdude.

Connecting using a DAPA cable

Depending on how you constructed your DAPA cable, it should be pretty easy to make the five connections we need. Notice that the DAPA cable doesn’t have a Voltage connection. The target processor must have its own power source (like the power supply we built on the breadboard) during programming. Here is what my DAPA cable looks like once connected.

If you’re unsure of the connection that need to be made, go back and compare the DAPA cable design to the circuit schematic. Match up our five connections: MISO, MOSI, RST, SCK, and GND.

Flashing firmware with AVRdude

If you did your homework from Part 1 of this series you should already have the cross compiler tools installed. First, download the firmware package and navigate to that directory in a shell, or at the command prompt. The following commands can be used on Linux and OSX systems to program the chip.

Arduino as the programmer:

avrdude -P usb -b 19200 -c avrisp -p m168 -U flash:w:main.hex

DAPA as the programmer:

avrdude -P /dev/parport0 -c dapa -p m168 -U flash:w:main.hex

AVR Dragon as the programmer:

avrdude -P usb -c dragon_isp -p m168 -U flash:w:main.hex

USBtinyISP as the programmer:

avrdude -P usb -c usbtiny -p m168 -U flash:w:main.hex

You can get help from the AVRdude program by running:

avrdude -h

That will print out a list of available commands, or you can read the online documentation. Windows users will need to change the /dev/* portion of the command to match your connection. You should find the Windows page of the online manual particularly helpful for this. Standard Windows port names include com0, com1, etc. for serial ports and lpt0, lpt1, etc. for parallel ports.

As for the other flags used in the programming commands above:

When using the Arduino as an ISP programmer you must specify the speed, using ‘-b’. That value is set in the Arduino sketch and should be 19200 by default.

You will always need to specify what kind of chip is connected to the programmer. Here I’ve used ‘-p m168’ for our ATmega168. Get a list of all compatible microprocessors by typing

avrdude -p ?

The same is true for specifying a programmer. You can change the ‘-p’ to ‘-c’ in the command above to get a list of programmers.

The final option in the commands we used tells the programmer to write (that’s the ‘w’) the file ‘main.hex’ to flash memory. Part of the command is used for many things, including changing the fuse bits on the chip. I’ll talk about this in Part 3 of the series.

Debugging

Your LED should be flashing away quite happily at this point. What’s that? It’s not? Time to start the real learning. Here’s a list to get you started:

  • Did you successfully program the chip? You should get the message: “258 bytes of flash verified” and “avrdude done. Thank you.”
  • If you had an error during programming, check first to make sure there is power going to your chip.
  • Try the programming command again using ‘-v’ in place of ‘flash:w:main.hex’. This will just attempt to talk to the chip instead of writing to it, and is very handy when working out programming bugs
  • Recheck your programming connections to ensure you’ve got the correct signals connected to the right pins
  • Make sure you have the correct port on the computer and that you have permission to use that port. Linux users may try talking to the chip with the -v flag as ROOT to discover if there is a permission problem. If this works you need to add your user to the group that has permission to access the port the programmer is connected to
  • If you did successfully program the chip you should recheck your hardware. Is the LED installed backwards, preventing it from lighting up?
  • Take a trip to Google and start searching… this usually plays a roll in the development process so don’t feel bad. A lot of folks have already experienced the trouble you’re having and they made it through okay in the end.

Conclusion

You’ve done it, your first embedded circuit is alive! For now it will just flash to let you know everything is working. But next time we’ll talk about how this was accomplished, what we can do to make it behave differently, and how to use the compiler to translate our code changes into a file that the microcontroller can run. Thanks for reading and we’ll see you back here for the next installment.

Follow Me

@szczys

Resources

Firmware package: Package download or Github page

Atmel AVR ATmega168 Datasheet (PDF)

AVR dude online documentation

AVR In-System Programming Application Note (PDF)

AVR ISP Programming Header:

67 thoughts on “AVR Programming 02: The Hardware

  1. I’d recommend the USBasp as a programming solution. It was the first programmer I built and I still use it for programing avrs. The downside is that you already need to get your hands on a programmer to flash your own programmer with the firmware.

  2. The only thing I would also mention is if you ever go to the Xmega avr chips then the TinyISP wont work for programming them. Avrdude supports the PDI programming method that these uC’s use. However you need to use something like the AVRISP MKII ($30) mouser. Also to note is there are many clones floating around which prolly will do fine. However if you get the Atmel ones they get firmware updates etc from avrstudio (windows only).

    -ril3y

  3. I haven’t worked with the Atmel AVR since 2006 or so, but the in-circuit debuggers are worth every penny if your time has any value.

    That means the AVRdragon or the MKII (along with the STK500 if you need a dev board to get started), or maybe the equivalents from Olimex.

    Everything else above is greasy kid stuff. If your time is worth money, being able to recover a chip you’ve locked is not a “nice-to-have” or something you spend weeks on a science fair project to do yourself with an Arduino, for example.

  4. Looking at Digikey to purchase the components and am overwhelmed with the variety of different options available for the capacitors and resistors and such. (Is there a better site?)

    Can you provide more detailed information on the components? Please include the pull-up resistor values as well as the decoupling caps.

    Should I purchase more of these components for future projects/tutorials? I figure that I might as well save on shipping costs and purchase everything at once.

  5. So the Atmel chips are SPI, low voltage programmable from the factory? That sounds awesome. Does it use actual SPI, or is there a difference? Sounds like you should be able to program one from a different kind of device, like a bus pirate or and MSP430 in spi mode >:D

    Microchip could learn from them. The need to program with a High Voltage programmer before you can use a low voltage one is stupid.

  6. @Mike Szczys,

    This is great, but you are driving me a bit mad with using Red wire for the AGND & VCC; and Green for AVCC & GND. Why not stick with Red wires for any positive voltage and Green for ground?

    For the newbie to electronics, mixing up the colors may add to the headaches.

    Also, showing the VCC connecting to AVCC and GND to AGND may help too.

    If you decide to swap out the wires so the colors match, feel free to delete this post as it won’t be relevant anymore.

    Thanks for everything!

  7. Kendall

    For most basic components (resistors capacitors diodes transistors) I would recommend to the beginner to get a fair supply by buying bulk assortments from surplus outlets. All electronics, Skycraft etc. You should also look for local surplus electronics. When I lived in Ohio We had Debco in Cincinnati and Mendelsons in Dayton.

    This is especially true for resistors as they are cheap.
    To get your lab started:

    Get a bag/box of 1/4 W through hole type assortment of resistors.

    Ditto for ceramic capacitors.

    A few good electrolytic caps of small often used values.

    Transistors such as N2222, 3904/3906 etc in TO-92 packages are cheap and used a lot

    Diodes 1n4001-4003 (rectifier) 1n914(switching) 1n58xx(shottkey)

    Voltage regulators 7905(5v) etc LM317(adjustable)

    Some assorted op-amps if you can find them cheap.

    Some 555’s and some CMOS 555’s for inverters!

    Large caps IC’s and such I buy as needed but usually buy extra if I find a deal.

    Inductors I usually buy as needed unless I find some good ones I like for cheap then I stock up. Sometimes I make my own.

    I can’t tell you how many times a project has been held up because I didn’t have a component and had to order and wait. As your supplies grow this becomes less of an issue. Fortunately for us electronics guys our parts are tiny so storage isn’t a problem.

    Hope this helps

  8. @cde, yes all(except really small ones) are SPI programmable at low voltage. The good thing is that all chips have spi. And yes, you could program a device from something else. In fact, i know somebody who does this.
    You only need to use high voltage/parallel programmer if you disable the spi programming ability. A while ago you had to set the enable on the fuse each time you programmed the device, and people forgot and disabled it. Now most programming software puts it automatically so you don’t have to worry.
    @Brent is very correct. One should have some sort of debugging tool.

    @everyone, the usbasp is a good programmer, i do recommend it too.

    Good luck!

  9. @Kendall: You’re right… selecting parts can be quite overwhelming. Know this: there’s a lot of wiggle room for most of these parts. In fact the datasheet for the voltage regulator recommends different capacitor values than I use but you’ll see that 100uf and 10uf are pretty common in power supply design like this one.

    As for pull-up resistors and decoupling capacitors. I usually use 4k7 (that’s 4700) ohm resistors as pull-ups. I use 0.1uF capacitors for decoupling and I’d recommend getting at lot of these (at least 25 at a time). You need them for pretty much ever IC you use. So if you have 3 I2C devices that you’re hooking up in a project you’ll probably need at least one for each of those chips.

    Maybe we need to do a tutorial on choosing parts… for now search around and see if someone else has already written one.

  10. Oh, I almost forgot

    Crystals! When I order say some AVR’s from digikey I’ll order the crystals at the same time. I know I’m going to run them at X MHz so I’ll get them. I also have a few of the “magic numbers” for RS232 communications.

    Good suggestion from Mike Szczys for the decoupling caps. Decoupling is something beginners often forget that will cause headaches. like leaving a reset pin unconnected(I have never done that)

  11. Good article. I highly recommend the AVR ISP MkII though. It’s relatively inexpensive, premade, works very well, and has a couple status LED’s to at least let you know what might be going on at times when something wont run (as long as it’s programmer related)
    One really doesn’t need a debugging platform, I haven’t ever used one. Though it might help solve a few headaches sometimes.

  12. With arduino, would it be possible to just remove the chip from the board, and insert another one (with a preloaded bootloader) to program it with your code?

    I already have a Duemilanove, but I want to buy an RBBB, and was wondering if it’s possible to use the Duemilanove to program the RBBB’s chip.

  13. Meh, sort of nice article but no mention of using an FTDI breakout/cable as an ISP programmer :/ Same method can be used to program *ANY* atmega chip via an arduino and the X3 pin header.

  14. First off, this is a great tutorial series, I cannot wait until part 3.

    Second, can anyone point me to a tutorial that covers the finer points of power supply design? Like choosing a regulator and filter caps.

    Third, Kepler, you usually write the code in another IDE and compile it using avr-gcc (I think), but to get a .hex from arduino:
    1.) Make sure that you’ve set the board (Tools -> Board) to something matching your AVR.
    2.) Load up your sketch and, while holding down the SHIFT key, press the play button at the top of the Arduino IDE.
    3.) Look in the output pane at the bottom of the IDE. One of the last few lines should be something like ‘/var/folders/qg/qg3jOUWGFLCJ6ikojIjVHk+++TI/-Tmp-/build1478307508853060821.tmp/ArduinoISP.cpp.hex ‘. This is your .hex file!

  15. I have the AVR MkII programmer/debugger. Though the article above only makes cursory mention of it, I can tell you that it’s the cadillac of programmers and costs similarly. It’s probably the most expensive option out there, but the cost is easily offset by the fact that it does *everything*. It comes with adapters for in-system-programming, JTAG, a replacement connection cable, and some very terse instructions on what all the little doo-dads in the box are for. One thing that I appreciated was that it came with a ribbon cable break-out adapter that allows you to connect to your programming pins even if they aren’t even located near each other. For instance, you can have separate test pins located all over your project for reset, miso, gnd, mosi, etc and they don’t have to be in a 2×3 6-pin header. Sometimes this makes board layout much easier at the expense of having to carefully connect up each individual pin. Furthermore, the height of some nearby components sometimes interferes with connecting the standard ISP connector (d’oh!), so this gives you a way to work around that limitation.

    Overall, if you can afford it (about $300 or so), I would highly recommend it. There’s no substitute for being able to actually debug your program via JTAG on the actual hardware, imho.

  16. You should use a 100nF ceramic capacitor between the VCC an GND lines. Always! Even in a breadboard design. I know, in most cases it’ll still work, but leaving them out can cause unpredictable errors, which can be frustrating to debug.

  17. @mk: If you program an AVR while it’s running at 16MHz, and then place it in a board where it runs, say, 8MHz, it may not run as designed. As long as both boards are running at the same speed, things should work out fine.

    And don’t worry about being a ‘newb’. Everyone has to start somewhere. I know what I know because I asked, and the people I asked learned from their own experiments and research, or by asking others.

  18. Might be good to cover the concepts of sink and source to the tutorial . People need to know the difference and what it means before they start connecting anything more than LED to pins. People just starting that confuse the sink/source meanings have destroyed quite a few ic over the years.

    For parts I would add , the 741 op amp, cheap and versatile. CD4011 – lots can be done with these, 2N4891 UJT is a good part to have to or another UJT. All sorts of things can be made with them.

  19. I got it working at one point, and then tried to reconfigure a few things and I messed it up.

    Is it normal to have a few retries when it’s writing to the flash memory? I’m using the USBTinyISP, the first time it fails writing, it says that the pipe is stalled, then I get “1 retries during SPI command” a few times and then finally the writing goes to 100%.

    I’ve broken it down and put it back together and now I get a verification error: first mismatch at byte 0x0000 0x0c != 0x04.

    I had this working great at one point, but I can’t figure out where I went wrong.

    Thanks,
    Matt

  20. @ Mike Szczys

    Thanks for this great series, I’m a long time programmer, and this was just the thing to get me to try embedded stuff.

    Just one issue with the post from my experience while following the
    directions to the T. Im using an intel imac w/ snow leopard, and an avr dragon.

    When connecting the ISP header from the dragon to the chip, you MUST connect the VCC line. Otherwise the dragon responds that the target isn’t powered up. It uses the VCC line to measure and see if it has the correct voltage.

    Other than that thanks so much for the series, can’t wait for the next bit, I’ve already gone ahead but I definitely will check back for part three.

  21. I’m having a problem. I’m trying to use the arduino as the isp, and when I type the command given above, I get an error saying “ser_open(): can’t open device “usb”: the system cannot find the file specified”

  22. I spent a whole evening on debugging the thing, even running avrdude reallly slow with -vvvv -i 10000 and LEDs on the data lines to see what’s going on.

    I just couldn’t get the PC to read back the data from the chip, until I finally went to the BIOS settings and changed the printer port mode from ECP+EPP to SPP, and then it worked.

    To test this condition, short MISO and MOSI together and see if avrdude gets the same thing back as it’s sending. If it sees just FF or 00 it might be your printer port.

  23. Hi, thanks for awesome article! I always thought this kind of stuff was way to complicated for me but you make it sound quite straightforward.
    Though i have a noob question:
    I looked up ATMEGA168 on the web of the store closest to me and I saw they have three versions:
    ATMEGA168-20AU, ATMEGA168V-10AU and ATMEGA168-20PU.
    The only difference in the description is that the first two are “TQFP-32” while the third is “DIL28”, which means nothing to me. Does it matter which one i get?
    Cheers!

  24. To Haluzak,
    DIL = Dual In-Line. Synonymous with DIP (Dual In-Line Package). This is the one you want. It means it has through hole (sometimes noted as T/H or THT{through hole technology). The others are surface mount packages (SMT or SMD).

    The -10 or -20 are just the max speed in MHz the chip can perform at.

    http://tinyurl.com/28hezpf
    Ask for USPS shipping as it weighs next to nothing.

  25. hello,

    i have made the parallel port programmer ,connected the circuit as shown .i have also installed winavr on windows xp but i don’t know how to compile and download the file on to the device…. i had tried to use pony prog to download the file onto the chip from the main.hex file given in the part 2 files and also tried making the parallel port as ecp in bios settings

  26. having problems :-(

    I’m using an AVR Dragon on OSX.. I checked the connections and pins 10 times… I’m getting the following error:

    avrdude: Device signature = 0x000000
    avrdude: Yikes! Invalid device signature.
    Double check connections and try again, or use -F to override this check.

    NOTE: I’m using a 328 instead.. but I checked the datasheet and the pinout is the same… Any advise?

    Here is a screenshot of my terminal output and my wiring

    Terminal Screenshot:
    http://itslennysfault.com/stuff/AVRIssue.png

    wiring photo:
    http://itslennysfault.com/stuff/AVRIssueWires.jpg

    Also, to further test the wiring I tried disconnecting the VCC wire from the ribbon cable and I got this error.. which seems to say it’s hooked up correctly (in my mind)?
    http://itslennysfault.com/stuff/AVRIssue.png

    Any help would be GREATLY appreciated.. thanks

    1. If you are working with a “new” ATmega328, the factory default fuse settings are for the internal 8MHz oscilator with a divide by 8 prescaler, making your MCU clock 1MHz. You’ll need to use a lower bitrate with the AVR DRAGON and AVRDUDE. Try this:

      avrdude -p m328p -c dragon_isp -B 200kHz -U flash:w:[file_name].hex

      The “kHz” IS CASE SENSITIVE.

      You’ll need to reprogram the fuses for a “new” ATmega328,. To set them to be “ARDUINO compatible”, use AVRDUDE with your AVR DRAGON (or USBtiny or USBASP, etc.) like this:

      avrdude -p m328p -c dragon_isp -B 200kHz -U lfuse:w:0xff:m -U hfuse:w:0xda:m -U efuse:w:0x05:m

      I have an AVR DRAGON and have been using it since about 2006. It’s great for programming and debugging via DEBUG-WIRE or JTAG. JTAG is much faster to debug with and DEBUGWIRE has left my ATmega48/88/168/328’s in a state of being unable to program via ISP because DEBUGWIRE disables the SPI interface. AVR STUDIO resets it when the debugging session is ended but sometimes AVR STUDIO crashes and leaves the MCU with BOTH SPI and DEBUGWIRE interface disabled. That’s when HVPP (or HVSP for ATtiny85, etc.) comes to the rescue.

      If the SPI interface is disabled and the DEBUGWIRE interface is still enabled, newer versions of AVRDUDE will recognize this and TEMPORARILY switch to DEBUGWIRE mode to program so that you can reprogram the fuses. A good source for an online AVR fuse calculator is http://www.engbedded.com/fusecalc

      I trust this is helpful.

      Peace and blessings,
      Johnny Quest (and Bandit)

Leave a Reply to ril3yCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.