This entry is about setting up the AVR STK500 Board for Ubuntu 11.04.
It is fairly easy since all packages available in the Ubuntu Repositorys.
The STK500 is a complete starter kit and development system for the AVR Flash Microcontroller from Atmel Corporation. It is designed to give designers a quick start to develop code on the AVR and for prototyping and testing of new designs. For an introduction to the AVR STK500 please see the user guide.
The STK500 starter kit is shipped with an AT90S8515-8PC microcontroller, which is used in this example.
I use AVRDUDE which is an utility to download/upload/manipulate the ROM and EEPROM contents of AVR microcontrollers.
The program is written in C and c
ompiled with gcc-avr.
Step 1)
Install the following packages via the Command Line Interface (CLI) or Synaptic:
avrdude
binutils-avr
gcc-avr
avr-libc
Step 2)
Since the computer I use does not have a serial port I use a Serial/USB converter.
The programmer needs to know which port the converter is connected to, so to finde the name of the converter use the following command in the CLI:
dmesg | grep tty
The result should look something like this:
sbms@sbms-desktop:~$ dmesg | grep tty
[ 0.000000] console [tty0] enabled
[ 4.235767] tty tty7: hash matches
[ 13.886990] usb 1-1.1: pl2303 converter now attached to ttyUSB0
sbms@sbms-desktop:~$
The dmesg utility displays the contents of the system message buffer. And from the result it can be seen that the Serial/USB converter (pl2303) is connected to the ttyUSB0 port. The name of the converter may vary but I found the name of my converter by using the command:
lsusb
The output should look something like this:
sbms@sbms-desktop:~$ lsusb
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 004: ID 046d:c52f Logitech, Inc. Wireless Mouse M305
Bus 002 Device 003: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
sbms@sbms-desktop:~$
The command shows the name of the devices that are connected to the USB ports on your computer.
Find the name of your device on the list.
Step 3)
Make a file called "binarycounter.c" with the following command:
touch binarycounter.c
Write the following code in the file:
#define F_CPU 10000000UL /* Clock Frequency = 10Mhz */
#include
#include
#include
int main(){
DDRB = 0b11111111; // Set all the pins of PortB as output
unsigned char value = 0xFF; // Initialize the variable named "value" to the he
x value FF
PORTB = value; //Turns off the output on the micro-controllers port B
while (1) {
value = value - 0x01;
PORTB = value;
_delay_ms(250);
}
}
Step 4)
Make a file called "makefile" with the following command:
touch binarycounter.c
Write the following in the file:
CC=avr-gcc
OBJCOPY=avr-objcopy
CFLAGS=-g -mmcu=at90s8515
#Info til AVRDUDE
PROGRAMMER = avrdude
BOARD = stk500
MCU = m8515
PORT = /dev/ttyUSB0
PFLAGS = -p $(MCU) -c $(BOARD) -P $(PORT)
rom.hex : bitmanipulation.out
$(OBJCOPY) -j .text -O ihex bitmanipulation.out rom.hex
bitmanipulation.out : bitmanipulation.o
$(CC) $(CFLAGS) -o bitmanipulation.out -Wl,-Map,bitmanipulation.map bitmanipulation.o
bitmanipulation.o : bitmanipulation.c
$(CC) $(CFLAGS) -Os -c bitmanipulation.c
clean:
rm -f *.o *.out *.map *.hex
program:
$(PROGRAMMER) $(PFLAGS) -e
$(PROGRAMMER) $(PFLAGS) -U flash:w:rom.hex
step 5)
Make sure that your STK500 kit is connected to your computer.
step 6)
Write the following in a console:
make
step 7)
Write the following in a console:
make program
Thats it, you should se the diodes on your STK500 kit function as a binary counter :-)

Ingen kommentarer:
Send en kommentar