What Is Needed to Program AVR Microcontrollers?

Orvin Demsy
6 min readMar 26, 2019

--

Microcontrollers are amazing, it runs on almost all home appliances. They run your phone, play the music, clean your t-shirts, warm your meal, and show your favorite movie. Before getting into those complicated features, it’s reasonable to understand the fundamental of programming microcontroller.

Based on my own understanding and setup, I’m going to share the basic tools to program AVR microcontrollers.

In order to flash your microcontroller, you need these following items :

Hardware

1. Computer w/ Windows OS (This tutorial will use Windows OS)

2. Programmer (This tutorial will use USBasp)

3. Development board (Circuit board that support microcontroller chip to function it)

Software

1. USBasp driver

2. WinAVR

3. IDE Application for AVR (This tutorial will use Atmel Studio 7)

Hardware

Computer
If you live in the 20th century you should know what a computer is. If not then you can easily google it. Oh, make sure that your PC is installed with Windows OS (Operating System), as this tutorial will run on Windows.

Programmer
Programmer! Yes, the “er” at the end of the word “programmer” refers to things that do the action of the verb, such as the word player, mixer, avenger, etc. AVR programmer means a device that could program the AVR. There are kinds of AVR programmers out there on the internet, in fact, each microcontroller has a different programmer so there‘ll be many kinds of them. But in this tutorial, we will use USBasp.

My USBasp programmer

Development Board
Development board is basically a tool that allows your microcontroller to communicate with the programmer. According to my findings, development board could also be called minimum system or target board. The reason it’s called the minimum system because it’s basically a system that allows microcontrollers to operate minimally. What does it mean by minimal? We’ll get to it later. For now, just remember that development board/target board/minimum system connects your microcontroller to your programmer. By the way, here’s mine :

My 40-pins AVR uC development board

Software

USBasp Driver
The driver is needed so that your computer could recognize the USBasp. If this is not installed, there’s no way your computer could recognize your programmer (USBasp) therefore making programming into MCU impossible.

Here is a link to USBasp driver I used, or you could look it up on google :

https://www.fischl.de/usbasp/

Download the driver and save it in anywhere you like. Try inserting the USBasp on the USB port, then to check whether the computer now recognizes it, go to Device Manager.

You will see that under “Other devices”, USBasp has a little yellow warning beside it. This means the driver has not yet installed. Next, we need to install the driver.

If the driver has been successfully installed, you will see the warning is now disappeared.

If the driver is not successfully installed usually you’ll still see a warning symbol on USBasp symbol, to solve this problem try reinstalling the driver, most of the time this will be the main cause. Other cause would be damaged USBasp, so you might need a new one, but it rarely happens.

Now your computer has recognized the USBasp, we are basically ready to program the MCU. But, we need a software which could run and compile C code. This software we’re going to use in this tutorial is called AVR Studio 7. AVR Studio is an IDE (Integrated Development Environment) that is built to match the requirement of an AVR. AVR Studio can be downloaded for free here.

The AVR Studio 7 itself needs to be set so that it recognized USBasp. For information on how to set things up in AVR Studio check the following.

WinAVR
WinAVR is a software development tools for Atmel microprocessors. WinAVR could be downloaded for free here. WinAVR includes GNU GCC compiler for C++ and C, Programmer’s Notepad, MFile, and AVRdude. ‘GNU GCC’ might sounds intimidating, but it is simply just a compiler for our C code. To get a more intuitive understanding of how to program MCU it is advisable to start programming by using programmer’s notepad. The tutorial on that will be available here.

AVRdude
AVRdude is a program to download and upload the program to on-chip memories on AVR microcontrollers using in-system programming (ISP) technique. It can program the Flash or the EEPROM. AVRdude is necessary if you want to program AVR microcontroller. To check whether AVRdude has been installed go to command prompt, then type ‘avrdude’, if a list of AVRdude’s command appears on the screen then, it is installed.

AVRdude’s list of command line

Integrating Atmel Studio 7 with USBasp and WinAVR

Inside WinAVR, there are couple software tools that interact so that our C code could be programmed into AVR chips. This interaction between those tools is called toolchain, just think of it like a chain, where one end is linked to another. In layman’s terms here is how our code could end up in uC:

1. Open Atmel Studio 7.

2. Write C Program.

3. Compile with GNU GCC Compiler.

4. Produce a hex file.

5. Command AVRdude to flash our program into microcontroller.

6. Microcontroller executes hex file inside its flash memory.

For details regarding AVRdude I have written a tutorial on how to AVR programming using programmer’s notepad, please check it.

That is it, folks! We are ready to program some cool things into our MCU! Check out the next part to start our very first program!

Terminologies
Summary of new words or abbreviation on this tutorial.

Flash/Program
Write the code into our MCU

MCU/uC
The abbreviation of microcontroller, MCU stands for Microcontroller Unit

IDE
Stands for Integrated Development Environment, is a software application that provide programmer for software development. (taken from Wikipedia https://en.wikipedia.org/wiki/Integrated_development_environment)

USBasp
One of the programmers for AVR MCU.

Development board/ Minimum system/ Target board
These three words refer to the same thing, which is the board we used to get our MCU ready before we flash our program.

WinAVR
A set of software tools built for Atmel microcontroller programming. Two important elements that included inside WinAVR :
- GNU GCC Compiler: C compiler
- AVRdude: a program to manipulate contents of AVR microcontroller using the in-system programming (ISP)

ISP (In-System Programming)
The ability of a chip that can be programmed without having to be removed from the whole system.

--

--

Orvin Demsy

I have a keen interest on machine learning, BCI, finance, math, and data.