Setting up USBasp for use with Atmel Studio 6

So you want to program AVRs from Atmel Studio with the USBasp?  Well I’ve written this guide for just that!  This was last updated on August 13th, 2015.

Lke many of you, I was born into electronics with an Arduino and I was eager to move from that to just AVR microcontrollers.  While the code difference is another battle, the actual programming of them can be confusing and frustrating to people on a budget.  I thought I’d share my experiences and solution to help anybody else out.

There are many AVR programmers out there: WinAVR, USBisp, USBasp, and a lot of others that are DIY.  After a lot of frustration trying to find help on them, I figured I’d just buy them and try all of them out.  Honestly, I found the USBasp to be the best one.  Since all of them claim to be a USBasp, I’ll clarify, the one at the top of the article is the exact one I use.

First, you are going to need to install some software, Atmel Studio 6, avrdude (<— those are links).  Make sure you put the AVRdude somewhere where you aren’t going to move it because if you do, it will break the method; My Documents is a good place.  I should note that the version of AVRdude is version 5.11, this is the version I used and it works although the newest versions should work fine as well; the older ones, I’m not so sure about.

 

Updating USBasp firmware

Once you have that all set up, the focus turns to the actual programmer.  Like I said, I recommend USBasp that looks like the one to the top.  You’ll notice an unpopulated header between the crystal and the jumpered header.  That one is the self-programming header, so solder a couple headers in there and use a jumper to connect them.  If you have a way of removing solder, you could just short the two pins together and then remove the solder.

Doing this will allow you to program the firmware on the ATmega8 microcontroller so plug that puppy into a usb port to provide power to it.  Next, you need to connect the 10-pin cable to another functioning programmer.  Kind of a catch 22 but if you have an Arduino, you can use the ArduinoAsISP sketch.  The AVRmkII is also affordable ($40-$50 for a high-quality programmer (which also begs the question, why am I making a programmer if I am going to buy a programmer?))  If anybody has a problem getting a hold a working one, e-mail me at strutz.shannon@gmail.com and we can maybe work something out.

Moving on get the newest firmware for the USBasp from here.  Since I can’t say for sure what you are using to program the programmer, I can’t say which utility it uses.  Since I’d used AVRmkII, I just used Atmel Studio.  If you are using a different programmer, but can use avrdude, open that up and program the USBasp with the hex file titled “usbasp.atmega8.2011-05-28.hex”.
This file also includes the device driver that we will install later.

 

External Tool Setup

Once you get the programmer….programmed (yo dawg, I heard you like programmers) its time to set it up for use in Atmel Studio 6.  Open that up and go to the tools menu and click on external tools and click on “ADD”.  Eventually you’ll wanna get your window to look this this the capture on the below.  The commands in the capture are listed below the image.

For quick and easy copy pasta, the commands are right here:
The command field is where your avrdude.exe is located.  Mine is at C:\Users\ShannonS\Desktop\avrdude-5.11-Patch7610-win32\avrdude.exe
The Arguements field is the parameters sent to the avrdude.exe.  Since I’m programming an atmega16, I have it like so:
-c usbasp -p atmega16 -B12 -U flash:w:”$(ProjectDir)Debug\$(ItemFileName).hex”:i

I have gotten some reports that putting the $(ProjectDir)……hex in quotations generates an error.  This must depend on what version of atmel studio 6 you are on.  If the above does not work change the line to:
-c usbasp -p atmega16 -B12 -U flash:w:$(ProjectDir)Debug\$(ItemFileName).hex

NOTE: You will have to change the -p argument if you want to program some other AVR controller.  At this point, it might be more appropriate to name the tool based off of what the target controller is

USBasp

 

If you want to learn what all those commands mean, check it out here!

Device Driver

Once you have the tool setup in Atmel Studio 6, you will have to install the device driver.  For windows users go to your device manager and look in the “other devices” area.  There should be a “USBasp” device.  Right click on it and click on update device driver.  Navigate to where you unzipped the firmware to and select the whole “win-driver” folder, don’t bother going into the folder and looking for the specific file.

At this point, your programmer should be usable.  If you want to make it a little easier to use it, you can add a button to your toolbar in Atmel Studio 6 by going to Tools->Customize, click on the Commands tab and select the Toolbar bubble.  I have the options “Build Selection” and “USBasp” in the bar “Device and Debugger”.  I’m not sure if that is the right spot but, its on the toolbar and thats all that matters.

Note that you do have to “Build” your project before you can program with these programmers (that may be with anything too though) so don’t forget to do that!

Troubleshooting Problems

There are numerous problems that can come about since this process is pretty janky.  If you come across one that isn’t listed, PLEASE e-mail me.

1) can’t read hex file:

2)error: could not find USB device “USBasp” with vid=0x16c0 pid=0x5dc
If you have an error like this, you must update the device driver

There it is! Thats all I have!  Please if you have any questions on this, ask in the comments section below!

You stay classy

-ShannonS

 

Posted in Pre-Graduation, Uncategorized.