ATMEL HOWTO
Getting your computer (and you) set up (Windows version)
- Download and install winavr
- Download and install AVR Studio 4.15
(local copies: astudio4b623.exe)
- Plug the AVR ISPmkII into the USB port of your computer
- Your computer may prompt you to install a driver (why, we don't know). Go through the motions of automatic installation.
- Every time you plug in a different programmer, you will have to repeat this process
- Start AVR Studio
- At some point, you may be prompted to upgrade the firmware on the programmer. This is OK (and recommended).
- Detailed AVR Studio Tutorial
Getting your computer (and you) set up (OS X version)
Getting your computer (and you) set up (Linux version)
You will need to find and install rpms or tar files for your distribution for:
- binutils and avr-gcc: see AVR GCC wiki
- avrlib
- avrdude
- Of possible use: gnome avrdude (a gui interface for avrdude)
- Getting avrdude to work as a normal user:
- Create the following file: /etc/udev/rules.d/85-avr.rules
- Add the following content: ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2104", MODE="0666"
Automatic installation:
- sudo apt-get install avrdude
- avrdude-doc
- gcc-avr
- avr-lib
- binutils-avr
Creating and compiling your program (with AVR Studio)
Grab a current version of OUlib: libou_atmega8.a and
oulib.h and place it in your project directory (or place a shortcut to these files in your project directory). You may also want oulib_serial_buffered.h and buffer.h.
See AVRstudio discussion (starting at slide 17).
Common Problems
With AVRstudio, it is not uncommon for things to be working, and then
suddenly stop working (with respect to compiling and downloading)
- text region full: Make sure the "optimization" flag is
set (see above). You will probably also need to re-add "F_CPU"
- Oulib error: F_CPU not defined. Re-add "F_CPU" as
above. After this, perform a "build clean" and a "rebuild all"
- Many things undefined, such as DDRB and PORTB. Re-set your
device to "atmega8"
Creating and compiling your program (without AVR Studio - i.e., Unix systems)
- Create your C program (you can start with this sample program:
led_flash.c). You will need a text editor of some form (e.g., xemacs)
- Create a makefile (start with this sample
makefile)
- Grab a current version of OUlib: libou_atmega8.a and
oulib.h and place it in your project directory (or place a shortcut to these files in your project directory). You may also want oulib_serial_buffered.h and buffer.h.
- Modify the makefile so that it points to your source file:
Change the TARGET = led_flash.c line so that it
contains the name of your source file.
- Compile the your program:
- Use your shell
- Use the "cd" command to change directory to the location
of your makefile and source file.
- Type make. If there are no errors in your
program, you will have a variety of files, including:
- led_flash.lss: a file
that shows both your program and the
corresponding assembly code
- led_flash.hex: a file that contains the program
information that will be downloaded to your
processor
- From your program directory, type: make program
- If you are using the AVRISP mkII (the blue cases), make sure that your port is set to usb
- If you run into device permission problems, you can do this as root as a temporary measure (to configure for standard user use, you must configure udev properly)
- Setting the programmer frequency: (if you run into trouble)
- Enter interactive mode:
avrdude -c avrispmkII -P usb -p m8 -F -u -t
- parms will give you the current clock period
- sck [period] will set the clock period
Use 1 for high speed programming (not possible unless you are using the external 16 MHz crystal)
Use 10 for low speed programming (compatible with the internal clock)
- quit
- Configuring for use with the external crystal: (again, use if you run into trouble)
- Set programmer frequency for low speed programming (above)
- Use make setfuse (make sure you have the latest copy of the makefile)
- Set programmer frequency back to high speed programming
A Basic Circuit
You may use the original led_flash2.fig
file if you wish (this is an xfig file).
The key components are:
- The Atmel Mega8: your microcontroller. Note the power and
ground connections.
- The AVR ISP Connector: connects the processor to the programmer.
- L1 and L2: LEDs used in the sample program. Note that the
polarity of the LEDs is critical. Also - you need a resistor
in series with each of the LEDs (200-1K ohms will do).
- LC is a status LED that allows you to see when the programmer
is downloading code to your processor. This LED is useful, but
not necessary.
- The crystal and 15 pF capacitors (these can also be 18 pF) connected to pins 9 and 10 are
necessary if you want your processor to be clocked at 16 MHz
(by default the processors use an internal clock that runs at 1
MHz).
- The 10K ohm resistor on the reset line (pin 1) keeps the line
high so that the processor will not reset (unless commanded by
the AVR ISP programmer).
Hints
- It is always a good idea to flash an LED in some unique way
at the beginning of your program. This way, you can be sure
that your processor is receiving power and that the power
supply is stable.
- You can find other examples in the examples directory.
- You can also download the oulib source and examples: oulib_2009_05_06.tar.
Atmel Mega8 Details
fagg [[at]] cs.ou.edu
Last modified: Wed May 6 13:03:53 2009