Burning Bootloader Using Two Arduino UNO-fixed ‘Atmega328 U’ bootloader burning error
Atmel AVRs are great little ICs, but they can be a bit tricky to program. You need a special programmer and some fancy .hex files, and its not very beginner friendly. The Arduino has largely done away with these issues. They’ve put a .hex file on their AVR chips that allows you to program the board over the serial port, meaning all you need to program your Arduino is a USB cable.
The bootloader is basically a .hex file that runs when you turn on the board. It is very similar to the BIOS that runs on your PC. It does two things. First, it looks around to see if the computer is trying to program it. If it is, it grabs the program from the computer and uploads it into the ICs memory (in a specific location so as not to overwrite the bootloader). That is why when you try to upload code, the Arduino IDE resets the chip. This basically turns the IC off and back on again so the bootloader can start running again. If the computer isn’t trying to upload code, it tells the chip to run the code that’s already stored in memory. Once it locates and runs your program, the Arduino continuously loops through the program and does so as long as the board has power.
Using the Arduino as a Programmer
If you go into the Arduino IDE you will see an example sketch called ‘Arduino as ISP.’ If you upload this code to your Arduino, it will basically act as an AVR programmer.
Upload Arduino as ISP
.Open your Arduino IDE. In your menu, select File > Examples > 11.ArduinoISP > ArduinoISP to open up the Arduino as ISP sketch.Select the COM port for your Arduino as ISP. The COM port may be different depending on how it enumerated on your computer.
Now upload the sketch to ‘PROGRAMMER’ UNO.
. You need to connect the two UNO’s like this:
Pin 10 on ‘PROGRAMMER’ UNO to RESET on the ‘TARGET’ UNO
Pin 11 to Pin 11
Pin 12 to Pin 12
Pin 13 to Pin 13
Once the ‘PROGRAMMER’ UNO has the sketch uploaded, and you have inserted the unprogrammed 328 into the ‘TARGET’ UNO, connect +5 and GND on the ‘PROGRAMMER’ UNO to the ‘TARGET’ UNO to give it power
Upload the code to your Arduino to turn it into a AVRISP.
Burning a Bootloader to Your Target
Leave the Arduino as ISP (i.e. your programmer) connected to your computer. If you have not already, connect your target Arduino. Then select the board definition for your target Arduino under Tools > Board.
Select the programmer that you are using under Tools > Programmer. In this case, our programmer is an Arduino as ISP so select ArduinoISP. You will also need to select the COM port that the Arduino as ISP is connected to if you have not selected the COM port already.
Finally, select Burn Bootloader. This will take the board you selected in the Arduino IDE and look up the associated bootloader in the board.txt file. Then, it will find the bootloader in the Arduino IDE’s program folder (specifically “…\Arduino\hardware\arduino\avr\bootloaders”) and install it. This only works if the board is installed correctly in the IDE and you have the correct bootloader.
Once complete, the ‘TARGET’ UNO is shut down. Remove power and then remove the chip. At this point, you can program another by placing the new chip in the slave, apply power and then press reset on the master.
If you are using Atmega328P microcontroller everything will work fine as explained above.But in the case of Atmega328 U microcontroller you may find an error as given below.
Then in order to fix this error you will have to edit boards.txt file.
Open boards.txt using WordPad and find uno.build.mcu=atmega328P
then change it to uno.build.mcu=atmega328 as shown below.
Save and restart arduino IDE then try again.