🔄 Arduino SPI Communication – Data Transfer Example 📘 Overview
This project demonstrates basic SPI (Serial Peripheral Interface) communication using an Arduino UNO as the Master device. It sends a sequence of 8-bit data values (0x80 → 0x01) through the SPI bus — a useful experiment for testing data shifting, LED control through SPI, or communication with SPI-based peripherals (like shift registers, DACs, or displays).
🧩 Components Required
Arduino UNO
SPI-compatible slave device (e.g., 74HC595 shift register, DAC, or another Arduino)
Jumper wires
Breadboard
⚙️ Pin Connections (Arduino as SPI Master) Arduino UNO SPI Function Description Pin 10 SS (Slave Select) Used to enable/disable slave Pin 11 MOSI Master Out, Slave In Pin 12 MISO Master In, Slave Out Pin 13 SCK Serial Clock
Note: Connect GND of Master and Slave together. The MISO pin isn’t used in this demo since the Master only transmits.
💻 Arduino Code
#include <SPI.h>
void setup()
{
pinMode(10, OUTPUT); // SS pin
SPI.begin(); // Initialize SPI as Master
delay(100);
}
void loop()
{
// Send 8 data bytes in sequence
digitalWrite(10, LOW);
SPI.transfer(0x80);
digitalWrite(10, HIGH);
delay(100);
digitalWrite(10, LOW);
SPI.transfer(0x40);
digitalWrite(10, HIGH);
delay(100);
digitalWrite(10, LOW);
SPI.transfer(0x20);
digitalWrite(10, HIGH);
delay(100);
digitalWrite(10, LOW);
SPI.transfer(0x10);
digitalWrite(10, HIGH);
delay(100);
digitalWrite(10, LOW);
SPI.transfer(0x08);
digitalWrite(10, HIGH);
delay(100);
digitalWrite(10, LOW);
SPI.transfer(0x04);
digitalWrite(10, HIGH);
delay(100);
digitalWrite(10, LOW);
SPI.transfer(0x02);
digitalWrite(10, HIGH);
delay(100);
digitalWrite(10, LOW);
SPI.transfer(0x01);
digitalWrite(10, HIGH);
delay(100);
}📊 Explanation
The SPI.transfer() function sends one byte (8 bits) at a time via MOSI.
The Slave Select (SS) pin is toggled LOW before transmission and HIGH afterward to indicate the start and end of a frame.
Each data byte represents a bit pattern, commonly used for LED shifting or register-based control.
Example:
0x80 → 10000000
0x40 → 01000000
...
0x01 → 00000001
🚀 Applications
Testing SPI signal timing and logic analyzer readings
Driving shift registers (e.g., 74HC595)
Sending data to DAC/ADC chips
Learning basic SPI protocol behavior
🧭 Future Enhancements
Add SPI Slave Arduino to verify bidirectional data exchange.
Implement multi-byte transfers and chip-select multiplexing.
Combine with LCD/LED display modules to visualize data.