Making a USB based AVR Programmer

Monday, March 29, 2010
Around time when I was beginning to learn about microcontrollers I had exchanged my laptop with a senior at college for his desktop - that's because the only way I knew how to program an ATMEGA chip was through either a serial port or a parallel port. USB programmers were not available widely and were generally thought to be expensive. The programming setup using a parallel port was very simple. I followed the DAPA programmer for my needs for some time. Here is a pic of the setup - ATMEGA8 chip on breadboard (pinouts matched against the one shown in above link), a parallel port DB25 connector and a USB cable that just to get 5V and GND quick and dirtly without any batteries and voltage regulators:


Over the time I learned about an inexpensive way of making a USB based AVR programmer called USBasp. It's faster, cheaper and has the convenience of letting you program AVRs from laptops. Here is a pic of the first USBasp programmer that I built, and promptly got my laptop back (in the link you can see more designs):


Plugging it into the laptop and seeing it get recognized was pure fun! Having it work right also meant that you could get it to a competition venue easily, in case you had to program the microcontroller again. Without this the only other way was to bring along a desktop which was just impractical. I can recall once at the IIT Techfest I had found a team bring a really old laptop which did have a parallel port and those folks were programming their chips on the spot and it just didn't feel fair for the rest of us... heh heh! I used this one for a long time, even took it to workshops at college and many came from time to time to get their microcontrollers programmed. Right now the one in the pic is with a friend who is using it for the project work at college. And here is another one that I built yesterday:


Looks neat, doesn't it! But making it wasn't hassle free this time. I started with programming an ATMEGA8 needed for the USBasp with DAPA programmer like the one in the first pic (except for I was not using an external crystal). Having written the USBasp firmware on the chip, I proceeded to program fuses (they need to be done for using the 12 MHz external crystal). One fuse byte got written and then the chip lost sync with the programmer. My programming softwares - both avrdude and uisp complained that they cannot read the chip. Such bad fuse scenarios are common and the one sweet way to recover the chip is to attach a crystal of right value to the dead chip and retry with the programmer. Alas, I did not have any ~20/22/27 pF caps in my stock to use with the crystal. I had to go to the local (which in my case is nowhere nearby) parts shop and I got the wretched caps that cost only two teaspoons of sugar! But then things flowed smoothly, after the dead chip received the much needed CPR and I got that neat looking DIY USB programmer for myself again.

26 comments :

  • Nimal2006

    Can you modify this to program PIC microcontrollers.?

  • animesh

    I don't think so because PIC and AVR are two different architectures of microcontrollers. However, projects similar to USBasp have also come up for the PIC family. These links will delight you :)

    http://openprog.altervista.org/OP_eng.html and
    http://usbpicprog.org/

  • Mayukh

    could you post a picture of the solder side of the perfboard? I am trying to make it but am scared that i'll screw it up and i don't want to go parts hunting again

  • animesh

    @Mayukh:

    Here you go- solder side

    I have mirrored the top image so that you could easily see where the component leads go. I must warn you, I haven't wired the end of programming ribbon cable as the standard AVR ISP header. I prefer it my style. You can wire it like this if you want the header to be a standard one.

  • Mayukh

    thanks...but i already finished soldering it...i tried to make it compact but it ended up a little messy....also why do you use 10 pin isp?

  • animesh

    @Mayukh:

    It's good to know that you made it.

    There is nothing special about using the 10 pin header. You are using only 4 signals plus a Vcc and Gnd, but I did not find any 6-pin FRC headers in the local market, so I opted for the next bigger one.

    Also, since I mostly use ATMEGA16/32 I like to line up the programming signals on one side of header in the same order as the pinout (pins 6-11)

  • Fayaz

    hi
    i am trying to make this usb programmer and i have made two circuits but every time i plugged it in my laptop it says usb not recognized(malfunctioned) i am using Atmega8L instead of Atmega8 as Atmega 8 is not available i also tried changing the crystal to 8 mhz
    but still the same problem

    do u have any ideas?????????

  • animesh

    Hi. Since you made the hardware twice, I assume you went through checking all the connections (painful task indeed) and it's not the connections.

    Other possibility is that the microcontroller did not get programmed properly with the firmware that you downloaded from the usbasp site, or that the fuse bits were not set properly. The readme file at usbasp site has instructions on the fuse bytes. I have, in fact, used ATMEGA8L successfully in the above programmer, keeping the crystal as 12 Mhz.

    One more thing, I have used usbasp.2007-10-23.tar.gz file from usbasp site for all these programmers. I did not try any newer versions. You might want to revert to this version if you believe circuit and fuse settings are perfect. Do tell me how this goes.

  • Fayaz

    ok i think my problem is with fuse bytes ...what i did was just programmed the atmega8l with the .hex file available in the rar file using the programmer at my university..the question now i how do i set the fuse bits ????? one more thing of what value of capacitors did u used with the crystal??????

  • animesh

    How to use fuse bits with the programmer at your university is not easy to answer. I assume those programmers are 'universal programmer' type devices that let you program microcontrollers from several different vendors. They come with their own specific software so you will need to check the manual/help. The option to choose fuse bits should be somewhere under programming options once you have selected the particular microcontroller.

    Bear in mind that fuse-bit 0 means 'programmed' and 1 means 'un-programmed'. The software with your programmer may not be so kind as to use these exact terms which leaves room for possibility that you might set fuses as bit-complements of the intended values. As for the crystal, you may use 22 pF capacitors with the 12 MHz one.

  • Fayaz

    thanks for your help... i found the fuse byte in the software and set them ( HFUSE=0xc9 LFUSE=0xef ) as said in the read me file beside the fuse byte their was also a lock byte option do i have to make any changes in the lock byte??? or should i leave it ?? one last thing do
    i have to use a brand new atmega8l or can i use the previous one which i programmed with out setting the fuse byte??
    again thanks for all your help

  • animesh

    You may leave the lock bits to the default value (un-programmed). Lock bits are used to disable further programming of the chip and optionally also disabling read-back from the chip. You want to be able to program your chip more than just this once, I guess :)

    Using a new chip is fine. The old one can also be used, as you haven't done anything to their fuses, no worries.

  • Unknown

    Hi,
    i was wondering why do we need to use both usb and isp connector?

  • animesh

    The USB cable connects the USBasp programmer to the computer. The ISP connector (pin-header) connects the target microcontroller (that you want to program) to the programmer.

  • Unknown

    Thanks very much, i am a total new comer in this field, figured it out last night, thanks again

  • Unknown

    Animesh, I tried, I failed.
    Is there any chance I could buy a module from you ?(I guess you aren't using your old one now)

    In case your answer is yes, please do mail me: eptheta@yahoo.com
    Thanks.

  • pratyush

    can we program fuse-bits of our AVR microcontroller using this USB programmer? if not then by which type of programmer is required or used for this purpose??

  • animesh

    Yes, this programmer lets you program fuse bits on the target microcontroller.

    It's really not a question of hardware though. The tool that you use to burn .hex file onto the chip should also let you configure fuses. In case you haven't come across any such options with your programming software, try avrdude. You can learn to use it real fast using this tutorial. In case you use WinAVR (Windows), you already have avrdude on your system!

  • animesh

    @Tushar: Is that e-mail address right? I couldn't get my message through. Regarding the programmer, I lost my old module long back... and wish to keep the new one for sentimental value. If you want to buy one, consider these resources:

    [1] http://www.nskelectronics.com/avr_dude.html
    [2] http://robokits.co.in/shop/index.php?main_page=product_info&cPath=12&products_id=54

    The first link points to a fairly popular store for hobbyists in Bangalore. The second link points to a programmer that worked fine for a friend of mine who ordered it online. But at any rate, making one in the DIY-spirit shall be more rewarding, I guess!

  • Unknown

    Hi Animesh,
    My previous comment was rather premature, I just followed instructions without really understanding things and it didn't work out.
    I guess I'm fine with my parallel port programmer for now (since I found a laptop that has one). Thanks for the links though.

    In any case, would you mind if I contacted you about some issues that I've been having about fuse bits, timers and PWMs ? I can't get any concrete help from sites like AVRFreaks and it seems you have had a lot of experience with this stuff.

    I would send you a mail, but I can't seem to find your e-mail address anywhere on your site. My 'real'(sorry,I was afraid of spam--just in case) e-mail address is tushar-n@hotmail.com

    Thanks,
    Tushar.

  • oprime

    Can you give the values of the components that you used for the circuit?
    I have heard that the USBAsp circuit given at fischl.de/usbasp does not always work. Some modifications are necessary.

    Since you have a working kit, the circuit is perfect. So please tell me the value of the components.

  • animesh

    Hello oprime.
    I have used the components with the same values as per the schematic in usbasp.2007-10-23.tar.gz from the same site. I never faced a problem with component values. All my hiccups while making the Usbasp were related to either incorrect wiring or incorrect burning of the firmware/fuses.

    Have a look at the closeups of the components to convince yourself:

    Microcontroller
    12 MHz rrystal
    22p and 100n caps, 68Ω resistors
    3.6V zener diode
    4.7μ cap

  • Unknown

    hey animesh...
    i didnt found any circuit diagram for the programmer
    if you can, please send me one on my email id prat33kg@gmail.com
    moreover, the UC you're using, is it necessary for it to have boot loader file.

  • Umair

    Hey! Great stuff man!
    Gonna build this thing from scratch and I have two questions for you (I am new to all of this so this is gonna be very dumbed down)
    1) I need to make a Ultrasonic range detector, and I am using an atmega 8 for it, so can I integrate this programmer with the actual project?
    2) Could you just go through the components required? I have listed out these so far.
    Resistor (1k (3Nos), 68 (2Nos), 2k, 10k)
    Caps (100n, 22p, 4.7u)
    Crystal (12MHz) (I am using an 18MHz crystal for the ultrasonic thing already, so what should I do here?)
    Diodes (3.6)
    ISP connector
    USB connector
    And if you wish to take a look, this is a link to my main project.
    http://electronicsproject.org/arduino-based-distance-sensor/
    Thanks a ton!

  • hemant baluja

    hi that is really good.... can u tell me that it can program atmega328p yes or no
    and can u send the component list required or schematic. hemant.baluja89@gmail.com
    pls replay as soon as possible

  • Unknown

    This link for products
    http://omatompower.com/index.php?route=product/category&path=127

  • Post a Comment