I'm trying to read a SPI sensor via the raspberry pi, but I seem to be getting strange voltage levels on the MOSI line and no response on the MISO line. The chip-select line and clock lines make sense.

enter image description here

The kernel module appears loaded:

$ ls -l /dev/spi* 
crw-rw-rw- 1 root spi 153, 0 Aug  8 09:17 /dev/spidev0.0
crw-rw-rw- 1 root spi 153, 1 Aug  8 09:17 /dev/spidev0.1
$ lsmod | grep spi
spidev                 20480  0
spi_bcm2835            20480  0
$ modinfo spidev
filename:       /lib/modules/4.19.57-v7+/kernel/drivers/spi/spidev.ko
alias:          spi:spidev
license:        GPL
description:    User mode SPI device interface
author:         Andrea Paterniani, <[email protected]>
srcversion:     4EE702C8B42456520F93538
alias:          of:N*T*CspidevC*
alias:          of:N*T*Cspidev
alias:          of:N*T*Csemtech,sx1301C*
alias:          of:N*T*Csemtech,sx1301
alias:          of:N*T*Cge,achcC*
alias:          of:N*T*Cge,achc
alias:          of:N*T*Clineartechnology,ltc2488C*
alias:          of:N*T*Clineartechnology,ltc2488
alias:          of:N*T*Crohm,dh2228fvC*
alias:          of:N*T*Crohm,dh2228fv
intree:         Y
name:           spidev
vermagic:       4.19.57-v7+ SMP mod_unload modversions ARMv7 p2v8 
parm:           bufsiz:data bytes in biggest supported SPI message (uint)

I don't get any errors on initializing the module:

import spidev

class RpiSpi():

    BUS_SPEED_HZ = 100000
    MODE = 0

    def __init__(self, bus, device):
        # Enable SPI
        self._spi = spidev.SpiDev()

        # Open a connection to a specific device (chip-select pin)
        # and bus.  There are two buses available.
        self._spi.open(bus, device)

        # Set SPI speed and mode
        self._spi.max_speed_hz = RpiSpi.BUS_SPEED_HZ
        self._spi.mode = RpiSpi.MODE

    def write_reg(self, reg, value):
        self._spi.xfer2([reg, value])

    def read_reg(self, reg):
        response = self._spi.xfer2([reg, 0x00])
        return response[1]

sensor = RpiSpi()
sensor.write_reg(0x70, 0b01000000)
while True:

I've tried all permutations of mode and bus/device combos.

The MOSI line on an oscilloscope looks weird (2.5 V in some places when I would expect 3.3 V):

Hardware: Raspberry Pi 3 Model B V1.2

spidev module documentation: http://tightdev.net/SpiDev_Doc.pdf

Pinout: enter image description here


1 Answer 1


This problem was sensor-dependent, thanks. It turned out I needed to control the power sequencing so that I could put it into SPI mode instead of I2C mode very soon after powering on the sensor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.