Setting up AVR development platform

You can be encouraged to use various types of AVR development tools. Most of them cost money to get full functionality and support. Most common commercial packages are CodeVisionAVR, Imagecraft ICCV, IAR Workbench. All they are great tools out of the box with fast support that you have to pay. Of course, you can give a try with their limited versions to se capabilities as we mentioned before we are going to use free tools that great enough comparing to commercial.

WinAVR or AVR-GCC tools

WinAVR is a toolset for C programming the AVR microcontrollers. It is a bunch of small programs that make development as comfortable as possible. Main tools here are avr-gcc compiler, avrdude programmer, avr-gdb debugger and even more. These are command line tools, so you need to integrate them into some integrated development environment (IDE). There can be any IDE supporting external tools like Eclipse and of course AVRStudio that we will be using. Besides, WinAVR comes with great program writing tool – Programmers Notepad. Actually, with WinAVR you can write, compile, upload to chip and even debug your firmware either in the emulator or via hardware debugger. As we are only going to use compiler only with different IDE, we won’t be going into more details. Ah, probably you will find some rumors that WinAVR-20100110 is the last release if this great tool. Eric Weddington (maintainer) who is also a Product Manager at Atmel is probably going to shift this product to official ATMEL release. This won’t affect the following tutorial as it still will be based on the same avr-gcc compiler. Install, use it and don’t worry.

AVRStudio – also free and powerful

We are going to use AVRStudio intensively during this tutorial so get used to it. It is an excellent IDE with lots of useful features like an editor, debugger and programmer. It has ASM compiler ready to go and plugin that supports avr-gcc compiler from WinAVR. When you install both winAVR and AVRStudio you are prepared to go. Let’s go through the process and compile our first program.

The first program in AVRStudio

Launch AVRStudio create New Project by selecting menu Project->New Project. You should see the following window pop-up:

Here you can create two types of Projects – ASM and C. As we want to create a C project, select AVR GCC option. Select a location where project will be stored.  It is good practice to Create a folder where all project files will be stored and if creating a new program, then create an initial file (it can also be created later). If you are set here then click Next button. In the next window things become more interesting as here you have to select a debugging platform and AVR chip:

As we are not using any hardware debuggers select AVR Simulator for software debugging and choose your device. I’ve chosen the ATmega16. Click Finish to go to the editor. Before writing code lets configure necessary settings so we could adequately compile the code. Go to menu Project->Configuration Options.

Here you can see a bunch of settings. Select device (Atmega16) and enter the frequency of the oscillator. Make sure that there is a checkbox Create Hex File marked – this will generate hex file ready to upload to chip. Click OK to save and let’s write a simple program.

#include <avr/io.h>
#include <util/delay.h>
int main (void)
{
    DDRB = 0x01; //set PB0 pin as output
    while(1) //loop for ever
    {
        PORTB =0x00; //turn LED ON
        _delay_ms(1000); //wait 1s
        PORTB =0x01; //turn LED OFF
        _delay_ms(1000);//wait 1s
    }
    return 0;
}

This is an elementary and straightforward program that will blink a single LED connected to PB0 pin of B port. This is only to show the building process so don’t care too much about the program itself. The circuit is simple as well:

When the code is entered you can build the project. Go to menu Build->Build and you should compile it without errors and see message below:

Build started 18.10.2010 at 23:11:48

AVR Memory Usage
----------------
Device: atmega16

Program:     156 bytes (1.0% Full)
(.text + .data + .bootloader)

Data:          0 bytes (0.0% Full)
(.data + .bss + .noinit)

Build succeeded with 0 Warnings...

If you go to the project folder, in default sub-folder you will find your hex file that can be programmed to your chip. How to flash the chip and debug we will discuss later. Now you should know how to compile a simple program in AVRStudio.

Bookmark the permalink.

5 Comments

  1. thanks for the article

    btw, i think C1 and C2 are missing connections to ground in the schematic

  2. Oops! Thanks for showing this. Fixed.

  3. Pingback: Electronics-Lab.com Blog » Blog Archive » Setting up AVR development platform

  4. hi i did all u said but i keep getting errors when i compile

  5. i named the project as flash it keeps popping
    avr-objcopy: ‘flash.elf’: No such file
    make: *** [flash.hex] Error 1
    Build failed with 1 errors and 0 warnings…

Leave a Reply