My First Steps into Embedded System

In this post, i would like to share a few links and tips which will make you to setup an AVR development environment for Linux with in five minutes, and writing your first AVR program.



First of all, you need to install 3 libraries avr-libc gcc-avr .

$sudo apt-get install avr-libc gcc-avr 

If you want to know the use of avr-libc and gcc-avr libraries read this.

My First Program: Blinking an LED

#include<avr/io.h>
#include<util/delay.h>
main()
	{
	DDRB |= _BV(PB0);
	while(1)
		{
		
		PORTB |=_BV(PB0);
		_delay_ms(1000);
		PORTB &= 0<<PB0;
		_delay_ms(1000);
		}
	}

This code assumes an LED is connected to port B 0 pin.

Compiling and Linking

$avr-gcc -g -Os -mmcu=atmega8 -c blink.c

-mmcu specifies your chip type. This command will produce a blink.o file. Next we link this file

$avr-gcc -g -mmcu=atmega8 -o blink.elf blink.o

It will create another file blink.elf. Next we want to convert it to hex

$avr-objcopy -j .text -j .data -O ihex blink.elf blink.hex

It will produce a blink.hex file. Now we can burn this file into microcontroller.

Burning .hex file into MCU

This part depends upon the programmer that you use to program the chip. I am using USB programmer brought from extreme electronics. You can use avrdude or extreme burner-avr.
I use extreme burner software, because it is free and Linux and windows versions of the software is available also GUI is very much user friendly.


The last step is to write the blink.hex file created earlier to the flash memory of atmega8. If you do all the above steps correctly, LED will blink. Welcome to Embedded System world 🙂

Advertisements

2 Comments (+add yours?)

  1. Geoff
    May 17, 2012 @ 15:24:47

    Will be following your footsteps. But can i erase or modify the code once installed or do I need to purchase a pile of chips for each of my trials ?

    Reply

    • Sharath
      May 17, 2012 @ 22:35:07

      No. Definitely you can erase and rewrite new code into chip. If you look at the eXtreme Burner software, there is an option to erase chip data.

      Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

RSS My Recently Bookmarked Links.

  • An error has occurred; the feed is probably down. Try again later.
%d bloggers like this: