i want to use multiple SPI busses at the same time.
but when i use to use SPI 4 and SPI 5 at the same time it crashes the whole system
it doesn't crash instantly sometimes it takes 10 seconds sometimes 10 minutes

it works fine if i use any other combination with spi 0,1,4,5
and it only crashes when 4 and 5 are used at the same time

the code

#! /usr/bin/env python3
import random
import spidev
spi = spidev.SpiDev()
spi.open(5, 0)
spi.max_speed_hz = 1500000
spi.mode = 0
data = [0]*120
while True:

when looking for the source of the bug i reduced the code to its minimum
to produce the error i run it in 2 separate terminals
in one terminal i use spi.open(5, 0) and the other spi.open(4, 0) the rest of the code is the same

the error

the raspberry pi is working headless, i run the code and receive the error through ssh
i think ssh crashes before the whole error is transmitted so sometimes the error is shorter, i put the longest version on pastebin
when i connect a monitor to the pi it shows the same message but its scrolling past very fast and i cant scroll back

i have tried

  1. using a different raspberry pi 4
  2. replacing the spidev with busio and similar code
  3. enabling spi using the command line dtoverlay spi5-1cs or by adding dtoverlay=spi5-1cs to /boot/config.txt
  4. using these functions to transfer the data spi.writebytes spi.writebytes2 spi.xfer spi.xfer2 spi.xfer3
  5. changing the data data = [0]*120 or data = random.choices(range(0,255), k=120)
  6. sending 10, 120 or 4096 bytes
  7. setting the CPU governor to performance
  8. setting max_speed_hz to 1500000 or not setting it at all
  • 3
    Get rid of the pastebin which serves no purpose other than to irritate readers. Put the text in your question. Other than that niggle this is a good question.
    – joan
    Sep 27, 2021 at 15:20
  • @joan thank you for the feedback putting the whole error code here would be a bit much i think unless there is a way to fold / hide it, but i want able to find how
    – Ruben
    Sep 27, 2021 at 15:48
  • So are you using AdaFruit software which is not not 100% compatible to Rpi OS?
    – tlfong01
    Sep 28, 2021 at 0:58
  • 1
    @tlfong01 no, i would prefer if it was 100% "normal" python and not circuitpython, i just noticed i typed busio wrong, trying busio was just to rule out a bug in the spidev library and i wasn't able to find an other spi library
    – Ruben
    Sep 28, 2021 at 7:40
  • Well, Rpi4B buster "normal" python has SPI "built in". If you are using third party SPI libraries, AdaFruit or otherwise, you are asking for trouble. I learnt my lesson after wasting some one hundred hours trying to fix compatibility.
    – tlfong01
    Sep 28, 2021 at 8:11

1 Answer 1


From what I've heard, Linux SPI drivers are quite sensitive to CPU frequency changes, and on some systems they are plain broken if you use them together with dynamic frequency scaling. Try setting the CPU governor to performance and see if that helps.

  • 2
    unfortunately setting the CPU governor to performance doesn't seem to change anything
    – Ruben
    Sep 27, 2021 at 13:55
  • @Ruben Sorry then. I knew t he chance for this to be a fix was slim, but then it doesn't take much time to rule it out. Sep 28, 2021 at 9:02
  • No problem, i appreciate you taking the time
    – Ruben
    Sep 28, 2021 at 11:10

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.