Arduino Programming Using an ISP Programmer
Programming Arduino Uno in pure C or Assembler is not much more difficult than using the standard programming language for Arduino. At the same time, you can greatly benefit in productivity and reduce the size of your program. Next, we will talk about how to upgrade the Arduino Uno R3 using the ISP programmer and AVR Studio 6.2.
So, we need Arduino Uno R3 , any ISP programmer compatible with Atmel Studio 6 , one LED and a resistor, for example, at 250 Ohms. For programming Arduino I use the universal Atmel ICE programmer . As I said, you can use any ISP programmer to program Arduino. You can see the list of supported programmers directly in Atmel Studio.
Everyone knows that the Arduino Uno R3 uses the ATmega328P-PU microcontroller. That is what we will program. In fact, after recording our program, we will no longer have Arduino, but simply a microcontroller with a strapping. Since we will erase the Arduino bootloader.
Unfortunately, the microcontroller ATmega328P-PUdoes not support advanced debugging through JTAG. Of course, you can debug your Arduino in Arduino Micro with breakpoints and output values in output (you need to explicitly ask what you want to get), but this approach is not always convenient, in addition, Atmel Studio has much more advanced debugging tools (viewing register states, memory monitoring, etc.). Therefore, we restrict ourselves to simply flashing our controller using ISP.
Open Atmel Studio and select the GCC C Exacutable Project , as shown.

Great, the project is created. Now you need to connect our programmer. I am using Atmel ICE. This is a universal programmer that fits most Atmel AVR and ARM microcontrollers. We connect the programmer to the computer, then in Atmel Studio select Tools -> Device Programming . Important! If you have Russian Windows, then do not create the project in my documents and generally with folders with a Russian name. It’s better to create a separate folder on the disk with the name without the Cyrillic alphabet, for example, D: \ myprog. Also, do not forget to run the studio with administrator rights.

In the window that opens, select the following options: Tool - the device for programming \ debugging in this case Atmel ICE, Device - the microcontroller that we are going to program, Interface - the interface through which our programmer will flash / debug the microcontroller, in this case only ISP is available.
Click the Read button to get the device identifier and its operating voltage. If the Arduino is connected correctly, then you should get the device number, for example 0x1E950F and voltage 4.9V.
Click Apply. After that, the settings for the programmer should appear as shown in the figure below.

Further we carry out the following actions. Change the ISP Clock to 250. Then go to the Memories section and press the Erase now button. Important! After this step, you will not be able to use your Arduino with the Arduino IDE, since the bootloader will be removed.

Now everything is ready for programming. Let's write a small program for blinking an LED.
Insert the LED into the breadboard and connect it through a current-limiting resistor. Connect the positive tab of the LED to digital output 5 on the Arduino.
Now you need to figure out which leg of the microcontroller corresponds to the output on the board. For this we need a datasheet .

Since we want to control the LED using the 6th pin on the Arduino, we will use the PORTD register and the 5th bit which will supply voltage to the 11th leg of our microcontroller.
Place the following code in the project code file.
Press “Ctrl + Alt + F5” or select Debug -> Start Without Debugging from the menu . The LED will blink!
That's all, actually ... Pay attention to the speed of the firmware and the size of the program. This example takes about 186 bytes, which is 0.6% of the controller memory.

So, we need Arduino Uno R3 , any ISP programmer compatible with Atmel Studio 6 , one LED and a resistor, for example, at 250 Ohms. For programming Arduino I use the universal Atmel ICE programmer . As I said, you can use any ISP programmer to program Arduino. You can see the list of supported programmers directly in Atmel Studio.
Everyone knows that the Arduino Uno R3 uses the ATmega328P-PU microcontroller. That is what we will program. In fact, after recording our program, we will no longer have Arduino, but simply a microcontroller with a strapping. Since we will erase the Arduino bootloader.
Unfortunately, the microcontroller ATmega328P-PUdoes not support advanced debugging through JTAG. Of course, you can debug your Arduino in Arduino Micro with breakpoints and output values in output (you need to explicitly ask what you want to get), but this approach is not always convenient, in addition, Atmel Studio has much more advanced debugging tools (viewing register states, memory monitoring, etc.). Therefore, we restrict ourselves to simply flashing our controller using ISP.
Open Atmel Studio and select the GCC C Exacutable Project , as shown.

Great, the project is created. Now you need to connect our programmer. I am using Atmel ICE. This is a universal programmer that fits most Atmel AVR and ARM microcontrollers. We connect the programmer to the computer, then in Atmel Studio select Tools -> Device Programming . Important! If you have Russian Windows, then do not create the project in my documents and generally with folders with a Russian name. It’s better to create a separate folder on the disk with the name without the Cyrillic alphabet, for example, D: \ myprog. Also, do not forget to run the studio with administrator rights.

In the window that opens, select the following options: Tool - the device for programming \ debugging in this case Atmel ICE, Device - the microcontroller that we are going to program, Interface - the interface through which our programmer will flash / debug the microcontroller, in this case only ISP is available.
Click the Read button to get the device identifier and its operating voltage. If the Arduino is connected correctly, then you should get the device number, for example 0x1E950F and voltage 4.9V.
Click Apply. After that, the settings for the programmer should appear as shown in the figure below.

Further we carry out the following actions. Change the ISP Clock to 250. Then go to the Memories section and press the Erase now button. Important! After this step, you will not be able to use your Arduino with the Arduino IDE, since the bootloader will be removed.

Now everything is ready for programming. Let's write a small program for blinking an LED.
Insert the LED into the breadboard and connect it through a current-limiting resistor. Connect the positive tab of the LED to digital output 5 on the Arduino.
Now you need to figure out which leg of the microcontroller corresponds to the output on the board. For this we need a datasheet .

Since we want to control the LED using the 6th pin on the Arduino, we will use the PORTD register and the 5th bit which will supply voltage to the 11th leg of our microcontroller.
Place the following code in the project code file.
#include<avr/io.h>#define F_CPU 16000000UL //16MHz#include<util/delay.h>intmain(void){
DDRD |= 1<<6;
PORTD &= ~1<<6;
while(1) {
PORTD |= 1<<6;
_delay_ms(100);
PORTD &= ~1<<6;
_delay_ms(100);
}
}
Press “Ctrl + Alt + F5” or select Debug -> Start Without Debugging from the menu . The LED will blink!
That's all, actually ... Pay attention to the speed of the firmware and the size of the program. This example takes about 186 bytes, which is 0.6% of the controller memory.
