This is an old revision of the document!
The following guide describes the installation and use of the AVR toolkit 9:10 Ubuntu operating system.
Install the following software:
1. Linux software packages
To install the packages, use the terminal command:
sudo apt-get install gcc-avr avrdude avr-libc
or graphical installation software (such as Ubuntu software center or Synaptic packetmanager).
2. Homelab library
The library simplifies the writing of program code, since lower-level functions are ready-made. Visit the Homelab website and download the file named Homeland library vX.X.run, where XX represents the version number. Run the following command to install the library:
sudo sh homelab_library_vX.X.run
Make sure that your library installation is successful.
3. KontrollerLab
KontrollerLab is an IDE (integrated development environment) for writing, compiling, loading and debugging AVR software. Download the KontrollerLab software and save it to some folder (for example, ~/Documents/AVR/KontrollerLab). Run the following command in this folder:
sudo dpkg -i kontrollerlab*.deb
If you have problems with packet dependencies, run the command, which installs the missing packages:
apt-get install –f
Connect to programmer with computer and see if the computer recognizes it. Write the command “lsusb” in the terminal window which should show the list of connected USB devices. Programmers name is “Future Technology Devices International, Ltd FT 232 USB-Serial (UART) IC”.
To get the port to which the programmer is connected to, check the /dev folder using the commands cd /dev (sets /dev as a current folder) and dir (displays the content of the folder). As the programmer is USB-serial interface, it is named as a “ttyUSBx” where “x” marks the index of the inteface. If there are no other USB-serial devices this number is zero.
To write an AVR program, a project must be created which contains all the necessary files: source codes, header files, compiled program, etc. To clearly seperate projects, a folder for each project should be made (this option is given by the project wizard also).
To create a project follow the steps:
1. Open KontrollerLab (Applications → Programming → KontrollerLab) and start a new project from the File → New → New project menu . A window opens where the project location must be specified. In this example the locations is ../Homelab/blinkingLED/.
2. The project must at least one C file where to write the program code. Files can be added from the File → New → New menu. In the opening window, select C source as a file type and specify the name of the file.
3. Next, the project must be configured for Homelab kit. From the Project → Configure Project menu open the configurations window and select Common tab. CPU type should be ATmega128 and the clock should be 14745600,0 Hz. Also the names of the HEX and MAP files should be specified. Pressing a Set as default button makes these configurations as a default for new projects. This is reasonable when working only with Homelab AVR microcontroller. As the HEX and MAP files are also stored as a default it is recommended to use some general name for them, for example “out.hex”.
NB! As the Homelab library can not be added on the Linker configuration tab, the command “-lhomelab” must be added behind the name of the MAP file.
Apply settings on the Compiler tab as showed on the following screenshot. Before pressing OK set compiler configurations also as a default.
4. Seadistada programmaatori sätted, valides menüü Project → Configure Programmer. Choose Programmer-kaardil valida AVRDUDE ning AVR DUDE kaardil määrata programmaatori tüübiks jtagmkI ja ühendusliideseks eelnevalt leitud port /dev/ttyUSBx (vt programmaatori peatükki). Määrata ka siin seadistatud parameetrid vaikimisi säteteks.
5. Seadistada tekstiredaktori sätted nii, et tabulaatorit tõlgendataks 4 tühikuna. See on vajalik, kui juhtutakse lähtefaili avama mõne muu tekstiredaktoriga, mis tõlgendab tabulaatorit teisiti kui KontrollerLab. Sel juhul võib koodi liigendus muutuda, nii et inimese jaoks on kood raskesti jälgitav. Selleks, et seda ei juhtu, valida menüü Settings → Configure Editor ja avanenud aknas vasakult Editing. Märgi linnuke kasti “Insert spaces instead of tabulators” sisse. Samuti määra tabulaatori laiuseks 4 tühikut.
6. Seadista avanenud alamaknad KontrollerLabis oma käe järgi ning kirjuta mingi lihtne programm keskkonna testimiseks. Järgnevas alampeatükis on näitena toodud vilkuva LED programm.
Kui arenduskeskkond on esimest korda paigaldatud ja seadistatud, on mõistlik testida, kas kõik sai tehtud õigesti. Selleks on lihtsaim viis teha üks väike programm, see ära kompileerida ja laadida kontrollerisse.
1. Ühendada programmaator ATMega128 Kontrollerimooduli plaadiga. Kontrollida, et programmaator saab ühendatud õigesse pistikusse (JTAG) ja õigetpidi (kaabel on suunatud kontrolleri plaadist eemale - vaata järgmist pilti). Pärast programmaatori ühendamist ühendada kontrolleri toide (kontrolleri plaadil peab süttima väike roheline LED).
2. Sisestada lihtne C-kood ja kompileerida see (compile).
#include <avr/io.h> #include <homelab/delay.h> int main(void) { // Viigu PB7 seadmine väljundiks DDRB = 0x80; // Lõputu tsükkel while (true) { // Viigu PB7 inverteerimine PORTB ^= 0x80; hw_delay_ms(500); } }
Veendu, et väljundaknasse tuleb teade “File compiled successfully”. Kui annab teate “Error(s) occurred: ”, siis kontrollida, et koodi sisestamisel ei ole tehtud mõnd kirjaviga.
3. Koodi pealelaadimiseks valida ignite käsk. Kui kõik õnnestub, siis väljundaknas viimase reana annab KontrollerLab teate “Project built and uploaded successfully”. Kontrolli, et punane LED hakkaks perioodiliselt vilkuma (500 ms põleb, 500 ms on kustund).
Kui LED vilgub, nii nagu eespool kirjeldatud, on tarkvara paigaldatud edukalt ja esimene labor läbitud. Palju õnne!
Mõnikord tekib vajadus AVR programmis kasutada ujukoma-arve. Nendega arvutamiseks ja nende esitamiseks printf-tüüpi funktsioonidega tuleb projekti seadistustes teha järgmised muudatused:
1. Avada projekti seaded menüüst Project → Configure Project ning valida Linker kaart. Märgistada Linker flags sektsioonis esimene linnuke (vaata ka juuresolevat pilti).
2. Vajutada OK ja sulgeda seadete aken.