Programming Atmega16A with a USBASP device

Hello guys,

This post is meant to help you out if you are programming a microcontroller for the first time. First off, you may use any AVR that you want but only AVR, not any other brand (USB ASP is only for AVRs). I have mentioned Atmega 16A since I am using this device.

Note: The ‘Technical Guides’ category on this blog is meant to help out people working with a specific technology. I post up guides on equipment I use during some projects to help out other people working on similar technology. You are encouraged to share your knowledge in the comments, however, I may not be able to answer your questions since I do not own the technology in any way.

Things you need

  • A USB ASP Device
  • An AVR microcontroller
  • A precompiled .hex file (download a precompiled one here)
  • WinAVR (that contains AVRDUDE)
  • Veroboard and stackable headers (for making the 10 pin IDC cable to MCU connector)

USB ASP device

You may compile your own .hex file. I use AVR Studio 5 for programming because that’s my preference. The hex file that I have uploaded here is a simple blinking LED program.

Now let me make one thing clear. Atmega 16A and Atmega16(L) are practically different.

Comparison of Atmega devices

Comparison of Atmega devices

The Atmega 16 also has a max frequency of 16MHz but it runs in a range of 4.5V – 5.5V. Atmega 16L is similar to Atmega 16 and has a greater supply frequency range (2.7V – 5.5V) but it would run at a max of 8MHz.

Atmega16A is the newer device and has both a greater supply voltage range and greater frequency  of 16MHz.

AVRDUDE will treat all three of these devices as atmega16. It does not care about the letter at the end. So in a nutshell, USP ASPs are compatible with the Atmega16A devices (and other *A devices) even though it’s not mentioned in their compatibility lists.

Now first of all, install the USB ASP device. A good tutorial is mentioned here.

Let me make one thing clear. Install the drivers AS SOON AS the device is recognized. A lot of people have had this issue that the device won’t be recognized the second time its connected. Don’t wait for it to cause problems for you.  No one has been able to figure out why. When you install the drivers successfully, you won’t have any issues.

Note: Install the drivers without any MCU connected to the device.

Now build the connector for connecting your 10pin (or 6pin) IDC cable to the MCU. You need to have the pinout of both your microcontroller and the 10pin (or 6pin) cable to do so. The pinout of the 10 pin IDC connector is given below:

Pinout of the 10 pin IDC connector

Now here’s the pinout of the Atmega 16A. The six pins needed for programming are highlighted in red.

Pinout for Atmega 16A

Pinout for Atmega 16A

In order to make the connector, you should know how to solder though!

This is the connector that I made:

Now remove the USB ASP, connect the MCU to it and connect the ASP back to the PC. You can actually connect the MCU to it while the device is connected to the PC but would not recommend that.

Now connect the ASP to the PC

Now  you are all set for programming. Open up Command Prompt on windows and issue the AVRDUDE command to program the MCU

avrdude -p <<device>> -P usb -c usbasp -U flash:w:<<file>>

In my case, it would be

avrdude -p atmega16 -P usb -c usbasp -U flash:w:Blink.hex

This is when I am currently in the directory of the file Blink.hex.

Now sit back and relax while AVRDUDE burns your code to the MCU. During this time, the red light on the USBASP will be lit showing that it is communicating with the AVR.

Burning the Code

After that, simply remove the microcontroller from the ASP interface and build your circuit. This is a simple Blinking LED project so I won’t go into the details of how the circuit is to be set up (I assume you must be knowing that). However, if you are using my Blink.hex file, connect two LEDs each to the pins B0 and B1 respectively. Don’t forget the current limiting resistors!

Now its time you powered up the micro from an external supply. The LEDs would start to blink. One remains on for 1 sec while other for half a sec.

That’s it. Good luck and happy coding!



41 responses to “Programming Atmega16A with a USBASP device

  1. why is a circuit given in many other tutorials of programming by USBasp?? I have an atmega16 and a development board.would i need any other components/circuit to program?

    • Hello!

      The circuit is meant to show you how to connect your microcontroller to the ASP (the programmer). This is done by a 6 pin ISP connector (or sometimes a 10 pin connector). See the pinout of the Atmega16A that I have shown above. You will need to build a connector with stackable headers so that you can connect the 6 pin connector to the microcontroller. (See the second last pic, captioned “Now connect the ASP to the PC”). The golden thing is the connector (built with a Veroboard and some stackable headers).

      When you have a development board though, you don’t even need to build this connector. The board has a port for this already. You just plug in the 6 pin header from the ASP onto it. Development boards, in other words, make the task easier for you. They also have some other stuff embedded onto them. Like the crystal oscillator, and stuff like that. If you have a development board, you won’t need the breadboard that I have shown above.

  2. i have a atmega16 development board with a usb programmer circuit also prebuilt….Can you provide me with instructions to burn the hex file onto the flash.. I am having problems while using avrdude gui and also burn-o-mat.

    • I personally don’t prefer using GUI apps. The command line works perfect. Also, can you provide more details? The exact model/version of your development board and the programmer built onto it? You need to specify the programmer type in the avrdude command syntax. Also, if you are using a GUI, make sure you have avrdude installed first. GUI’s also use the avrdude command program while burning the .hex file.

  3. i had installed the drivers of my usb avr programmer correctly but it is showing as digitally unsigned………….why?
    now after making connections as described above and writing in command prompt as

    “avrdude -p atmega16 -P usb -c usbasp -U flash:w:Blink.hex”

    it gives error as

    “avrdude: error:could not find usb device ‘usbasp’ with vid=0x16c0 pid=0x5dc”.

    what should be the reasons? please help me………..

    • Try it on a different computer. The driver is not correctly installed I assume, hence it cannot find your device. Also, there is some bug with these devices they are very finicky in getting recognized. However, once they are, and you install the drivers, there won’t be any problem for you.

    • Are you referring to the current limiting resistors? If yes, the resistance of those resistors depends on the LEDs that you use on pins B0 and B1.

      The current limiting resistors will be attached in series with the LED. To find its resistance value, use the formula:

      R(\Omega) = \dfrac{V_{S}-V_{L}}{I_{L}}

      Where V_{S} is the supply voltage (5 V), V_{L} is the voltage rating of the LED and I_{L} is the current rating of the LED.

  4. Hello, thanks for your tutorial. I have a question: together with USB ASP device, I have bought an adapter cable from 10 to 6 pins. Do I need anything else or can I connect this cable directly to the respective pins of Atmega16? Thank you!

    • I don’t know what type of output is given at the 6 pin micro controller end. But I believe you will definitely need a breadboard to connect this end and the micro controller together (and to build the circuit also). Breadboards are really cheap relatively and you can find one at your local electronics shop.

      • Thank for your quick reply. The output are as follows: Vcc, GND, MOSI, MISO, SCK and RST. I have a breadboard and the micro controller, beside connecting the wires to the respective pins, is there anything I have to do?

      • You’re welcome 🙂
        As far as connectivity is concerned, no you do not need to do anything else. Just the wires to the respective pins and the device to the computer via a USB port.

      • Thanks, I thought so, I don’t know what is wrong… maybe I have burnt my Atmega in previous attemps 🙂 I will buy a new one and try again.

      • Most probably not! See the special note I have written in the post:

        Let me make one thing clear. Install the drivers AS SOON AS the device is recognized. A lot of people have had this issue that the device won’t be recognized the second time its connected. Don’t wait for it to cause problems for you. No one has been able to figure out why. When you install the drivers successfully, you won’t have any issues.

        Now that it is causing problems for you, try on a different computer.

  5. Hello, I found the solution to my problem and I wanted to get back here, maybe this will help others. I was using the command “avrdude -p ATmega162 -P usb -c usbasp” but keep getting the “avrdude: initialization failed, rc=-1” error. Then I found on another site that using -B xy at the end works… so, as soon as I added -B16 or -B32: “AVR device initialized and ready to accept instructions””. Yee! 🙂 Thank again! 🙂

  6. It has to be connected all ground pins of programmer? And second – how about power supply? Does ATmega16A has to be connected to external +5V power supply or it has power via USBasp programmer? And what about pin 30 – (it should be connected to +5V even it is not used – datasheet) and pin 31 – GND. Must they be connect to programming? Thanks.

    • You can connect to any one of the GND pins of the programmer (all are interconnected). ATmega16A can be powered both directly from the programmer OR externally, its totally your choice. I personally connect it via the programmer only. If you plan to power using external source, just hook up the VCC and GND pins to a power supply’s 5V and GND respectively.

      Pins 30 and 31 don’t need to be connected (neither during programming, nor during operation). They are the power pins for the Analog to Digital Converter. The datasheet suggests they must be connected even if the ADC isn’t used, but I never found the need to connect them.

  7. i am using usbasp for atmega16 … after loading the first program no other program is now being installed in the microcontroller…. tell me what to do or how to reset the atmega 16

    • I haven’t tried, but it should. Often, running Windows 7 applications in compatibility mode solves the problem. I don’t think you will need that for avrdude though, since it’s a command line application. Do let us know if you try it on 8.1.

  8. I’ve got a question. You said that even though you’re using atmega16a, you choose atmega16 is AVRDUDE. So, I’ve got ATMega168A, can I just choose Atmega168 in AVRDUDE?

  9. sir.
    i want to burn atmega16 with the help of avr target board and avr usb programmer .
    but when i trying to burn atmega16 its shows that power on failed communicate with target chip.
    i using extreme burner ..
    plz help me 2 solve this..

  10. Hey, i try to conenct my atmega16 with this way, but it wont work.
    Should i set up the minimum system requirements for downlaoding the hex file?
    Or i just need to connect the usb downloader with the correct port?

  11. Sir i have connect my mcu with usb asp according to with ur pin diagram. nd i am insatall avr studio 5 nd usbasp driver nd avr dude. now i want to program on atmega16a mcu. Plzzz sir tell me process

  12. i m sure my connection is right nd my usbasp working bt i have not knowlodge for upload the program on atmega16a ic

  13. repeatedly it is saying that there is no such file or dictionary. i dont know why. i have tried creating many hex files but always the same message. plz give some solution

  14. so i used your tutorial to try to load my hex file and as you can see unsuccessfully. the problem is that i have programmer without slow clock jumper and i need to program a new chip and make it work on external clock 16 MHz ( atmega 32).so the problem is how can i switch speed without jumper or do i need to solder one true schematic…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s