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
In case you don’t know what a USBasp looks like, here’s an image for you.
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.
Make sure you have Atmel Studio, WinAVR and a USBasp to follow this tutorial.
Install both Atmel Studio and WinAVR. You can follow the guided instruction embedded in the installation wizard.
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.
Go to Tools > Options > Toolchain
Select Atmel AVR 8-bit (Cpp Language) option from the dropdown menu.
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
]
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.
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?
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
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.
Now we need to test if my configuration is working properly. Create a new project [GCC C++ Executable Project].
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
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 ==
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.
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
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.
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].
You can take the following steps to resolve the problem
Double check if it’s powered properly with +5V DC.
Short AVCC and VCC together and both GNDs together.
Check the crystal’s and the ceramic capacitors’ connection
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!
No comments, be the first to comment