The latest asignment I got from my company is to do some R&D and find a low cost programmer for AVR. The idea is to find a low cost alternative for AVR MKII programmer. One of our clients needs a simple method with which he can upload the hex file without any effort. The client dont want to install AvrStudio and configure it with MKII Programmer etc, he wants a simple method in one click which will burn the hex to the microcontroller. When I got the assignment without doing any R&D itself I knew the answer is USBasp programmer by Thomas Fischl. Most of the micro-controllers have the In-System Programming (ISP) feature, implemented using three pins, Serial ClocK (SCK), Master-In–Slave-Out (MISO) and Master-Out–Slave-In (MOSI). USBASP is an open sourced ISP (In-System Programming) programmer available from http://www.fischl.de/usbasp. USBASP can be used for programming other AVR micro-controllers also. It can be used for burning the boot loader.A low cost of clone of USBasp programmer is available in India from MicroHOPE Foundation (http://microhope.org). The only thing that changes from controller to controller is the fuse settings. So we planned to buy one USBasp programmer from MicrHOPE foundation.
This is the programmer
We purchased the USBasp programmer from Zyxware Technologies India (http://www.zyxware.com/shop/electronics/microcontrollers/microhope-a-micro-controller-development-kit)
First we tested the programmer with GNU/Linux. We used avr-gcc as the compiler and avrdude as the uploader. Install avr-gcc and avrdude in your GNU/Linux system which is available in the package manager
sudo apt-get install avrdude avr-gcc
Suppose you are having hex file named bootloader.hex. Now we need to upload the bootloader.hex to the controller. The uploading is done via commandline method , here I will explain two scenarios so that it will be helpful to know how the commandline arguments changes for different controllers.
For Atmega324 :
Upload hex file :
avrdude -B10 -c usbasp -p atmega32 -U flash:w:bootloader.hex
Set Fuse :
avrdude -B10 -c usbasp -p atmega32 -U lfuse:w:0xff:m -U hfuse:w:0xda:m
For Atmega644 :
Upload hex file :
avrdude -B10 -c usbasp -p atmega644 -U flash:w:bootloader.hex
Set Fuse :
avrdude -B10 -c usbasp -p atmega644p -U lfuse:w:0xff:m -U hfuse:w:0xd8:m
So the difference is only in the name of controllers and fuse settings.
In GNU/Linux to automate this process you can create a shell script. Create a file named upload.sh.
Open the file using vim or gedit.
#! /bin/sh #For Atmega324 avrdude -B10 -c usbasp -patmega32 -U flash:w:bootloader.hex avrdude -B10 -c usbasp -patmega32 -U lfuse:w:0xff:m -U hfuse:w:0xda:m
Give executable permission to the script
sudo chmod +x upload.sh
Now run the shell script so that it burns the bootloader.hex to the controller
In Windows the above process is not that much easy. First download USBasp driver for windows from the below link
Connect your USBasp programmer to the USB port of your PC/laptop. A window like this will pop up.
The driver searching will finally fail and will show the below pop up.
Now go to My Computer, right click it and select manage to get this on your screen
Click device manager –> LibUSB Win32 Devices –> right click USBasp –> update driver software
Now you will get the below window .
Select –> Browse my computer for driver software. You will see a window like this:
Now browse to the location where you have usbasp-windriver.2011-05-28 and select usbasp-windriver.2011-05-28\usbasp-windriver.2011-05-28\libusb_22.214.171.124
Don’t forget to check the “include subfolders” box and then click next
You will get this warning message
Select “Install this driver software anyway”
The driver gets installed and USBasp will be identified by Windows 7.
Now download Avrdude for windows.
Extract the Avrdude. In some cases it may say libusb0.dll is missing if you are encountering with that error donwload libusb0.dll from the below link and place it inside the avrdude folder
Open the Command Prompt window by clicking the
Start button > All Programs > Accessories > Command Prompt.
From the command promt you can call the same above explained avrdude command with a slight difference, the only difference is that you need to give path of avrdude or you need to chnage directory to the folder where avrdude.exe exists. For example if the extracted avrdude folder is placed inside C drive then the command will be like this
C:\avrdude\avrdude.exe -B10 -c usbasp -p atmega32 -U flash:w:C:\Hex\bootloader.hex
The absolute path to avrdude.exe and bootloader.hex must be given.
To automate this process open a batch script type the commands to burn hex and set fuse.
cd C:\avrdude\ avrdude.exe -B10 -c usbasp -p atmega32 -U flash:w:bootloader.hex avrdude.exe -B10 -c usbasp -p atmega32 -U lfuse:w:0xff:m -U hfuse:w:0xda:m pause
Now just double click the batch script and get it done
On sucessful burning you will get an output like this.
If there is any error in connecting pins or driver detection you will get an error messsage like this
Embedded System Engineer