0% found this document useful (0 votes)
3 views

8_USBAsp

This document provides a tutorial on using AVRdude with USBasp to program Atmel AVR microcontrollers. It includes instructions for setting up the environment, connecting hardware, executing commands, and troubleshooting common errors. Additionally, it features example C programs for interfacing LEDs with the ATmega32 microcontroller.

Uploaded by

h50522039
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

8_USBAsp

This document provides a tutorial on using AVRdude with USBasp to program Atmel AVR microcontrollers. It includes instructions for setting up the environment, connecting hardware, executing commands, and troubleshooting common errors. Additionally, it features example C programs for interfacing LEDs with the ATmega32 microcontroller.

Uploaded by

h50522039
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Microprocessor & Microcontroller (3141008) Date:

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.

Here is the argument that I provided

avrdude -c usbasp -p m32 -u -U


flash:w:$(ProjectDir)Debug\$(TargetName).hex:i

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

Download and extract this executable in a suitable folder.

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

50 Electronics & Communication Engineering Department, GEC Bharuch


Microprocessor & Microcontroller (3141008) Date:

Connect the USBasp to PC.

Pinout of USBasp

Connection of USBasp and Microcontroller

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.

Give +5V supply to the microcontroller.

51 Electronics & Communication Engineering Department, GEC Bharuch


Microprocessor & Microcontroller (3141008) Date:

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:

> cd D:\mega32\sample code\ex01_simple_input_output\Exe


> d:

If you have NOT added the avrdude’s path to the system path, execute following
command with your path. Otherwise skip this step.

> set PATH=%PATH%;c:\avrdude_6_3\;

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

You should see something like this :

52 Electronics & Communication Engineering Department, GEC Bharuch


Microprocessor & Microcontroller (3141008) Date:

Explanation for command

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.

-p : Processor. We are using ATmega32, hence “m32”.

-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

The memtype field specifies the memory type to operate on.


calibration One or more bytes of RC oscillator calibration data.
eeprom The EEPROM of the device.
efuse The extended fuse byte.
flash The flash ROM of the device.
fuse The fuse byte in devices that have only a single fuse byte.
hfuse The high fuse byte.
lfuse The low fuse byte. lock
The lock byte.

Op

The op field specifies what operation to perform:


r read the specified device memory and write to the specified file
w read the specified file and write it to the specified device memory
v read the specified device memory and the specified file and perform a verIfy
operation.

Filename

SpecIfy the hex file name. If file is not in current directory specIfy file name with
appropriate path.

Format

53 Electronics & Communication Engineering Department, GEC Bharuch


Microprocessor & Microcontroller (3141008) Date:

Format need not be specIfied, for hex files, avrdude will automatically detect the
format.

The trick to do it uickly : The Batch file

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.

Possible errors and problems

1)couldn’t find usbasp:

found 5 busses found


5 busses
avrdude: error: could not find USB device “USBasp” with vid=0x16c0 pid=0x5dc

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.

2)target does not answer

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.

50 Electronics & Communication Engineering Department, GEC Bharuch


Microprocessor & Microcontroller (3141008) Date:

Observation:

Conclusion:

51 Electronics & Communication Engineering Department, GEC Bharuch


Microprocessor & Microcontroller (3141008) Date:

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?

52 Electronics & Communication Engineering Department, GEC Bharuch


Microprocessor & Microcontroller (3141008) Date:

EXPERIMENT – 9

Aim: Interfacing of LED with ATmega32 microcontroller.

Hardware reuiered: USBasp loader, ATmega32 microcontroller,


Resistors, LEDs, Connecting wires.

Software reuired: AVR Studio 5, avrdude, USBasp driver.

Program 9A: Write a C program to blink single LED continuosly.

Interfacing diagram:

#include <avr/io.h>
#include <util/delay.h>
int main (void)
{
DDRB |=
0x01;
While(1)
{
PORTB ^= 0x01;
_delay_ms(1000);
}
return 0;
}

53 Electronics & Communication Engineering Department, GEC Bharuch


Microprocessor & Microcontroller (3141008) Date:

Observation:

54 Electronics & Communication Engineering Department, GEC Bharuch


Microprocessor & Microcontroller (3141008) Date:

Program 9B: Write a C program to blink 8 LED continuosly.

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:

55 Electronics & Communication Engineering Department, GEC Bharuch


Microprocessor & Microcontroller (3141008) Date:

Program 9C: Write a C program for scrolling of 8 LED.


Interfacing diagram:

#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;

56 Electronics & Communication Engineering Department, GEC Bharuch


Microprocessor & Microcontroller (3141008) Date:

_delay_ms(1000)
; PORTB = 0x80;

57 Electronics & Communication Engineering Department, GEC Bharuch


Microprocessor & Microcontroller (3141008) Date:

_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:

58 Electronics & Communication Engineering Department, GEC Bharuch


Microprocessor & Microcontroller (3141008) Date:

Program 9D: Write a C program to display 8-bit binary counter value on 8 LED.

59 Electronics & Communication Engineering Department, GEC Bharuch

You might also like