The hardware requirements for programming Windows and Linux are identical. The PC must only have a Parallel port, usually designated "LPT". You MUST do all the following as an ADMINISRATOR.
Installation:
1. Ensure that your PC has a 25-pin parallel port (printer port) which looks like the one on the feft.2. Download the C compiler for AVR, called WINAVR, from the sourceforge page here. Install the executable.3. Download AVRSTUDIO, a free IDE for programming AVR devices, available from Atmel Corp here. AVR studio should detect the presence of WINAVR on your system without any additional inputs.
Startup:
To begin with, compile and load a simple "hello world" program. Since the board above has only a pair of LEDs as outputs, these will be used to indicate that the controller is alive and running.
First, launch AVR studio. When it starts up, it will open a dialog like this.
Click on the image for a larger view.
Hit new project. Select AVR GCC from the "Project Type" list on he left. Enter an appropriate project name and directory (create one if needed). The name of the project has to be the same as the name of the main file in the project. Hit next.
Select the Debug Platform as 'AVR Simulator' on the left and the device as "ATmega32" on the right. Then hit finish. Since we have no debugging hardware, we an only use the simulator for debugging.
The First Program:
The editor that now opens up contains the blank main file. Add to this the following code:
#include <avr\io.h>
/*This header file is needed for the compiler to understand the register and bit names and device specific assignments, such as ports and pins*/
int main()
/*Traditionally, a main program running on micro-controller will never end. It must go on running in an infinite loop. As such, it is immaterial what the return type of main is, but Linux based compilers, like the GCC, complain if it is not 'int'*/
{
MCUCSR |= 0x80;
MCUCSR |= 0x80;
/*The MCUCSR is the MCU Control and Status Register. The most significant bit is the JTAG disable bit(JTD). Since the JTAG hardware shares pins on PORTC, it needs to be disabled before we can use all PORTC pins.*/
DDRC = 0xff;
/*The Data Direction Register (DDR) is an 8 bit register that controls the direction of data flow on each pin of a given port. Thus there are 4 DDR registers - DDRA through DDRD for ports A, B, C and D. A value of '1' in each bit of the data direction register. Setting 0xff, therefore, causes the entire port to be set as output.*/
PORTC = 0xff;
/*The PORT register sets the actual value (level) on the PORT pins. Each of the 8 bits in this register correspond to one pin on the respective port. A value of 0xFF sets all the pins high, and will cause both the LEDs to glow.*/
while(1);
}
Compiling:
To compile the program, simply hit F7, or 'Build' from the top menu. There should be no errors. Ensure that the build dialog at the bottom of the screen shows green bullets and messages "Build Successful" and "Device: atmega32". The result will be the creation of files in the debug folder in the project directory - a HEX file (to program the flash), a *.EEP file (to program the EEPROM), a list file (LSS) and a MAP file. The assembly generated can be viewed in the List file.
All that you need to do now is to load the program onto the chip.
Programming:
This is the only task that cannot be performed through AVR Studio, since the IDE only provides access to Atmel standard programmers and devices. We will use AVR-DUDE, a free/open source AVR programmer. The full manual for AVRDUDE is here.
Launch a command prompt.
Change directory to the "default" folder in your project directory where the *.HEX file is located.
Call AVRDude using the command in pink. This command (avrdude -p m32 -c dapa) asks the programmer (avrdude) to look for a device or part called m32 (atmega32) via an interface or protocol called "DAPA". The default port assigned for DAPA is the first parallel port, called LPT1.
D:\AVR-project\P1\default>avrdude -p m32 -c dapa
avrdude: can't open device "giveio"
avrdude: failed to open parallel port "lpt1"
If you see the above error, it means avrdude is unable to access the parallel port. All you need to do is open another terminal and change directory to the WINAVR installation binaries. (e.g. C:\WinAVR-20090313\bin)
Now run install_giveio.bat.
C:\WINAVR~1\bin>install_giveio.bat
Copying the driver to the windows directory
target file: C:\WINDOWS\giveio.sys
1 file(s) copied.
Remove a running service if needed...
Installing Windows NT/2k/XP driver: giveio
installing giveio from C:\WINDOWS\giveio.sys... ok.
starting giveio... ok.
set start type of giveio to auto... ok.
Success
Just to be sure, check that it has been installed by running status_giveio.bat:
C:\WINAVR~1\bin>status_giveio.bat
status of giveio:
Type: [0x01] Kernel driver.
Start Type: [0x02] Automatic
Error Control: [0x01] NORMAL: Display a message box.
Binary path: \??\C:\WINDOWS\giveio.sys
Load order grp:
Dependencies:
Start Name:
ok.
C:\WINAVR~1\bin>
Now close this terminal and go back to the previous terminal and run avrdude again:
D:\AVR-project\P1\default>avrdude -p m32 -c dapa
avrdude: AVR device not responding
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
avrdude done. Thank you.
If you still get the above response, it means the chip is not responding. Try and answer the following:
1. Is the cable connected properly to the PC?
2. Is the cable connected to the board?
3. Is the chip getting power? Check this with a multimeter.
4. Are the connections on the cable correct? Remove the AVR chip and check continuity with a multimeter.
5. If the answer to all the above questions is YES, then you have either a dead or burnt chip with you. The fastest way is to put in a new chip and check.
If all has gone well, you should see the following:
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e9502
avrdude: safemode: Fuses OK
avrdude done. Thank you.
For most simple applications, you will need to write only to the flash memory in the controller. This can be done using the following command for AVRDUde:
avrdude -c dapa -p m32 -U flash:w:somename.hex
In the above command, somename.hex is the HEX file generated by AVR Studio. It can be found in the default folder in your project directory. The 'w' refers to a write. You may replace this with a 'r' (for read) and 'v' (for verify). The first argument 'flash' tells the programmer where to write on the chip. Most MegaAVR devices have a flash area, an EEPROM area, and the fuses.
Some basics about tinkering with the Fuses are given here.