Avr Linux Note

First of all you need to install (via apt-get, yum or source):
geany (simple IDE, of course you can use nano, vim…)

Write this really simple C code and name it a.c (turning on all led on PORTD)

#include <avr/io.h>

int main(void)
  // Set Port D pins as all outputs
  DDRD = 0xff;

  // Set all Port D pins as HIGH
  PORTD = 0xff;

  return 1;

Compile it for your atmega (mine is ATMEGA32-16PU)

avr-gcc -mmcu=atmega32 -Os a.c

Next you need to convert this program to HEX

avr-objcopy -j .text -j .data -O ihex a.out a.hex

Now it's time to burn it to your microcontroller. I am using AVR ISP mkII (USB).

Show a list of supported microcontroller (for the -p argument)

avrdude -p list -P usb -c avrispmkII

First you need to set the SCK

avrdude -p m32 -P usb -c avrispmkII -tuF

avrdude: Expected signature for ATMEGA32 is 1E 95 02
avrdude> sck 10
avrdude> quit

Programming the hex file into an ATMEGA32:

avrdude -p m32 -P usb -c avrispmkII -Uflash:w:a.hex

Having problems? Want to restart from scratch:

avrdude -p m32 -P usb -c avrispmkII -tuF
avrdude> sck 1000
avrdude> e
avrdude> sck 10

avrdude: erasing chip

Check the state of the chip and other informations

avrdude -p m32 -c avrispmkII -P usb -v
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License