Programming Arduino using Atmel Studio 6

Arduino Atmel Banner
Arduinos are based on Atmel microcontrollers, and they can be programmed using Atmel’s native IDE – Atmel Studio 6.

The main reason to use Atmel Studio 6 instead of Arduino IDE is because it provides better performance, Arduino IDE might be easy to use but it is slow because of inefficient compilation. It takes more cycles to execute an instruction written in Arduino IDE.

In this article, I’ll be using a USBASP programmer, a custom low cost programmer made to program Atmel’s microcontrollers.

IMG_2243

With it, you’ll need a command line tool called AVRDUDE which can be downloaded here.

avrdude-help

Next, download Atmel Studio 6 here and install it.

AVR-Studio-6-StartPage

Before starting, you’ll need to add the USBASP programmer into Atmel Studio.

Go to Tools –> External Tools

add-ext-tools

Add a new tool and name it USBasp. Follow the configuration shown.

ext-tools-window

Arguments :

-c usbasp -p m328p -F -U flash:w:”$(ProjectDir)Debug\$(ItemFileName).hex”:i

 

 

m328p refers to ATmega328P, if you’re programming another MCU, change it accordingly.

Let’s create a new project to test it out. Select ‘GCC C Executable Project’ and give the project a name.

create-new-project

Next, select your MCU. Since I’m using an Arduino Uno, it’ll be ATmega328P.

device-sel

A project will be generated and you can use the code below in the main c file.

// Example Blink code
// by Siew Wai Hung
// http://waihung.net
 
# define F_CPU 16000000L // Specify MCU speed so that delay is correct
#include <avr/io.h>;
#include <util/delay.h>;   
 
int main(void)
{
DDRB = 0b00100000;	
// set bit 5 high to set PORTB,5 as output
// PORTB,5 is Digital Pin 13 on the Arduino
 
    while(1)
    {
	PORTB = 0b00100000; // set bit 5 high to turn on pin
	_delay_ms(500);	
	PORTB = 0b00000000; // set bit 5 low to turn off pin
	_delay_ms(500);
    }
}
//

# define F_CPU 16000000L // Specify MCU speed so that delay is correct
#include <avr/io.h>;
#include <util/delay.h>;

int main(void)
{
DDRB = 0b00100000;
// set bit 5 high to set PORTB,5 as output
// PORTB,5 is Digital Pin 13 on the Arduino

while(1)
{
PORTB = 0b00100000; // set bit 5 high to turn on pin
_delay_ms(500);
PORTB = 0b00000000; // set bit 5 low to turn off pin
_delay_ms(500);
}
}
//

Click on Build –> Build Solution to compile. Upon successful compilation, proceed to upload the code by going to Tools –> USBasp

avrdude-output

The LED on the Arduino should blink if everything goes as planned.

400px-Burning_uno

  1. Alex05-06-2014

    Hi, nice tutorial, but i have a question: i tried to find USBASP on ebay and there are a lot of variants, not seem to be same, can you tell me the exact model? (some cost some dollar some over 50.. can i peek a random one?)

    Thanks

    • Bence06-25-2014

      Hi Alex,

      Buy the cheapest (about 2-3 dollars) USBASP programmer. And do a firmware update: http://www.rogerclark.net/?p=702 (it’s not necessary, but if you do this you can burn the AVR faster).

      Bence

Leave a Reply to Alex Click here to cancel reply.