HW - ES Lab
HW - ES Lab
College Of Engineering
Arduino ISP
Methods for connecting & interrupt
external sources to Arduino
No. 26
Part 1 : Arduino ISP
Introduction:
Arduino ISP:
The Arduino ISP is a firmware that runs on the Arduino board, allowing it to act as an In-System
Programmer. The ISP allows the Arduino board to program other AVR microcontrollers through
its SPI (Serial Peripheral Interface) pins. The Arduino ISP can be used to program boards that do
not have a bootloader, as well as to reprogram the bootloader itself.
The Arduino board is based on the AVR microcontroller, which contains a processor, memory,
and other peripherals. The AVR microcontroller has a Harvard architecture, which means that it
has separate memory spaces for instructions and data. The instruction memory is known as the
program memory, while the data memory is divided into the SRAM and EEPROM. The program
memory is non-volatile and can hold the bootloader and user code, while the SRAM and
EEPROM are volatile and non-volatile memory, respectively.
The bootloader is a small program that runs on the microcontroller when it is powered up or
reset. Its main function is to initialize the microcontroller and wait for incoming data from the
serial port. Once it receives the data, the bootloader writes it to the program memory, overwriting
the existing code. After programming is complete, the bootloader jumps to the beginning of the
user code.
Experimental Results:
To demonstrate the interaction process between the Arduino ISP and other devices, we will use
two Arduino Uno boards. One board will act as the ISP, while the other will be programmed
using the ISP. The following steps need to be followed:
Connect the two Arduino Uno boards using the following connections:
Arduino ISP board:
Pin 10 - SS
Pin 11 - MOSI
Pin 12 - MISO
Pin 13 - SCK
GND - GND
5V - 5V
Target board:
Reset - Reset
GND - GND
Open the Arduino IDE on the ISP board and select "Arduino as ISP" from the Examples menu.
Open the Blink example from the File menu and modify the code to blink the LED on Pin 12.
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include <avr/eeprom.h>
#include <avr/boot.h>
#define SS PB2
void setup() {
pinMode(SS, OUTPUT);
pinMode(MOSI, OUTPUT);
pinMode(SCK, OUTPUT);
pinMode(MISO, INPUT);
// Enable SPI and set as master
SPSR = bit(SPI2X);
void loop() {
digitalWrite(SS, LOW);
spi_transfer(0x00);
spi_transfer(0x00);
digitalWrite(SS, HIGH);
digitalWrite(SS, LOW);
spi_transfer(0x00);
spi_transfer(0x00);
digitalWrite(SS, HIGH);
digitalWrite(SS, LOW);
digitalWrite(SS, HIGH);
SPDR = data;
This code sets up the Arduino to use the SPI pins to communicate with the ISP programmer. The
setup() function initializes the SPI pins and sets the clock to the maximum speed. The loop()
function then programs the Arduino by sending commands to the ISP programmer using the
spi_transfer() function.
To use this code, simply connect the ISP programmer to the Arduino's SPI pins as shown in the
circuit diagram, and then upload this sketch to the Arduino using a standard USB cable. After
programming, the ISP programmer can be disconnected and the Arduino will run the program
that was just uploaded.
Conclusion:
The Arduino ISP is a useful tool that allows users to program other AVR microcontrollers using
the Arduino board. The internal structure of the Arduino board is based on the AVR
microcontroller, which contains a processor, memory, and other peripherals. The bootloader is a
small program that runs on the microcontroller when it is powered up or reset. Its main function
is to initialize the microcontroller and wait for incoming data from the serial port. With the
experimental results, we have demonstrated the interaction process between the Arduino ISP and
other devices.
Part 2 : interrupts
An interrupt is a signal that temporarily stops the normal flow of a program's execution to
perform a specific task or event. Interrupts are essential in real-time embedded systems where
specific actions must be taken immediately when an event occurs.
On the Arduino, interrupts are used to handle events such as button presses, sensor readings, or
incoming data. When an interrupt occurs, the program stops executing its current instructions
and jumps to an interrupt service routine (ISR), which is a function that handles the event. After
the ISR finishes executing, the program resumes its normal flow from where it was interrupted.
Example :
on pin number 2 which will fire the Interrupt and the Interuppt