8_USBAsp
8_USBAsp
Command: This will initiate the avrdude program, so you need to put the
avrdude directory path in this blank. For me it was E:\WinAVR-
20100110\bin\avrdude.exe
Arguments: This is the most tricky part. This is the arguments section where you
need to pass specIfic arguments to do specIfic tasks. Since here we have used external
tool as the program code loader. We need to put the command which we’d use in
avrdude for uploading codes.
AVRDude Tutorial : Burning hex files on Atmel AVR using USBasp and
AVRdude
The AVRdude is excellent program for burning hex code into Atmel AVR
microcontroller. USBasp is awesome USB based Atmel AVR programmer. In this
tutorial we will see how to use AVRdude for burning hex files into AVR
microcontroller using USBasp.
In order to program AVR microcontroller you need the .HEX file. It is nothing but the
machine code for the microcontroller. This file is generated by the AVR assembler,
which converts assembly code into machine code. Assembly code can be produced
by third party C cross compiler software or can be handwritten. Typically everyone
uses Atmel Studio, or Arduino environment to write programs in C language.
After compiling, these tools generate .hex file as their output.
AVRdude executables for Windows (or tar archive for linux) can be found at: All
releases : http://download.savannah.gnu.org/releases/avrdude/ look for version
6.3
Windows exe : http://download.savannah.gnu.org/releases/avrdude/avrdude-
6.3-mingw32.zip
NOTE 1: Make sure the path for the avrdude’s folder is added to the PATH
environment variable, otherwise “avrdude.exe” cannot be accessed fron any
random directory on the command prompt. Refer to this page on how to add a path
to PATH environment variable.
NOTE 2: When you connect your USBasp hardware to the Windows 10 machine, you
will need to download and install the drivers for the same.
Connections
Pinout of USBasp
Connect SPI programming pins of USBasp to the AVR microcontroller. Following figure
shows sample schematic diagram, If you have dIfferent AVR, then connect MOSI,MISO,
SCK, RESET and GND pins of that uC to corresponding pins of USBasp.
If you are burning a fresh microcontroller, close the Slow Serial Clock jumper of
USBasp. Since many brand new microcontroller are factory programmed for
internal 1MHz oscillator. USBasp uses very high speed serial clock for faster
programming. Thus you will have to specIfically tell USBasp to use slow serial clock.
This setting is done by above mentioned jumper.
NOTE: If you have microcontroller which has internal oscillator enabled and after
the programming you are not planning to change its fuse bits back to external
clock setting, then you can skip the crystal.
Executing AVRdude:
Fortunately AVRdude is command line tool, so that you can be very sure of what you
are doing with your uC Or Unfortunately AVRdude is command line tool, so you will
have to spend little time to get familiar with it.
o Open the command prompt. (Press WinKey + R. Run dialogbox will appear.
Type cmd and press enter.)
o Navigate to the directory where .hex file is located. For example:
If you have NOT added the avrdude’s path to the system path, execute following
command with your path. Otherwise skip this step.
To burn the hex file enter following command. Consider for example name of my hex
file is io.hex :
> avrdude –c usbasp –p m32 –u –U flash:w:io.hex
-c : Indicates the programmer type. Since we are using the USBasp programmer,
argument “usbasp” is mentioned.
-u : Disables the default behavior of reading out the fuses three times before
programming, then verIfying at the end of programming that the fuses have not
changed. Always use this option. Many times it happens that we forget to switch on
the AVR’s +5V power supply, then at the end of programming cycle, avrdude detects
inconsistent fuses and tries to reprogram them. Since there is no power supply, fuses
gets programmed incorrectly and entire microcontroller gets screwed up(means
becomes useless). Thus always use this option.
-U : memtype:op:filename[:format]
Perform a memory operation. Multiple ‘-U’ options can be specified in order to
operate on multiple memories on the same command-line invocation.
Memtype
Op
Filename
SpecIfy the hex file name. If file is not in current directory specIfy file name with
appropriate path.
Format
Format need not be specIfied, for hex files, avrdude will automatically detect the
format.
It is extremely boring to type such a long command every time you program the uC.
Therefore to avoid this you can create something called as Batch file. It is a text file
which contains series of commands which will be executed by dos command
processor. To create batch file follow these steps :
o Open notepad
o Type our avrdude command. i.e. copy paste following line into notepad.
avrdude –c usbasp –p m32 –u –U flash:w:io.hex
o Save the file with filename “burn.bat” and put it into the directory, which has the hex
file.
Now whenever you recompile your program and want to burn it, simply double
click on burn.bat. This will execute avrdude command that we have typed in it.
This happens when USBasp is not connected or not recognized by the PC. Try to
connect it to dIfferent USBport. Make sure that “Self programming” jumper of
USBasp is open. Always disconnect AVR from USBasp, before plugging USBasp to the
PC.
found 5 busses
avrdude: error: programm enable: target doesn’t answer. 1
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override this check.
avrdude done. Thank you.
Check the connections of USBasp with uC. Check the power supply of the uC. Check
whether you have connected the crystal and decoupling capacitors. If everything
is fine and still you are getting this error, then it indicates that either ur uC is dead or
its fuse bits have got screwed up.
Observation:
Conclusion:
Review Questions:
1. What is USBasp, and what is its primary use in AVR microcontroller programming?
2. Why is USBasp preferred over traditional parallel programmers for AVR
microcontrollers?
3. What are the main components of the USBasp hardware?
4. Describe the role of the onboard microcontroller in USBasp.
5. What types of connectors are commonly used in USBasp for connecting to the AVR
microcontroller?
6. How does the USBasp provide power to the target device? Can it power the target
microcontroller directly?
7. Which software tools are commonly used with USBasp to program AVR
microcontrollers (e.g., AVRDude)?
8. Why is a driver often required for USBasp on certain operating systems?
9. How do you install and configure USBasp drivers on Windows, Linux, and macOS?
10. What are the typical steps to program an AVR microcontroller using USBasp and
AVRDude?
11. What are fuse bits in AVR microcontrollers, and how can you configure them using
USBasp?
12. Explain the role of the -U option in AVRDude when using USBasp.
13. What is the purpose of the jumper settings on the USBasp board (e.g., slow SCK
jumper)?
14. How can you verify a successful upload or programming of firmware using USBasp?
15. What could cause a USBasp to not be recognized by a computer, and how would you
troubleshoot this issue?
16. If programming fails due to a "target not detected" error, what steps would you take
to resolve the issue?
17. How do you handle situations where the USBasp programmer operates too quickly
for a new AVR microcontroller?
18. Can USBasp be used to flash bootloaders onto AVR microcontrollers? If so, how?
19. How does USBasp support ISP (In-System Programming)?
20. What are the limitations of USBasp when compared to other AVR programmers like
Atmel ICE?
EXPERIMENT – 9
Interfacing diagram:
#include <avr/io.h>
#include <util/delay.h>
int main (void)
{
DDRB |=
0x01;
While(1)
{
PORTB ^= 0x01;
_delay_ms(1000);
}
return 0;
}
Observation:
Interfacing diagram:
#include <avr/io.h>
#include <util/delay.h>
int main (void)
{
DDRB |=
0xFF;
While(1)
{
PORTB ^= 0xFF;
_delay_ms(1000);
}
return 0;
}
Observation:
#include
<avr/io.h>
#include <util/delay.h>
int main (void)
{
DDRB |=
0xFF;
While(1)
{
PORTB = 0x01;
_delay_ms(1000)
; PORTB = 0x02;
_delay_ms(1000);
PORTB = 0x04;
_delay_ms(1000)
; PORTB = 0x08;
_delay_ms(1000);
PORTB = 0x10;
_delay_ms(1000)
; PORTB = 0x20;
_delay_ms(1000)
; PORTB = 0x40;
_delay_ms(1000)
; PORTB = 0x80;
_delay_ms(1000);
}
return 0;
}
OR
#include
<avr/io.h>
#include
<util/delay.h>
int main (void)
{
DDRB |= 0xFF;
PORTB = 0x01;
While(1)
{
If(PORTB ==
0x00) PORTB =
0x01;
_delay_ms(1000);
PORTB =
1<<PORTB;
}
return 0;
}
Observation:
Program 9D: Write a C program to display 8-bit binary counter value on 8 LED.