0% found this document useful (0 votes)
10 views8 pages

HW - ES Lab

The document discusses the Arduino ISP (In-System Programming), which allows an Arduino board to program other AVR microcontrollers through its SPI pins. It explains the internal structure of the Arduino board, including the role of the bootloader, and provides experimental results demonstrating the programming process. Additionally, it covers the concept of interrupts in Arduino, detailing how they temporarily halt program execution to handle specific tasks or events.

Uploaded by

eng24310051
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views8 pages

HW - ES Lab

The document discusses the Arduino ISP (In-System Programming), which allows an Arduino board to program other AVR microcontrollers through its SPI pins. It explains the internal structure of the Arduino board, including the role of the bootloader, and provides experimental results demonstrating the programming process. Additionally, it covers the concept of interrupts in Arduino, detailing how they temporarily halt program execution to handle specific tasks or events.

Uploaded by

eng24310051
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

University of Basrah

College Of Engineering

Department of computer Engineering

Arduino ISP
Methods for connecting & interrupt
external sources to Arduino

Embedded System Lab

Name: Zahraa muhaned mohamed faeq

No. 26
Part 1 : Arduino ISP
Introduction:

Arduino is an open-source electronic platform based on simple hardware and software. It


provides an easy-to-use interface that allows users to create projects and interact with the
environment. Arduino comes with its integrated development environment (IDE), which allows
for easy programming and uploading of code to the board. However, sometimes the Arduino
board may not have the necessary hardware or connectivity to interface with a particular device.
In such cases, the Arduino ISP (In-System Programming) can be used to program the device.

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.

Internal Structure of the Arduino Board:

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.

Upload the sketch to the ISP board.

Open the Blink example from the File menu and modify the code to blink the LED on Pin 12.

Select "Arduino Uno" as the board from the Tools menu.

Select "Arduino as ISP" as the programmer from the Tools menu.

Select "Burn Bootloader" from the Tools menu.

Wait for the bootloader to be programmed.

Upload the modified Blink sketch to the target board.

Verify that the LED on Pin 12 is blinking.


Example :

#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 SCK PB5

#define MISO PB4

#define MOSI PB3

#define SS PB2

void setup() {

// Set SPI pins to output mode

pinMode(SS, OUTPUT);

pinMode(MOSI, OUTPUT);

pinMode(SCK, OUTPUT);

pinMode(MISO, INPUT);
// Enable SPI and set as master

SPCR = bit(SPE) | bit(MSTR);

// Set clock to maximum (F_CPU/2)

SPSR = bit(SPI2X);

void loop() {

// Set the target chip to the correct mode

digitalWrite(SS, LOW);

spi_transfer(0xAC); // Select programmer mode

spi_transfer(0x53); // Set to ISP mode

spi_transfer(0x00);

spi_transfer(0x00);

digitalWrite(SS, HIGH);

// Erase the chip

digitalWrite(SS, LOW);

spi_transfer(0xAC); // Select programmer mode

spi_transfer(0x80); // Erase chip

spi_transfer(0x00);

spi_transfer(0x00);

digitalWrite(SS, HIGH);

// Program the chip

digitalWrite(SS, LOW);

spi_transfer(0x40); // Select memory programming mode

spi_transfer(0x00); // Address high byte (unused)


spi_transfer(0x00); // Address low byte

spi_transfer(0x0F); // Data to program

digitalWrite(SS, HIGH);

void spi_transfer(byte data) {

// Start the SPI transmission

SPDR = data;

// Wait for transmission to complete

while (!(SPSR & bit(SPIF)));

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 :

This sketch is about exploring the use of external interrupt

in Arduino. Pushing the pushbutton will cause a RISING edge

on pin number 2 which will fire the Interrupt and the Interuppt

Service Routine will be executed

const byte pushpin = 2;

const byte ledpin = 6;

//Put the keyword volatile, since this variable is used in ISR

volatile int pressed = LOW;

You might also like