Are you looking to burn a bootloader and program AVR microcontrollers easily and efficiently? In this tutorial, we will guide you through the process using an Arduino Uno board and the Arduino IDE software. By utilizing the In-circuit Serial Programmer (ISP) feature of an Arduino Board, you can quickly install the bootloader and program various AVR microcontrollers.
There has definitely been times that:
- Your microcontroller IC has been burnt
- Or you have obtained a new microcontroller and are willing to program it in the simplest way with the shortest time
However, before doing that, you need to have bootloader burnt on your microcontroller. When you buy a new microcontroller, you can’t just connect it to your computer and program it using a UBS to TTL converter. First, you need to install the bootloader on your microcontroller through the ISP pins, and then you will be able to upload your desired code to it using a USB to TTL converter.
We can use the ISP (In-circuit Serial Programmer) of an Arduino Board for installing the bootloader and also programming different AVR microcontrollers.
In this comprehensive tutorial, we are going to burn the bootloader on an AVR microcontroller and program it using an Arduino Uno Board and the Arduino IDE software. We will actually use the Arduino Uno as an ISP programmer.
Most of the Arduino Boards come with an AVR microcontroller. So we can do the same thing between two Arduino Boards. We can use one as an ISP programmer and the other as the target. If you want to know more about this, you can check this link.
What You Will Learn
In this tutorial, we want to show you how you can program a new AVR microcontroller using an Arduino Uno board and the Arduino IDE. For that, we first burn a bootloader on the AVR microcontroller using the Arduino Board. Then, we will program the microcontroller with a simple code. So, we will be covering all steps needed to program a new AVR microcontroller using an Arduino Board.
By the end of this tutorial, you will be proficient in burning bootloaders and programming AVR microcontrollers using an Arduino board.
Arduino Uno Board Pinout as an ISP Programmer
One of the easiest ways of programming an AVR microcontroller is to use the ISP pins of an Arduino Board. The ISP pins of an Arduino Board make it possible for us to use the Arduino Board as an ISP programmer. These pins can be accessed in two ways:
- Pins 11, 12, and 13 on the Arduino Uno board (note that the pin numbers may vary for different Arduino boards).
- The ISP connector (having 6 pins) which is directly usable.
The 6 pins of the ISP are as follows:
- VCC: 5V
- GND: Electrical ground
- MOSI: Data line from the Master to the Slave
- MISO: Data line from the Slave to the Master
- SCK: Clock pin
- RESET: Reset pin
The 3 pins 11, 12 and 13 are usually used when using the Arduino Board as the programmer. And, the ISP connector is used if we want to program the Arduino Board.
What is a Bootloader?
As mentioned earlier, a new AVR microcontroller cannot be programmed using USB to TTL adapters. To program it in that way, we need to first burn a program named “Bootloader” on it and then, they can be programmed using a USB to TTL converter. Once the bootloader is burnt on the AVR microcontroller, you can upload your desired codes on it using the Arduino IDE.
The volume of this program is about 512B and is stored at the end of the Flash memory. This program is executed again each time the microcontroller is reset. For example, the Atmega8 microcontroller has an 8 KB flash memory. This memory is divided into 2 parts. The end of this memory belongs to the bootloader program, and the rest is used to store other programs that are uploaded. The image below is a representation of the Flash, SRAM and EEPROM memories of the Atmega8 microcontroller.
Different Types of AVR Microcontrollers
AVR microcontroller are manufactured in various sizes and number of pins. Generally, they can be divided into the 5 following categories:
If you want to know more about each of the AVR microcontroller categories above, click here.
The Atmega8 microcontroller belongs to the MiniCore family. These microcontrollers have a total of 28 pins. The pinout of the microcontrollers in the MiniCore series is as follows:
To install the bootloader on an AVR microcontroller and program it, we need some information regarding its pinout:
- 1- These pins are used for burning the bootloader on the microcontroller.
- 2- The microcontroller power supply pins -GND and VCC-
- 3- These 2 pins are for connecting the external crystal to set the operating frequency of the microcontroller
- 4- The RX and TX pins for programming the microcontroller using a USB to TTL converter.
Note that the same pins are used for all AVR microcontrollers. They only might have different pin numbers in different microcontrollers.
We are going to complete this tutorial on the Atmega8 microcontroller from the AVR microcontroller series. To program this microcontroller properly, some other components are also used. These components are necessary for the proper functioning of the whole process. Here is the list you need:
Burn Bootloader on an AVR Microcontroller
Step 1: Arduino as an ISP Programmer
We want to use an Arduino Uno board as a programmer. For that, we first choose the right board and port from the “tools” menu in the Arduino IDE.
In the same menu and in the “Programmer” section, we choose the “Arduino as ISP” option.
Now, we go to “Files → Examples” and open the “ArduinoISP”.
The following code will appear. Upload it on your Arduino board:
/* Made on 18 may 2021
Step 2: Circuit
In this step, the microcontroller is connected to the required components on a breadboard and finally connected to the Arduino Board:
- The “RESET” pin is pulled-up using a 10K resistor.
- A 10 uF capacitor is put between the power supply pins (VCC and GND) to avoid noise and stabilize the supply voltage.
- The 2 pins of the crystal connected to the GND through 2 22pF capacitors
The 2 capacitors used for the crystal can be between 18 – 22 pF.
Step 3: Adding the Target Microcontroller
Now, the circuit is ready, and we can add a microcontroller, so we can burn the bootloader on it. For that, we do as following:
- Step 1: First, check this Github link and find out the AVR category your microcontroller belong to. For example, ours is the Atmega8 and belong to the MiniCore category.
- Step 2: In the Github link above, go to “How to install” section and copy the link below:
- Step 3: Open the Arduino IDE and open the “Preferences” in the “Files” menu. In the opened page, click on the “Additional Boards Manager URLs” and paste the link you copied in the previous step:
- Step 4: Go to “Tools → Board” and open the “Board Manager” icon.
- Step 5: Wait until the downloading is completed. Then, search the word “MiniCore” and install it.
You can repeat the same procedure for any other AVR microcontroller.
Step 4: Burn the Bootloader on the Target AVR Microcontroller
When the final circuit is ready, once again open the Arduino IDE, go to “Tools → Board” and open the MiniCore icon and choose your target microcontroller which is “Atmega8” in our case.
Finally, click on “Burn Bootloader” at the end of the “Tools” menu. Wait for the burning to complete. After properly doing the procedure above, the phrase “Done Burning Bootloader” will appear.
In some applications, we need the whole memory to program the microcontroller. In such cases that the bootloader has been burnt on your microcontroller, and now you need the whole memory for your new code, write your desired code and instead of upload, go to the “Sketch” menu and click on “Upload Using Programmer”. This way, the bootloader is removed and the code you’ve uploaded will occupy as much space as it needs.
Program the Microcontroller
Once the bootloader is burnt on your microcontroller, the microcontroller is ready to be programmed using a USB to TTL adapter and the Arduino IDE. Now, we are going to upload a simple code on the microcontroller and test its performance.
For that, we can use the Arduino Board as our USB to TTL converter and program the microcontroller through the 2 RX and TX pins.
Step 1: Circuit
As already said, the 2 pins RX and TX are used for the communication between the microcontroller and the software. Pay attention that we should connect the RX and TX pins of the Arduino Board to the RX and TX pins of the microcontroller, respectively. We actually want to program the microcontroller using the USB to TTL adapter chip of the Arduino Board. To do that, we need to take the microcontroller of the Arduino Board out of the circuit. For that purpose, connect the “RESET” pin of the Arduino Board to the Ground.
We have connected an LED to pin 8 of the microcontroller, so we can test the programmer performance with a simple code.
Step 2: Programming the Microcontroller
After setting up the circuit, connect the Arduino Board to the computer again and check the settings in the “Tools” menu:
- In “Tools → Board”, choose Atmega8
- In “Tools → Port”, choose the port the Arduino Uno is connected to
To make sure everything has been done successfully up to now, we are going to upload a simple “Blink” code on the Atmega8 microcontroller and see the results.
For the uploading process to performed properly, we connect a button to the “RESET” pin of the microcontroller and the other side of the button to GND. When we hit the “Upload” in the Arduino IDE, we should push the button down at the same time and keep pushing. In that time, the code starts getting compiled. When it starts uploading, we should release the button. This way, the “Uploading” will be completed and the phrase “Done Uploading” will appear.
Upload the following code on your microcontroller.
/* Made on 18 may 2021
If all the steps above are done properly, the LED will start blinking. You can change the delay time and upload again to make sure that it is working just fine.
- Using an 8MHz clock and changing the fuses of the microcontroller
- Setting up the microcontroller with the internal clock
- Using a USB to TTL adapter to program the microcontroller
- Programming an Arduino Board using another Arduino Board
- Programming STM32 microcontrollers with the Arduino IDE
This concludes the process of burning the bootloader on an AVR microcontroller and programming it using the Arduino IDE. Feel free to explore further and experiment with different codes and functionalities.
Good luck with your AVR microcontroller projects!