If you have an Arduino Uno R3, then you don’t need any programmer to flash a bootloader into ATMEGA328P.
How does it work: There are two microcontrollers on the Arduino board: ATMEGA328P (328P) and ATMEGA16U2 (16U2). You can update firmware of 16U2 to become AVRISP MKII programmer and then use Atmel Studio to flash 328P.
I started with kosakalab website, but I had some issues and the steps didn’t work very well for me (especially the part of flashing bootloader through Arduino Software). There were more problems and therefore I decided to put the whole process on my blog, so other people can save their time.
Install Atmel FLIP Software
You will need Atmel FLIP software to update the firmware inside 16U2.
1. Go to http://www.atmel.com/tools/FLIP.aspx and download FLIP.
2. Install it. You should not have any problems, just follow the installation wizard.
3. Take your Arduino board, disconnect it from Power and USB. Fit a Link on ICSP1 header, pins 5-6 (this will keep 16U2 RESET in Low).
4. Connect Arduino to USB.
5. Unfit the Link ICSP1 (5-6). At this moment, 16U2 goes into DFU mode. A new USB device should be recognized.
6. If driver is not installed automatically, install it from “c:Program FilesAtmelFlip 3.4.7usb”
7. Go to Device manager (Win+Pause -> (Hardware) -> Device Manager) and check if you can see the driver installed correctly. It will be located under Atmel USB Devices -> ATmega16U2
Flash AVRISP MKII firmware into ATmega16U2
We are ready to re-flash the firmware inside 16U2.
1. Download AVRISP MKII hex file here. If you would like to know how to compile it, have a look at Compile LUFA AVRISP MKII Project. The file is based on LUFA project.
2. Disconnect your Arduino from USB cable and Power.
3. Fit a Link on ICSP1 pins 5-6.
4. Connect Arduino to USB.
5. Unfit the Link on ICSP1 pins 5-6.
6. Start FLIP Software: Go to Start -> All Programs -> Flip -> Flip.
7. Go to Settings -> Communication -> USB.
8. Press “Open”.
9. Go to File -> Load HEX file and select LUFA-BOTH-AVRISP-MKII.hex
11. Press “Run”.
12. ATMEGA16U2 is now AVRISP MKII and it runs in Atmel Studio Mode. Important: Your “Arduino AVRISP MKII” can run in two modes: Atmel Studio or Avrdude. Below I only will be speaking about Atmel Studio mode as I had a lot of problems with Avrdude mode.
Install Atmel Studio
1. Download and Install Atmel Studio (including drivers) from http://www.atmel.com/microsite/atmel_studio6/
2. After the installation, connect your Arduino to the USB cable. Both LEDs (RX&TX) should blink two times (that means, 16U2 is in “Atmel Studio” mode,). A new device will be recognized.
3. Install drivers. If they are not recognized automatically, you will find them in “c:Program FilesAtmelAtmel USB Drivers”
4. Go to Device Manager (press Win+Pause -> (Hardware) -> Device Manager ) and check if you can see the driver properly installed. It will be under Jungo Connectivity -> AVRISP mkII
5. You are ready to flash ATMEGA328P. Go to the next point.
Flashing Arduino bootloader into ATMEGA328P through ATMEGA16U2
1. This is the hard part 🙂 You will need to solder down some wires. Basically, we need to connect:
ICSP1 MISO2.Pin.1 ICSP MISO.Pin.1
ICSP1 SCK2.Pin.3 ICSP SCK.Pin.3
ICSP1 MOSI2.Pin.4 ICSP MOSI.Pin.4
JP2 PB4.Pin.1 ICSP RESET.Pin.5
See this nice picture at kosakalab post (thank you Kimio):
2. Connect your Arduino board to USB cable. The RX&TX LEDs should blink two times. Drivers should be correctly recognized (Jungo Connectivity -> AVRISP mkII)
3. Start Atmel Studio. Go to Start -> All Programs -> Atmel -> Atmel Studio.
4. Go to: Tools -> Device Programming
5. Select: “Tool” -> AVRISP mkII; “Device” -> ATmega328P; “Interface” -> ISP; and press “Apply” button.
6. Set ISP clock to 16.1kHHz. Press “Set” button.
Note: Programming will not work if you set a very low ISP clock speed. You will get error: “ispProgramMem: Error status received: Got 0x81, expected 0x00 (RDY/nBSY pin sampling timed out)”. However, the maximum ISP speed is also limited and it can not be more than 1/4 frequency of the device.
7. Go to: “Device signature” and click on “Read” button. You should see the correct “Device signature”: 0x1E950F
8. Click on “Memories” and find the Arduino bootloader hex file. It is located in “C:Program FilesArduinohardwarearduinobootloadersoptibootoptiboot_atmega328.hex”
9. Press “Program” button
IMPORTANT NOTE: If you use a brand new unprogrammed ATMEGA328P, you also must program FUSES. Go to Fuses and use following values: low_fuses=0xff; high_fuses=0xde; extended_fuses=0x05
10. You have successfully programmed 328P with Arduino bootloader. In the next step, we will put back the original 16U2 firmware.
Re-flash ATMEGA16U2 to the original Arduino software
Almost done. We need to put back the original software into the ATMEGA16U2.
1. Disconnect your Arduino from Power and USB.
2. Put a Link on the ICSP1 and short pins 5-6.
3. Connect USB cable.
4. Remove the ICSP1 5-6 Link.
5. Start FLIP software. Go to: Start -> All Programs -> Flip -> Flip.
6. Go to: Settings -> Communication -> USB.
7. Click to “Open”.
8. Go to: File -> Load HEX file. Select this file “c:Program FilesArduinohardwarearduinofirmwaresatmegaxxu2arduino-usbserialArduino-usbserial-atmega16u2-Uno-Rev3.hex”
9. Press “Run”.
10. Disconnect USB cable and connect it again. A new USB device should be recognized. If driver is not installed automatically, you will find it in “c:Program FilesArduinodrivers”.
11. Go to Device manager (Win+Pause -> (Hardware) -> Device manager) and check if the driver was loaded correctly. You should see it under Ports -> Arduino Uno
12. Great! We can now test a Blink example. Start Arduino software (Start -> Arduino).
13. Click on the “Open” icon (arrow Up) -> 01.Basics -> Blink.
14. Select COM Port: Tools -> Serial Port -> COM(select the port where the board was recognized).
15. Click to “Upload” icon (arrow Right).
16. The user LED should start blinking 🙂
17. Done! You have successfully re-programmed ATMEGA328P without using any external Programmer.
After this course, you will design your own Arduino like board. This course is for everyone who has never designed any board before and would like to try it.
How to register for this online course?
Find out more about this course in this short introduction video