Lesson 6: SPI Communication - High-Speed Data Transfer
đ Learning Objectivesâ
- Understand what SPI protocol is
- Learn about SPI hardware connections
- Understand differences between SPI and I2C
- 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 Name | Full Name | Function |
|---|---|---|
| SCLK | Serial Clock | Clock line |
| MOSI | Master Out Slave In | Master output, slave input |
| MISO | Master In Slave Out | Master input, slave output |
| CS | Chip Select | Chip 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â
| Feature | I2C | SPI |
|---|---|---|
| Wires needed | 2 | 4 |
| Device addresses | Yes (7-bit/10-bit) | No (uses CS) |
| Speed | Slower (typically 400kHz) | Faster (up to several MHz) |
| Communication | Half-duplex | Full-duplex |
| Multiple devices | Shared addressing | Each device has independent CS |
| Complexity | More complex | Simple |
đ¯ When to Use SPI?â
Good for SPI:â
- Need high-speed transfer: Reading large amounts of data
- SD card/W25Q storage: Fast read/write
- Displays: Quick screen refreshes
Good for I2C:â
- Save pins: Not enough pins available
- Many sensors: Temperature, humidity, light, etc.
- Low-speed devices: Don't need high speed
đ§ SPI Devices in JoyKitâ
Common SPI devices on JoyKit:
| Device | Purpose |
|---|---|
| W25Q32 | Flash memory (store data, images) |
| 4.3" LCD | Main screen display |
| OLED | Secondary display |
đŦ Classroom Demo: Comparing I2C and SPIâ
Demo Goalâ
Experience the different characteristics of I2C and SPI.
| Comparison | I2C Sensor | SPI Screen |
|---|---|---|
| Wires | Few | Many |
| Speed | Slow | Fast |
| Purpose | Read data | Write display |
đĄ Memory Aidsâ
| Protocol | Characteristics |
|---|---|
| I2C | Few wires, has addresses, good for sensors |
| SPI | Many 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!