Sunday, February 17, 2008

AVR STK500 Programming

In January i bought a new ATMEL STK500 board and a AVR Dragon board. I did not touch the Dragon board till now. But i could able to program STK500 board using the RS232 connector in the baord. You can view my boards here.

The Atmel AVR STK500 is a starter kit and development system for Atmel's AVR Flash microcontrollers. Most of the AVR microcontrollers are supported with this board. I got two microcontrollers with this board itself : ATMEGA8515L and ATMEGA16. Board is having some switches and LEDs connected to different ports of the microcontroller. This can be used for prototyping. 6 sockets are there for 8, 20 , 28 and 40 pin microcontrollers. Two RS-232 interfaces are there in the board. One for serial programming and the other one to interface with other boards. We can use 10-15 V DC supply.

The suggested way of programming STK500 programming board is using AVR Studio interface software for Windows. And my laptop is not having serial port. So, i bought one USB to serial converter from one electronics shop here. But i could not able to program using AVR microcontroller 8515L using AVR Studio. When programming it is not giving any error, but the load is not working at all..that means LEDs are not blinking(The program was for that purpose..:). Still i dont know what is the problem.

Then i connected the board using Linux. I compiled the program using avr-gcc. Read how to build cross compiler for AVR in my previous post. This time i was successfull. Without no issues, the program loaded to microcontroller and the LEDs started blinking...:)

The program is very simple one. LEDs are connected to PORTB in the microcontroller using switches in the board and connectors.

/* I/O PORT B, DATA DIRECTION REGISTER (0 -> in, 1 -> out) */
#define DDRB (*(volatile unsigned char *)(0x17 + 0x20))

/* I/O PORT B, DATA REGISTER */
#define PORTB (*(volatile unsigned char *)(0x18 + 0x20))

int main(void) {
int i;

/* Set the whole port (all bits) to "output" */
DDRB = 0xff;

while(1) {
/* Turn off all leds connected to port B */
PORTB = 0x00;

/* Delay */
for(i = 0; i < 0xffff; i++);

/* Turn on all leds connected to port B */
PORTB = 0xff;

/* Delay */
for(i = 0; i < 0xffff; i++);
}

return 0;
}

Then , execute following commands.

avr-gcc -mmcu=atmega8515 a.c
avr-objcopy -j .text -j .data -O ihex a.out a.hex
avrdude -p m8515 -c stk500v2 -P /dev/ttyUSB0 -U flash:w:a.hex -v
avr-objcopy is the tool for converting from one object file format to other. Here we are converting from ELF format to Intel Hex format. avrdude is a free software tool for loading the programs to the Flash of AVR microcontrollers.

3 comments:

Amit Kumar Malik said...

Where I could buy STK500 & STK501 in bangalore.

Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...

hi, good site very much appreciatted