rpi-firmware icon indicating copy to clipboard operation
rpi-firmware copied to clipboard

SPI stopped working on Rpi B1 from 4.9.43+ onwards

Open ghost opened this issue 8 years ago • 8 comments

Hello, SPI stopped working for me in the latest Raspbian stretch update. So I went back through the kernel versions here bisecting until I found the latest working version. Latest working version for me is 4.9.41+, it does not work in 4.9.43+ anymore. Is there a benign explanation? Did I miss a required configuration change? Best regards, Max

ghost avatar Nov 07 '17 13:11 ghost

File this in https://github.com/raspberrypi/linux/issues and I'll be happy to help.

pelwell avatar Nov 07 '17 13:11 pelwell

Giving the timing I think you have been negatively affected by this commit: https://github.com/raspberrypi/linux/commit/3b1e49ba1a8e5853c75914eee12000aa18ada46d

Unfortunately the SPI subsystem doesn't allow a default value to be specified - the maximum is used instead - so increasing the maximum has also increased the default.

Which SPI library are you using? Whichever it is, it is failing to choose a sensible bus speed.

pelwell avatar Nov 07 '17 13:11 pelwell

I followed the instructions here years ago https://www.raspberrypi-spy.co.uk/2014/08/enabling-the-spi-interface-on-the-raspberry-pi/ and also remember using this one https://github.com/lthiery/SPI-Py.git but I am not actually sure. Which SPI library is recommended or up to date?

ghost avatar Nov 07 '17 14:11 ghost

Some application must be failing, otherwise you wouldn't know that SPI is broken. Which application is it?

pelwell avatar Nov 07 '17 14:11 pelwell

pip install spidev -U updated to latest version 3.2 Still not working.

It is a simple python script reading from mcp3008 A/D chip


import spidev
import time
import os

# Open SPI bus
spi = spidev.SpiDev()
spi.open(0,0)

# Function to read SPI data from MCP3008 chip
# Channel must be an integer 0-7
def ReadChannel(channel):
  adc = spi.xfer2([1,(8+channel)<<4,0])
  data = ((adc[1]&3) << 8) + adc[2]
  return data

....

ghost avatar Nov 07 '17 15:11 ghost

Add:

spi.max_speed_hz = 500000

after spi.open to restore the old default/maximum speed.

pelwell avatar Nov 07 '17 15:11 pelwell

That fixed it. Thank you!

ghost avatar Nov 07 '17 15:11 ghost

This issue has been resolved and the GitHug user account has been deleted, therefore it says @ghost. Please close this issue.

Ruffio avatar Aug 26 '20 14:08 Ruffio