ESP32 FAQ

ESP32 SPI: Pins, Modes, Wiring

// spi · faq

Filed under: ESP32 · SPI · Updated August 2026

SPI is the fast one — full duplex, tens of MHz, one chip-select line per device. This covers the classic pin defaults, the four SPI modes, wiring a display or sensor, and the quad SPI question that keeps coming up.

How Would I Use Quad SPI ESP32?

In practice: almost never directly. Quad SPI (QSPI) is how the chip talks to its own external flash — four data lines instead of one — and the ROM bootloader handles it before your code exists. If you asked because you want extra storage, a plain SPI flash chip wired to VSPI is far easier to use from Arduino; quad SPI is for custom hardware and PSRAM designs.

Which pins does the ESP32 use for SPI by default?

Classic ESP32 devkits default to VSPI: SCLK 18, MISO 19, MOSI 23, SS 5. HSPI sits on pins 14, 12, 13, 15. The S2, S3, and C3 families rearrange everything, so check pins_arduino.h for your exact board — the classic numbers are wrong there. Our SPI pinout guide in the KB tracks the per-board tables.

What are SPI modes 0, 1, 2, 3?

They set clock polarity (CPOL) and phase (CPHA). Mode 0 — clock idle low, data sampled on the rising edge — is what most sensors expect. In practice, 90% of breakout boards run mode 0; when a device returns garbage, try mode 1 or 3 before suspecting wiring. Your mileage varies per chip.

How do I wire an SPI device?

Three wires are shared by every device on the bus — SCLK, MOSI, MISO — plus one chip-select (CS) pin per device, each on its own GPIO. Pull CS high by default; it goes low to talk to a specific device. Keep leads short: SPI at 26 MHz over 30 cm of dupont wire is asking for trouble.

Can I use any GPIO for SPI?

Yes — SPI.begin(sck, miso, mosi, ss) remaps any four pins you like. Avoid strapping pins (GPIO0, 2, 12 on classic) and, on WROVER modules, the pins PSRAM owns. Mostly works on any free set; I run my second TFT on HSPI pins 14/12/13/15 and it has been stable for a year.

SPI or I2C — which bus for my project?

SPI wins on speed and simplicity per device; I2C wins on wires and device count. A 2.4-inch TFT redraws visibly faster over SPI, while four sensors on one breadboard are easier over I2C. If you move frames or audio, SPI; if you move a few bytes now and then, I2C. You can compare both in the free ESP32 simulator before picking.

My SPI device returns garbage — what do I check?

Mode mismatch is the number one cause; a CS line that never asserts is number two. Then check swapped MISO/MOSI, 5V logic on a 3.3V input, and clock speed. My ILI9341 showed random snow at 40 MHz and was perfectly clean at 26 MHz — wiring, not the chip. The debugging article has the systematic checklist.

How fast is SPI on the ESP32?

The hardware handles 80 MHz for flash reads, and peripheral SPI is typically happy at 26-40 MHz. The real limit is your wiring: breadboard capacitance and long leads cap you well below the chip’s maximum. Depends on your board and how you wire it, honestly.

Can I run SPI and I2C at the same time?

Yes — they are independent hardware controllers, and the Arduino core does not care if both are active. Keep them on separate pin groups and never share a pin between the two buses. One exception to watch: some modules pull certain strapping pins, so read the under-the-hood deep dive before finalizing pin assignments.

Do I need pull-ups or level shifters for SPI?

No pull-ups — SPI is push-pull, unlike I2C’s open-drain lines. Level shifting is another story: a 5V sensor board feeding 5V into an ESP32 GPIO is the quickest way to kill a pin. Classic ESP32 is not 5V tolerant, so check the module’s logic level before wiring anything.

Watch SPI Frames on the Wire — In Your Browser

Protocol modes click when you can see the bus talk:

========================
  SPI Protocol Test
========================
SPI initialized.
Clock divider: 16

A loopback that echoes means the peripheral, the pins and the mode bits agree; one that returns garbage tells you mode/polarity questions from this FAQ are live and debuggable — no scope required.

Leave a Reply

Your email address will not be published. Required fields are marked *