ATMEL HOWTO
Step 1: Installation
See Installing the AVR Tools
Step 2 (AVR Studio): Creating and compiling your program
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 the AVRstudio discussion.
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"
Step 2 (non-AVR Studio): Creating and compiling your program
- 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
Step 3: 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
Atmel Mega8 Details
fagg [[at]] cs.ou.edu
Last modified: Tue Feb 15 00:53:42 2011