Setting up Atmel Studio for USBasp and AVR Programming

10 May 2016
Home

Discontinuity of a piecewise continuous function

This article will take about 6 minutes to read.
No comments

feat_image

It can be a lot confusing someone for who just started programming in AVR environment. Atmel studio is the best IDP [Integrated Development Platform] for AVR programming and embedded system development. It takes awful lot of time just to get installed. But once you’re done configuring the IDP for AVR programming, there’s no way you’re going back!

In case you don’t know you can only install Atmel Studio in Windows. So if you’re using linux, this blog post won’t be of any help for you.

First of all, let’s take a look at my current system configuration

Software

Hardware

USBasp

In case you don’t know what a USBasp looks like, here’s an image for you.

usbasp

AVR Development Board

I’m using a USBasp based development board. It supports USBasp driver, so even if I am configuring my IDP using this development board. It should work on your USBasp too.

This development board has a ZIF socket where you can put AVR chips and program using the board. No extra connections are necessary. There are pinout slots for GPIO.

AVR Mini Development Board

Make sure you have Atmel Studio, WinAVR and a USBasp to follow this tutorial.

First Step

Install both Atmel Studio and WinAVR. You can follow the guided instruction embedded in the installation wizard.

Next step

Configuring Toolchain for Compilation

Since I am going to upload my codes to AVR using avrdude. I need to compile the codes first using the same toolchain.

To do that, I need to make a custom toolchain configuration.

Step 1

Go to Tools > Options > Toolchain Select Atmel AVR 8-bit (Cpp Language) option from the dropdown menu.

todo

Step 2

Click Add Flavour, then set the package name “WinAVRDev” or anything you may like.

For the package base path go to WinAVR installation directory and find the bin folder. Now copy the path and paste it. [For me it was E:\WinAVR-20100110\bin ]

todo2

Click Add.

You can make the newly created toolchain package default by clicking on to the Set as Default button.

If you’re done with the toolchain package configuration, click OK to close the Dialog Window.

Creating External Tool for USBasp

To upload the compiled hex files. You need to configure the external tool for USBasp. If you don’t create an external tool for USBasp that’s fine too, then you need to type the avrdude commands to upload or use other software to upload the hex file for you.

Why bother when Atmel Studio can help you on both code compilation and hex file uploading process?

Step 1

Go to Tools > External Tools Click add and fill up the blanks with following strings.

Check: Use Output window

Uncheck: Prompt for arguments, Treat output as Unicode

extools

Title: You can give any title you want.

Command: This will initiate the avrdude program, so you need to put the avrdude directory path in this blank. For me it was E:\WinAVR-20100110\bin\avrdude.exe

Arguments: This is the most tricky part. This is the arguments section where you need to pass specific arguments to do specific tasks. Since I am using the external tool as the program code loader.

I need to put the command which I’d use in avrdude for uploading codes.

You can find a lot about avrdude commands here. Here is the argument that I provided

avrdude -c usbasp -p atmega8 -U flash:w:$(ProjectDir)Debug\$(TargetName).hex:i

You can see that I put atmega8 here. That’s because I am programming my ATmega8 chip. If you need to program other microcontroller. You must change the chip name.

Testing the configuration

Creating new project and device selection

Now we need to test if my configuration is working properly. Create a new project [GCC C++ Executable Project].

Toolchain Selection

We need to check if the proper toolchain is selected or not.

View > Solution Explorer

Right click on to the Project > Click Properties > Advanced > Toolchain Flavour > Select your Toolchain from the dropdown menu

howto

Project compilation

Build > Build Solution

If you can relate the last line of your output with mine then you’ve successfully compiled your program and you can upload it right away!

=== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==

Uploading the *.HEX File

By uploading the hex file I mean programming the avr chip. Remember, up to now you’ve only compiled the project and you haven’t uploaded the code to your atmega chip yet.

Make proper connections with the USBasp and your AVR microcontroller.

Using external clock

If you use external crystal then the you’ll be needing two ceramic capacitors too, connect the components according to the following diagram. If you’re using external clock

extclock

Now connect the ATmega chip to the USBasp

USBasp With ATmega8/168/328

Finally uploading the Code

Before jumping into that, don’t forget to connect the USBasp to your PC first!

I am now going to use the External Tool to upload the hex file to the avr chip.

A successful upload looks like this.

Successful Upload

Troubleshooting

If any error occurs, first of all, check your WinAVR directory.

For the following error take the mentioned steps.

avrdude.exe: error: programm enable: target doesn't answer. 1
avrdude.exe: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
avrdude.exe done.  Thank you.

It means your USBasp can’t communicate with the target chip [The chip you’re going to program].

Steps:

If the steps don’t work, your chip may be bricked. Try the whole process on a new working chip.

Congratulations if you’ve programmed your AVR chip without facing any problems. Stay tuned for AVR based blog posts. Thanks for reading!

Share on
Categories
Embedded-Systems AVR

No comments, be the first to comment

Sending failed, please try again.
Thank you! Your comment is sent. Please note that all of the comments go through moderation.