Skip to main content

Lesson 6: SPI Communication - High-Speed Data Transfer

📌 Learning Objectives​

  1. Understand what SPI protocol is
  2. Learn about SPI hardware connections
  3. Understand differences between SPI and I2C
  4. Learn to use SPI devices

đŸŽ¯ What is SPI?​

SPI = Serial Peripheral Interface

A Useful Analogy​

Imagine a meeting room:

  • Master = The meeting host
  • Slaves = Meeting participants (can be multiple)
  • MOSI = What the host says
  • MISO = The participants' responses
  • SCLK = Meeting rhythm
  • CS = Calling roll: Only the one called speaks

🔌 SPI Hardware Connections​

Requires 4 wires:

Wire NameFull NameFunction
SCLKSerial ClockClock line
MOSIMaster Out Slave InMaster output, slave input
MISOMaster In Slave OutMaster input, slave output
CSChip SelectChip select (chooses which device to talk to)

Connection Diagram​

Microcontroller      SD Card        OLED Screen
│ │ │
├─ SCLK ───────â”ŧ─ SCLK ───────┤
├─ MOSI ───────â”ŧ─ MOSI ───────┤
├─ MISO ───────â”ŧ─ MISO ───────┤
├─ CS1 ───────┤ │
└─ CS2 ───────────────────────┤

📊 SPI vs I2C Comparison​

FeatureI2CSPI
Wires needed24
Device addressesYes (7-bit/10-bit)No (uses CS)
SpeedSlower (typically 400kHz)Faster (up to several MHz)
CommunicationHalf-duplexFull-duplex
Multiple devicesShared addressingEach device has independent CS
ComplexityMore complexSimple

đŸŽ¯ When to Use SPI?​

Good for SPI:​

  1. Need high-speed transfer: Reading large amounts of data
  2. SD card/W25Q storage: Fast read/write
  3. Displays: Quick screen refreshes

Good for I2C:​

  1. Save pins: Not enough pins available
  2. Many sensors: Temperature, humidity, light, etc.
  3. Low-speed devices: Don't need high speed

🔧 SPI Devices in JoyKit​

Common SPI devices on JoyKit:

DevicePurpose
W25Q32Flash memory (store data, images)
4.3" LCDMain screen display
OLEDSecondary display

đŸ”Ŧ Classroom Demo: Comparing I2C and SPI​

Demo Goal​

Experience the different characteristics of I2C and SPI.

ComparisonI2C SensorSPI Screen
WiresFewMany
SpeedSlowFast
PurposeRead dataWrite display

💡 Memory Aids​

ProtocolCharacteristics
I2CFew wires, has addresses, good for sensors
SPIMany wires, fast speed, good for screens/storage

🎉 Summary​

What we learned today:

  • ✅ SPI is Serial Peripheral Interface
  • ✅ Needs 4 wires: SCLK, MOSI, MISO, CS
  • ✅ SPI is faster than I2C
  • ✅ I2C for sensors, SPI for screens/storage
  • ✅ JoyKit has multiple SPI devices

Next will be comprehensive projects using everything we've learned!