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)
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.
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:
Now here’s the pinout of the Atmega 16A. The six pins needed for programming are highlighted in red.
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 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.
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!