Nav:  [home][elec][pdev][avr][parport] > [software]
Go:  [index] [parallel] [serial] [supply circuit] [software]

Electronics -- Atmel/AVR-programming: Programmer Software


Jul 2005: No longer maintained
I am now using my USB-based download cable. Since the parport-based one is no longer used, the programmer software presented here is no longer updated/maintained.
It should, however, still be working nicely.
Mar 2005: Version 2.1:
  • Support for ATMega8515 added.
  • Support for different page sizes (not only 128 bytes).
  • Added -special command to allow for special actions directly coded into main.c. Currently it sets ATMega8515's clock fuses to external clocking.
Apr 2004: Version 2.0:
  • Support for serial programming (SPI interface, allows in-system programming): writing and reading of flash and EEPROM is implemented. Tested with ATMega161 (writing one page at a time) and with AT90S2313 (writing one byte at a time); uses data polling instead of delay timing for better writing performance.
  • Improved -compare again.
Dec 2003: Version 1.5:
  • Improved hex dump (skip 0xffff) and better -compare.
  • Applies Dec/2003 version of Latch16Bit drivers (with critical bug fixes).


The program atmelprg was developed by me and is available under the GNU GPL.
atmelprg can be used to load data onto the AVR RISC's flash and eeprom and to read these contents.
The software works together with the Latch16Bit-based parallel programming circuit as well as with serial programming via SPI interface.

Download and Build

The program is distributed as source code, only. It should compile without problems on the Linux-ix86 platform using the GNU C++ compiler (gcc). Other hardware running gcc and Linux is likely to work, too.

Source: atmelprg-2.1.tar.gz   [21kb gzipped source tarball]
Version:2.1   (2007-06-09)
Author:Wolfgang Wieser   (report bugs here)
License:GNU GPL (Version 2)

After downloading the source code, you need to manually configure the code before compiling it:
For details on the timing issues, see the parallel programming or serial programming page, respectively.
Furthermore, you need to look up your PC's parallel port base address and assign a proper value to parport_baseaddr in

I hope that no additional tweaks are needed. Compiling should be fairly trivial by simply calling make. If an error occurs try and fix it yourself and then send me an e-mail about what could be improved.

First Steps

Note that you need a bidirectional parallel port. I switched mine to "bidirectional" mode (I do not know if it also workd with EPP or ECP modes) in the BIOS (hey, the box is from 1995!) and it works. Don't know about other computers.

In order to see if things work for parallel programming, plug in the Latch16Bit board and the parallel programmer board (with an AVR RISC in the socket, of course), make sure the switch is open (no programming mode), switch on the 5V and 12V power supply.
For serial programming, connect the device via SPI interface and make sure clock and power are applied.
Then, and try to execute:

atmelprg -readsig

(Note: For serial programming, you must call the program atmelspi instead of atmelprg.)
The program will wait for you to enter programming mode (parallel: by closing the switch, serial: by applying a positive RESET pulse and hitting the return key), then read the signature, dump it (or report an error) and (wait for you to) leave programming mode again (parallel: by opening the switch).
If successful, the output should look about like that:

Waiting to enter programming mode... OK
Detected device: (0x1e9401)
  Device name: ATMega161       Flash size.:  16384 bytes  [0x2000 words]
  Vendor.....: Atmel           EEPROM size:    512 bytes
  Has PAGEL: yes;  Fuse+Lock: 2 bytes;  ChipErase: RDY/BSY
Waiting to leave programming mode... OK

NOTE that atmelprg currently only knows AT90S2312, ATMega161 and (untested:) AT90S4433. Other devices will generate an error. Feel free to patch my software or kindly ask me to do that. (When the program reacts upon closing the programming switch, then this is already a good sign.)

Next, you can try to read and dump the flash content which should be 0xff for a newly-bought chip:

atmelprg -readflash -dump flash

The output should look lite that:

Waiting to enter programming mode... OK
Detected device: (0x1e9401)
  Device name: ATMega161       Flash size.:  16384 bytes  [0x2000 words]
  Vendor.....: Atmel           EEPROM size:    512 bytes
  Has PAGEL: yes;  Fuse+Lock: 2 bytes;  ChipErase: RDY/BSY
Reading flash into buffer "flash" (16384 bytes)... done
Dumping buffer "flash" (16384 bytes)
         [skipping 0x0000..0x1ff0: 8192 words 0xffff]
Waiting to leave programming mode... OK

Writing flash and eeprom can be done as follows:

atmelprg -load flash.bin -load eeprom.bin -erase -writeeeprom eeprom.bin -writeflash flash.bin

Atmelprg Documentation

First of all, remember to call atmelprg --help to get a list of all options/commands with a brief description.
Make sure to call the program atmelprg for parallel mode and atmelspi for serial mode. (Use a symlink.)

The basic operation is as follows: Each cmd line arg which begins with a dash is considered a command, the others are parameters. So, -load file.bin means: execute command "load" with parameter "file.bin". Commands are executed in the order they appear on the command line.

The next basic principle is buffers. Most commands operate on buffers which are referred to by their names. So, in order to load the binary file file.bin into the buffer named buf1, use -load file.bin buf1. In case you leave away the second parameter (as further above), the buffer will get a default name which is the file name (without path, i.e. "file.bin").
Note that specifying an already-existing buffer as output will overwrite it without asking, specifying an unknown buffer name as input will generate an error.

The program will not (tell you to) enter programming mode unless this is necessary. You may SIGINT (^C) it when waiting for you to close the switch.
The program will try to go on executing the next commands when one command fails (illegally spelled or referencing non-existing input puffer).

If you understood the above, then atmelprg --help will give you anything you need to know. To complete it, here are a few examples:

This will load the files fileA.bin and fileB.bin into two buffers with the same names as the files, erase the chip, download (buffers) "fileA.bin" to flash and "fileB.bin" to EEPROM:

atmelprg -load fileA.bin -load fileB.bin -erase -writeflash fileA.bin -writeeeprom fileB.bin

In case you want to read the flash contents of the device, dump them and save them to file flash.bin, and also read the lock and signature bits, use:

atmelprg -readflash -dumasc flash -save flash flash.bin -readfuse

(Note that readflash without parameter puts the content info a buffer named "flash". Also note that -dumpasc needs more than 80 columns on the terminal, use -dump without the ASCII column if you only have 80 columns.)

I find it practical to verify the written data after programming the flash so you may use:

atmelprg -load flash.bin -erase -writeflash flash.bin -readflash tmpbuf -compare tmpbuf flash.bin

[home] [site map] [Impressum] [Datenschutz/privacy policy]
Valid HTML 4.01!
Copyright © 2003-2007 by Wolfgang Wieser
Last modified: 2007-06-09 20:20:52