Tecnología

June 8, 2009

MY FIRST VENTURE WITH ATMEGA16 VIA LINUX

After a long struggle with never ending commands and long lists of packages, not forgetting some tedious circuitry, we finally managed to blink an LED using an Atmel ATMEGA16 microcontroller. I’ll explain what we did in some simple steps.
1. Building a programmer (hardware) to program the Microcontroller( MuC )

2. Installation of necessary packages, for compiling and burning the MuC.

3. Burning the MuC

4. Sample program

All the installation and applications are  based on GNU Linux Debian / Ubuntu . Please bear with it.

I. Building a Programmer.
We need a hardware circuit to interface the MuC with a PC via its parallel port so that we can transfer our program from the latter to the former. We have used a circuit compatible with Uisp programming application. The circuit is available here.

atmega16-programmer
The hardware on the bottom right hand side is that for supplying Vcc.
Pin 9 is RESET (active low) and so it is always kept HIGH by connecting it to Vcc via 10k resistor as shown.
Make sure that the GND of Parallel port and that of Power supply are shorted.
Q1 is 4MHz crystal for clock.

II. Packages
Several packages/libraries need to be installed on linux for compiling our program(specifically for MuC) as well as uploading it onto the microcontroller’s (flash) memory using the programmer we discussed above. They are build-essential, avr-libc, gcc-avr, binutils, uisp. To install these packages, type as root user :

#apt-get install  build-essential avr-libc  gcc-avr  binutils uisp

You may skip rest of this section if the above command worked fine!!!

If any error creeps up showing invalid repositories or something similar, we may need to update the repositories file of aptitude (apt). The new repositories to be added for Debian are:

deb http://http.us.debian.org/debian testing main
deb http://www.uk.debian.org/debian stable main contrib non-free

These are to be added/written to the file sources.list in the directory.

/etc/apt/sources.list

( Check whether the current repositories of your apt have the packages  or not, even if your distro is/is not Debian/ Ubuntu. And if needed you may have to find out the necessary ones from the internet )

With our new repositories in place, we need to update our apt with this command:

#apt-get update

If you end up with an error indicating wrong key or something like below

Screenshot:

Reading package lists… Done
W: There is no public key available for the following key IDs:
9AA38DCD55BE302B

try the following commands :

#gpg –keyserver pgpkeys.mit.edu –recv-key your-key

/* in this particular case, ‘your key’ is 9AA38DCD55BE302B */

#apt-key add /root/.gnupg/pubring.gpg

The second command should give a result OK. Else try this one also.

#gpg –export your key | apt-key add –

A possible screen-shot:

#gpg –keyserver pgpkeys.mit.edu –recv-key 9AA38DCD55BE302B

gpg: requesting key 55BE302B from hkp server pgpkeys.mit.edu
gpg: key 55BE302B: public key “Debian Archive Automatic Signing Key (5.0/lenny) <ftpmaster@debian.org>” imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)

# apt-key add /root/.gnupg/pubring.gpg
OK

So we are done with updating apt-get. Now the next step is installing the packages. Retype the first command of this section.

The installation part is done!

III. Burning the MuC
Several commands are listed below, which will compile a file ‘a.c’ for running on a MuC, create ‘a.hex’ and burn it onto the MuC. They are as follows

To compile and make a.out :
#avr-gcc -mmcu=atmega16 -Os a.c

To convert it into a.hex
#avr-objcopy -j .text -j .data -O ihex a.out a.hex

To detect MuC

#uisp -dprog=dapa .

To erase any existing program:
#uisp -dprog=dapa -dlpt=0x378 –erase

To load it into MuC
#uisp -dprog=dapa -dlpt=0x378 –upload –verify if=a.hex

Screenshot:
#uisp -dprog=dapa
Atmel AVR ATmega16 is found

#uisp -dprog=dapa -dlpt=0x378 –erase
Atmel AVR ATmega16 is found.
Erasing device …
Reinitializing device
Atmel AVR ATmega16 is found.

# uisp -dprog=dapa -dlpt=0x378 –upload –verify if=a.hex
Atmel AVR ATmega16 is found.
Uploading: flash
Verifying: flash

IV.Sample Program

Here is a sample program for testing the MuC, The LED to be blinked has to be connected as per the diagram given above, on the 19th PIN. Remember, this is just a sample program. So don’t jump into conclusions straight away if you are new to programming a MuC

#include <avr/io.h>
#include<util/delay.h>
#define LED PD5

int main(void)
{
DDRD=(1<<LED);
/ * enable PD5 as output */

while (1) {
PORTD=(1<<LED); /* LED ON */
_delay_ms(100);
PORTD=(0<<LED); /* LED OFF */
_delay_ms(100);
}
return 0;
}

Note : It is two separate ‘-‘ characters where it appears to be one long ‘-‘ eg: ‘–erase’ is actually – – erase without spaces. ( wordpress magic it seems! )

October 11, 2008

ICFOSS

Filed under: Open Source Software — Rohith @ 12:10 am
Tags: ,

My dear state Kerala is going to be the face of Free and Open Source Software in India. 

The Kerala State Information Technology Mission is keen to set up the proposed International Centre for Free and Open Source Software (ICFOSS) by December this year.

Concurrent with the launch of the Centre, the government will hold an international seminar on ‘Free Software, Free Society: Freedom in Computing, Development and Culture’ with a view to highlighting the State’s feats in FOSS. It is also aimed at formulating a consortium of FOSS-related organisations the world over.

For the complete story :

http://www.hindu.com/2008/08/02/stories/2008080253780400.htm

September 22, 2008

beagleboard.org

Hello World!

Here I am, starting off my blog with a post on a seminar which I had attended on 20th Sept,at the CEDT Department, IISc Bangalore. It was an Embedded Linux Training Session for students conducted by Texas Instruments Pvt. Ltd (India) featuring their latest gadget Beagleboard.

Registration had started at around 9.30-9.45 and there was an introductory speech by Mr. Khasim Syed Mohammed. Some beagleboard.org volunteers gave a short ‘Basic GNU Linux concepts’ class for a part of the audience who were absolutely new to this environment( commands like ls, cd, etc). But a thing which is still vibrating in my mind is that one among the guys who gave us this short intro was repeatedly saying ‘laa-yi-nux’ for ‘li-nux’ … (hmm…well..which is true ? and better ?)

A tea break followed 🙂

At 11.45, the next session kicked off with Mr Khasim introducing us with the OMAP3 architecture which underlines our Beagleboard.

Beagle Board is an Ultra-low cost high performance, Low power OMAP3 based platform form Beagleboard.org. It is basically intended for students ,hobbyists and desktop developers looking to get into low-power, small-form-factor applications. It has the electronic industry’s highest performance ARM 600MHz Cortex-A8 processor with graphics and video accelerators. And a surprising thing about it is that its just a 3″-3″ USB powered board. Cool ain’t ?

The session which followed gave us an overview about the software components of it. It was primarily a Hands ON session with the kernels and drivers , bootloaders and compilation steps involved.

Now to make the board working, first they cross-compiled the u-boot and x-loader bootloaders. Then linux kernel and the required drivers were compiled and file system was written. Now this is just an outline. Do read this if you want to know more:

http://code.google.com/p/beagleboard/

They connected basic I/O devices and played a movie ( King Kong 🙂 ) on that board for us

 

All the tools and softwares used were Open Source Software. Its really an amazing piece of electronic marvel. Do visit http://beagleboard.org/

For more pics :

DSC01048

Create a free website or blog at WordPress.com.