Thursday, December 5, 2013

Programming AVR microcontroller with AVRDUDE in Windows

Step - 1: Install avrdude

Download and install winavr which includes avrdude from the link below. Note - If AVR studio is installed on you PC, a different driver is used for avrispmk2 and hence avrdude can not be used for programing.

http://sourceforge.net/projects/winavr/files/

 Once installed, go to command terminal and type avrdude. you should get something like this -




Step - 2: Verify your micro-controller and programmer is supported by avrdude

To get list of supported programmers, type

C:\>avrdude -c asdf

You should get response similar to below (with list of supported programmers)




To get list of supported micro-controller type

C:\>avrdude -c avrisp

The response should be similar to this (list of supported micro-controllers) -



Once verified, that you have supported programmer and controller. Next step is to program the micro-controller.

For this tutorial, I am using attiny45 and avrisp mkII programmer.

Step - 3: Programming


The syntex of the command is 

avrdude [options]

Where the options are 

(1) -p
To specify which micro-controller to program 
Example -  for attiny 45 uC, the syntax should be

avrdude -p t45

(2) -c
Type of programmer
Example - if using Atmel AVRISP mk II, the syntax should be

avrdude -p t45 -c avrisp2

(3) -P
Which serial port to use, If using USB device like AVRISP mkII you don't need to include this option or simply use -P usb

avrdude -p t45 -c avrisp2 -P usb 

(4) -U [memory]:r|w|v:[:format]

 [memory] - is either flash or eeprom (or hfuselfuse or efuse for the chip configuration fuses
 r|w|v - means you can use r (read) or w (write) or v (verify) code in memory
[:format] - is file format which we will read/write/verify. we will always be using "Intel Hex" format, so use i


Example: 


If you wanted to write the file test.hex to the flash memory, the complete syntax will be.

avrdude -p t45 -c avrisp2 -P usb -U flash:w:test.hex:i

If you wanted to read the eeprom memory into the file "eedump.hex" you would use 
-U eeprom:r:eedump.hex:i

Step - 4: Make makefile (optional)

A good practice is to make a .make file with all the commands in it and simply run the following commands from command window

1) Make Hex file

make -f  filename.make

2) Program fuses using avrispmk2 programmer (or other programmer, see makefile)

sudo make -f .make program-avrisp2-fuses

3) Program flash

sudo make -f .make program-avrisp2

update - if AVR studio is also installed in your system than you will get this error

did not find any USB device "usb"



Note

AVRISP2 LED Status
 Red - Idle and no target power
Green - Idle with target power
Orange - Busy, programming
Orange blinking - Reversed target cable connection, or not correct pull-up on the reset line.
Red Blink - short circuit in target
Red - orange blink - Upgrade mode


make clean
         make hex
         (sudo) make fuse (check programmer in Makefile, may need to repeat)
         (sudo) make program

No comments:

Post a Comment