In Circuit System Programming (ICSP) using USBtinyISP and Arduino IDE

1. Description

This tutorial shows how to use Arduino IDE (1.8.2) and an USBtinyISP programmer to upload code (bootloader and/or schetches) into ATmega328P-PU microcontrollers without using a serial/USB connection.

USBtinyISP is an inexpensive open-source external programmer that can be used to easily upload code into Arduino Uno R3,  stripped-down AVR development boards and/or standalone ATmega328P-PU microcontrollers.

Difficulty level: intermediate.

2. Parts

– 1 x Arduino Uno R3;
– 1 x Standalone ATmega328P-PU w Reset Button and LED;
– 1 x USBtinyISP v2;
– wires.

3. Interconnecting USBtinyISP Programmer with ATmega328P-PU (on Arduino Uno R3 or standalone)

USBtinyISP is an inexpensive open-source programmer that offers the possibility to easily program an ATmega328P-PU microcontroller using Arduino IDE and/or other software. It could be purchased online for less than 10$ or built from parts. Extensive details about USBtinyISP could be found at the following link: https://learn.adafruit.com/usbtinyisp/overview

The choice of using Arduino IDE offers simplicity and requires no additional cost (as the software is available for free at https://www.arduino.cc/en/Main/Software).

Details on interconnecting USBtinyISP to Arduino Uno R3/standalone ATmega328P-PU microcontroller for programming purposes are presented below:

– USBtinyISP v2 – connectors’s pin-out:

(click to enlarge)

– USBtinyISP v2 – 6 pin ICSP connector and cable pin-out:

(click to enlarge)

– Arduino Uno R3 – 6 pin ICSP connector pin-out:

(click to enlarge)

– Arduino Uno R3 to USBtinyISP:

(click to enlarge)

Note. Connecting USBtinyISP to an Arduino Uno R3 developement board is straight forward, double check pin match at both ends of the 6 pin ICSP cable.

– Standalone ATmega328P-PU – connection to USBtinyISP’s 6 pin ICSP connector:

(click to enlarge)

– Standalone ATmega328P-PU to USBtinyISP:

(click to enlarge)



4. Program a bootloader into ATmega328P-PU (USBtinyISP and Arduino IDE)

4.1.ATmega328P-PU on Arduino Uno R3 development board

– Insert the microcontroller (Atmega328P-PU) into the Arduino board in the right position (double-check orientation); do not power on the Arduino board (power will be supplied by USBtinyISP);
– Set USBtinyUSB jumper on (connecting the two wires) in order to supply power to the target microcontroller;
– Interconnect USBtinyISP to Arduino (6 pin cable, check orientation) – see details in section 3 of this tutorial;
– Plug USBtinyISP to the computer USB port;
– Start Arduino IDE;
– Select the Tools->Board->Arduino/Genuino Uno:

(click to enlarge)

– Select Tools->Programmer->USBtinyISP:

(click to enlarge)

– Select Tools->Burn Bootloader:

(click to enlarge)

The USBtinyISP red LED should light up. It will take a few seconds to program the chip. When it is done, the IDE will tell you it has completed and the red LED will be off.

Note. When trying to upload the bootloader, it is possible to get the following (or similar) error message:

Actually this is not an error, it’s a warning only. The bootloader upload is successfully executed despite of that message, explanation below.

In ATmega328P-PU, extended fuse (“efuse”) uses the three less significant bits (LSB) only (see Extended Fuse Byte in the ATmega328/328P datasheet). As those bits are identical for both 0xfd and 0x05 (see below), any of those values will work the same:

To fix the warning, the corresponding value should be adjusted accordingly in boards.txt (C:\Program Files (x86)\Arduino\hardware\arduino\avr\boards.txt):

– before:

– after:

The boards.txt file might not be editable in place (elevated rights required); copy file elsewhere, edit and save it and overwrite the original.

4.2.Standalone ATmega328P-PU

The steps are similar as in the previous scenario (section 4.1.):

– Built a standalone ATmega328P-PU setup; do not power it on from any external source (power will be supplied by USBtinyISP);
– Set USBtinyUSB jumper on (connecting the two wires) in order to supply power to the target microcontroller;
– Interconnect USBtinyISP to ATmega328P-PU (6 pin cable, see section 3 and interconnection diagram below):

(click to enlarge)

– Plug USBtinyISP to the computer USB port;
– Start Arduino IDE;
– Select the Tools->Board->Arduino/Genuino Uno (screen capture in section 4.1);
– Select Tools->Programmer->USBtinyISP (screen capture in section 4.1);
– Select Tools->Burn Bootloader (screen capture in section 4.1);

The USBtinyISP red LED should light up. It will take a few seconds to program the chip. When it is done, the IDE will tell you it has completed and the red LED will be off.

Note. See note in section 4.1 for the warning related to the extended fuse (“efuse”) value.



5.Upload a sketch into ATmega328P-PU (USBtinyISP and Arduino IDE)

Advantages of using a hardware programmer (USBtinyISP) with ArduinoIDE to upload sketches rather than the standard USB interface:
– faster sketch upload;
– faster boot;
– more SRAM available for sketches (2KB instead of 1.5KB) as a bootloader (512B) is not needed anymore;
– no more conflicts between microcontroller’s Rx/Tx pins and serial programming;
– easier programming of standalone ATmega controllers and/or stripped down development boards.

5.1.ATmega328P-PU on Arduino Uno R3 development board

– Insert the microcontroller (Atmega328P-PU) into the Arduino board in the right position (double-check orientation); do not power on the Arduino board (power will be supplied by USBtinyISP);
– Set USBtinyUSB jumper on (connecting the two wires) in order to supply power to the target microcontroller;
– Interconnect USBtinyISP to Arduino (6 pin cable, check orientation) – see details in section 3 of this tutorial;
– Plug USBtinyISP to the computer USB port;
– Start Arduino IDE;
– Select the Tools->Board->Arduino/Genuino Uno (screen capture in section 4.1);
– Select Tools->Programmer->USBtinyISP (screen capture in section 4.1);
– Select Sketch->Upload Using Programmer:

(click to enlarge)

The USBtinyISP red LED should light up. It will take a few seconds to program the chip. When it is done, the IDE will tell you it has completed and the red LED will be off.

5.2.Standalone ATmega328P-PU

The steps are similar as in the previous scenario (section 5.1.):

– Built a standalone ATmega328P-PU setup; do not power it on from any external source (power will be supplied by USBtinyISP);
– Set USBtinyUSB jumper on (connecting the two wires) in order to supply power to the target microcontroller;
– Interconnect USBtinyISP to ATmega328P-PU (6 pin cable, see section 3 and interconnection diagram in section 4.2);
– Plug USBtinyISP to the computer USB port;
– Start Arduino IDE;
– Select the Tools->Board->Arduino/Genuino Uno (screen capture in section 4.1);
– Select Tools->Programmer->USBtinyISP (screen capture in section 4.1);
– Select Sketch->Upload Using Programmer (screen capture in section 5.1).

The USBtinyISP red LED should light up. It will take a few seconds to program the chip. When it is done, the IDE will tell you it has completed and the red LED will be off.

8. Additional resources

References:

– USBtinyISP: https://learn.adafruit.com/usbtinyisp/overview
– Atmel ATmega328-328P_Datasheet:
http://www.atmel.com/Images/Atmel-42735-8-bit-AVR-Microcontroller-ATmega328-328P_Datasheet.pdf



Leave a Reply