Raspberry Pi SPI does not work: enable it, check /dev/spidev and the chip select

Enable SPI in the configuration tool and reboot. Then check that /dev/spidev0.0 exists.

What the message means

SPI is off by default. Without it the device files are missing and libraries report that no device is found.

Fix it in this order

  1. Run the configuration tool and enable SPI under interfaces.
  2. Reboot the Pi.
  3. List /dev/spidev* and confirm the files exist.
  4. Use bus 0 and device 0 or 1, matching the chip select pin you wired.
  5. Check MOSI, MISO, SCLK and CS wiring against the pin map.
  6. Install the Python spidev package if the import fails.

Why it happens

The SPI controller is switched off in the default Raspberry Pi OS image, so the kernel creates no device nodes. Enabling it in raspi-config under Interface Options, or by adding dtparam=spi=on to the boot configuration file, loads the driver at the next boot. After that /dev/spidev0.0 and /dev/spidev0.1 appear, the last digit being the chip-select line: CE0 for 0 and CE1 for 1.

If the files exist but every read returns zeros or 0xFF, the fault is usually wiring: MOSI and MISO swapped, no common ground, or the chip-select line on the wrong pin. Test with the device’s datasheet read-ID command, which gives a known answer.

If you see this, do this

You seeDo this
No /dev/spidev0.0SPI not enabled.
Reads all zerosWiring or chip select.

Pi I2C not found, RC522 wiring.

Last reviewed: November 2026. These are the usual causes and the order that finds them fastest. Test on your own board; clones and cables differ.

Why this happens

SPI on the Pi is a hardware block that is off in the default image. When it is enabled, the kernel loads the driver and creates /dev/spidev0.0 and /dev/spidev0.1, one for each chip-select line. The kernel drives that chip-select line itself, so if your own code also uses it as an ordinary GPIO output, the two conflict.

On SPI0, the data and clock pins are fixed: MOSI on GPIO 10 (pin 19), MISO on GPIO 9 (pin 21), SCLK on GPIO 11 (pin 23), CE0 on GPIO 8 (pin 24) and CE1 on GPIO 7 (pin 26). A wire on a wrong pin gives an all-zero or all-0xFF reading even though the device files exist.

How to confirm the cause

  • Run ls /dev/spidev* and confirm the files exist.
  • Run lsmod | grep spi to see that the SPI driver is loaded.
  • Look in the boot configuration file for lines that enable or change SPI, such as a dtoverlay that disables a chip-select line.
  • Do a loopback test: join MOSI (pin 19) to MISO (pin 21) with one wire, and send two bytes. You should get them back.
  • Check that your user can open the device without sudo.

Worked example

A loopback test with the spidev module. With pin 19 joined to pin 21 and nothing else attached, the bytes come straight back.

import spidev
spi = spidev.SpiDev()
spi.open(0, 0)              # bus 0, device 0 (CE0)
spi.max_speed_hz = 500000
spi.mode = 0
print(spi.xfer2([0x55, 0xAA]))   # expect [85, 170]
spi.close()

Common mistakes

  • Running at a high clock speed over long jumper wires.
  • Using the wrong SPI mode for the device.
  • Controlling the hardware chip-select pin as a GPIO as well.
  • Connecting a 5 V device directly to 3.3 V GPIO pins.
  • Leaving the loopback wire in place when you connect the real device.

If this did not fix it

  • The device needs a different SPI mode, or a lower speed, which the datasheet states.
  • No common ground or a weak 3.3 V supply to the device.
  • A second device sharing the bus with a chip-select that is not high when idle.