Tutorial: AVR STUDIO 5.0 with ARDUINO boards

Tutorial: AVR STUDIO 5.0 with ARDUINO boards

Postby boomber » Mon Dec 12, 2011 11:17 pm

Image

Edit: Check out the new version of this tutorial, using Atmel Studio 6!
Part 1: Using Atmel Studio with Arduino Boards
Part 2: Using Atmel Studio and Arduino Code with Arduino Boards
Part 3: Using custom Arduino libraries in Atmel Studio



Why AVR STUDIO?
Because Arduino IDE is slow, and WinAVR is awful to use.
AVR Studio is a really convenient IDE, based on Visual Studio and released by ATMEL itself.

It includes an astonishing number of 474 example projects, but none for Arduino boards, which need a bit of configuration to be used. But once this is done, coding with AVR Studio becomes really convenient, intuitive and efficient!

AVR Studio 5 description page
http://www.atmel.com/microsite/avr_studio_5/default.asp?category_id=163&family_id=607



TUTORIAL:

1- Download AVR Studio 5.0

Two ways for that, either the long and Atmel way, which needs registration,

Or the short way, directly with the download link from Atmel servers

DOWNLOAD LINK AVR STUDIO 5.0

Current version: 5.0.1223 (since 11.11.2011)



2- Install AVR Studio 5.0

Run the installer and follow the steps.
You will go through 4 major installations: Microsoft Framework 4.0 (which will require a reboot), Visual Studio 2010 SHELL, USB Drivers and AVR Studio 5.0.

Run AVR Studio and let it set the environment for the first time.



3- Get the extensions

C++ isn't natively supported but that can be changed really quickly.

Go to TOOLS -> Extension Manager...
Click "Online Gallery"

Download AVRGCC C++ (Beta).
Since you're here, also download Terminal Window. This is the serial monitor.

Click "restart now"


4- Configure the programmer

THIS REQUIRES THAT YOU HAVE ARDUINO IDE ALREADY INSTALLED

Go to TOOLS -> External Tools...
Create the new tool with those settings:

Title: Serial Program
Command: C:\arduino\hardware\tools\avr\bin\avrdude.exe
(Change that to match your arduino installation folder and locate avrdude.exe)
Arguments: -CC:\arduino\hardware\tools\avr\etc\avrdude.conf -patmega328p -cstk500v1 -P\\.\COM3 -b57600 -Uflash:w:"$(ProjectDir)Debug\$(ItemFileName).hex":i

Check "close on exit"

Change these parameters depending on the board you are using


Arduino Pro Mini:
-patmega328p -cstk500v1 -P\\.\COM3 -b57600

Arduino Uno:
-patmega328p -cstk500v1 -P\\.\COM3 -b115200

Arduino Mega2560:
-patmega2560 -cstk500v2 -P\\.\COM3 -b115200


-p Name of the board
-c Name of the programmer
-b Baudrate of the programmer

Don't forget to change the COM name of your serial port.
Coming from Arduino, you should know all of that, otherwise Find your serial port, and google for the rest!



5- You're done

To create a new project:
File -> New -> Project
Click on C++ Executable project, name it (No spaces or special characters, otherwise AVRDUDE won't work), locate it and click ok.
Select your chip and click ok.

Voilà!
Image

AVR Studio and WinAVR includes are the same, so you won't feel lost if you come from WinAVR



6- Getting started

Attached is a sample Hello World project blinking a LED and printing on serial.

Image


Download it, extract it, and open the "HelloWorld" AVR Studio 5 Solution File.

Open "HelloWorld.cpp" in the main tab.

Build the solution:
Build -> Build Solution

Program your chip:
Tools -> Serial Program

The Terminal Window should have opened with the project. If not, open it:
View ->Terminal Window
Choose your COM port, baud 9600, ASCII, and click Connect
Click "OK" if an error message pops up, it is irrelevant.

This should work with the LED blinking, and your screen should look like the above screenshot!


"HELLO WORLD" should be printed every two seconds and the LED changing its state every 1s.




Things to keep in mind:
*When you run "Serial Program", run it while having in the main tab whatever is your "Main.cpp". (In this case, "HelloWorld.cpp")
Otherwise, AVRDUDE will try and program the chip with just the .hex file of whatever tab you were viewing (which won't work since there is no .hex file of that).

*If you're running the serial monitor, click "Disconnect" before trying to reprogram the chip.

*If you add a new .h or .cpp file, make sure it compiles:
In the solution explorer, click on the file, and just below in "properties", "Build Action", select "Compile"




Troubleshoot:

Make sure that you have the right clock speed configured in your main file, just before "#include <util/delay.h>"
# define F_CPU 16000000L stands for 16MHz

* The LED doesn't blink *
Check your ports


* The serial doesn't work*
Open USART.H and change FOSC to match your cpu (same as F_CPU), and change BAUD to your liking. Just make sure to select the same Baudrate in the Terminal Window.




I hope this helped and made you want to switch to AVR Studio!


02/07/2012: Updated F_CPU and troubleshoot
Attachments
HelloWorld.zip
Atmel Studio 6 VERSION (take the other file for this tutorial)
(41.26 KiB) Downloaded 972 times
HelloWorld.zip
AVR Studio 5 VERSION -Sample code for LED blinking and Serial printing
(66.68 KiB) Downloaded 439 times
Last edited by boomber on Mon Feb 13, 2012 12:02 am, edited 9 times in total.
boomber
 
Posts: 127
Joined: Mon Dec 12, 2011 8:28 pm

Re: Tutorial: AVR STUDIO 5.0 with ARDUINO boards

Postby TSquared » Sat Feb 04, 2012 3:12 pm

I just finished downloading avr studio 5.0 and followed your instructions, for some reason the board is still giving me the "timeout" error when I run the serial program. Is there a solution for this?
TSquared
 
Posts: 22
Joined: Thu Nov 24, 2011 11:53 pm

Re: Tutorial: AVR STUDIO 5.0 with ARDUINO boards

Postby boomber » Sat Feb 04, 2012 5:38 pm

Did you set the right processor when you configured you new project?

It worked like a charm for me :/

Can you put a screenshot of your avrdude error? (in "External tools" for serial program, uncheck the "close on exit" box, it'll help for the screenshot)
boomber
 
Posts: 127
Joined: Mon Dec 12, 2011 8:28 pm

Re: Tutorial: AVR STUDIO 5.0 with ARDUINO boards

Postby TSquared » Sat Feb 04, 2012 6:25 pm

here is the picture of the message I am getting, the board I have selected is the mega2560 so I am not sure what the issue is, this is the same problem that winAVR is giving me as well. Something with a timeout issue.
avr_pic.JPG
avr_pic.JPG (208.59 KiB) Viewed 8112 times
TSquared
 
Posts: 22
Joined: Thu Nov 24, 2011 11:53 pm

Re: Tutorial: AVR STUDIO 5.0 with ARDUINO boards

Postby boomber » Sat Feb 04, 2012 8:06 pm

Try using the former version of AVRdude.
Download Arduino 0023 if you don't have it, and link to its AVRdude for the Serial Program.
The old avrdude is 1,8Mo, the new one 500Ko, so they definitely changed it.

EDIT: Ok I just tried it and I also have the timeout error with the new AVRdude, so definitely try what I said above. What puzzles me though is that on winAVR none worked, but the trick of unplugging worked for both...w/e. Keep me posted!
boomber
 
Posts: 127
Joined: Mon Dec 12, 2011 8:28 pm

Re: Tutorial: AVR STUDIO 5.0 with ARDUINO boards

Postby TSquared » Sun Feb 05, 2012 1:13 am

I just tried to use the file locations from the arduino 0.22 version and now this is the error I am getting.
avr_pic.JPG
avr_pic.JPG (30.32 KiB) Viewed 8102 times
TSquared
 
Posts: 22
Joined: Thu Nov 24, 2011 11:53 pm

Re: Tutorial: AVR STUDIO 5.0 with ARDUINO boards

Postby boomber » Sun Feb 05, 2012 5:39 am

Could be from a bunch of things.
Try those:

*No spaces or special characters in the path.
Just put your Arduino folder so as to match the arguments line I provided and it should be fine. (C:\arduino\hardware\tools\avr\bin\avrdude.exe and C:\arduino\hardware\tools\avr\etc\avrdude.conf)

*Double check the Serial Program external tool arguments line

*You say you're using arduino 0022, try making a clean install of 0023 and use those files
boomber
 
Posts: 127
Joined: Mon Dec 12, 2011 8:28 pm

Re: Tutorial: AVR STUDIO 5.0 with ARDUINO boards

Postby TSquared » Mon Feb 06, 2012 7:00 pm

I still am not managing to get this to work, is there any way we could me on campus?
TSquared
 
Posts: 22
Joined: Thu Nov 24, 2011 11:53 pm

Re: Tutorial: AVR STUDIO 5.0 with ARDUINO boards

Postby boomber » Tue Feb 07, 2012 3:19 am

PM sent
boomber
 
Posts: 127
Joined: Mon Dec 12, 2011 8:28 pm

Re: Tutorial: AVR STUDIO 5.0 with ARDUINO boards

Postby TSquared » Thu Feb 09, 2012 10:56 pm

Hey, some reason when I try and change the program the blink rate does not change no matter what I make the delay_ms, not sure if that means that the new program is not actually being uploaded or if there is some other error. Also, the serial does not work for some reason I set the baud to 112500 on tools, the usart.h, as well as the terminal window yet it didn't work.
TSquared
 
Posts: 22
Joined: Thu Nov 24, 2011 11:53 pm

Next

Return to AVR/PIC

Who is online

Users browsing this forum: No registered users and 1 guest