This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
en:examples:setup:linux [2012/05/29 11:31] – removed raivo.sell | en:examples:setup:linux [2020/07/20 09:00] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== The software environment for Linux ====== | ||
+ | |||
+ | The following guide describes the installation and use of the AVR toolkit 9:10 Ubuntu operating system. | ||
+ | |||
+ | ===== Software Installation ===== | ||
+ | |||
+ | Install the following software: | ||
+ | |||
+ | **1. Linux software packages** | ||
+ | |||
+ | * gcc-avr – GNU C-language compiler for AVR | ||
+ | * avrdude – Program for uploading hex-files to microcontroller | ||
+ | * avr-libc – C language libraries to write code for AVR platform | ||
+ | |||
+ | 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 packet manager). | ||
+ | |||
+ | **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 //Homelab 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 (// | ||
+ | |||
+ | sudo dpkg -i kontrollerlab*.deb | ||
+ | |||
+ | If you have problems with packet dependencies, | ||
+ | |||
+ | apt-get install –f | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | ===== Connecting the programmer ===== | ||
+ | |||
+ | Connect to programmer with computer and see if the computer recognizes it. Write the command " | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | 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 " | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | ===== Creating a new project ===== | ||
+ | |||
+ | 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 also given by the project wizard). | ||
+ | |||
+ | To create a project follow the steps: | ||
+ | |||
+ | **1.** Open KontrollerLab (// | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | **2.** The project must have 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 " | ||
+ | |||
+ | NB! As the HomeLab library can not be added on the //Linker// configuration tab, the command " | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | Apply settings on the // | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | **4.** Configure the programmer by opening the configurations window from the //Project -> Configure Programmer// | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | **5.** At last, place the windows in the KontrollerLab as it is more convenient and get ready to write your first program. | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | ===== Writing and testing a program ===== | ||
+ | |||
+ | After the configurations steps are done, it is time to programm. | ||
+ | |||
+ | **1.** Connect the programmer with Controller module. Double-check if the programmer is correctly connected with a JTAG socket. The cable must head away from the board (look at the picture). Now connect the power supply and check if the green LED lights on the Controller board. | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | **2.** Write the following program in the Kontrollerlab file editor window and compile it: | ||
+ | |||
+ | <code c> | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | int main(void) | ||
+ | { | ||
+ | // Set pin PB7 as an output | ||
+ | DDRB = 0x80; | ||
+ | |||
+ | // Lõputu tsükkel | ||
+ | while (true) | ||
+ | { | ||
+ | // Inverting pin PB7 | ||
+ | PORTB ^= 0x80; | ||
+ | hw_delay_ms(500); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | [{{ : | ||
+ | |||
+ | Make sure that the output window shows "File compiled successfully" | ||
+ | |||
+ | **3.** To download the program into the Controller press the //Ignite// button. After the succeful download, the " | ||
+ | |||
+ | If everything was done correctly the red LED on the Controller board should blink periodically, | ||
+ | |||
+ | ===== Using floating-point numbers ===== | ||
+ | |||
+ | Sometimes it is neccessary to use floating-point numbers in program. To calculate with them and use them with // | ||
+ | |||
+ | **1.** Open the //Project Configurations// | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | **2.** Press //OK// and close the window. | ||