Page 1 of 1

spurious low pulse on SPI0:CS output

Posted: Wed Nov 02, 2022 3:41 am
by MikeDmnb
Due to the shortage of Raspberry Pi's I bought a beaglebone black, and am trying to move my python code to the new platform. This code uses the SPI port to communicate with a battery management chip.
During testing I found that not only do you have to manually re-allocate the function of the SPI port pins with config-pin (os calls), but also the CS pin has a spurious pulse, identical to that found with the spidev driver used on the raspberry pi. has the details and the cure - which was commenting out some lines of C code in the driver module, and re-compiling. I suspect that the Adafruit BBIO code needs the same fix. However, there does not seem to be a link to the source code for the Adafruit module, so the fix must come from the module maintainer.

source code snipit:
// WA:
// in CS_HIGH mode CS isn't pulled to low after transfer, but after read
// reading 0 bytes doesnt matter but brings cs down
// tomdean:
// Stop generating an extra CS except in mode CS_HOGH
if (self->mode & SPI_CS_HIGH) status = read(self->fd, &rxbuf[0], 0);

the above line needs to be commented out for sip.xfer, spi.sfer2.

Open source coding is wonderful - the same bugs show up in many places!!!


Re: spurious low pulse on SPI0:CS output

Posted: Wed Nov 02, 2022 5:25 pm
by adafruit_support_mike
Good information, thank you!

I'll pass this along to the folks who handle the BBIO code.

FWIW, this library is deprecated:

and has been superseded by Blinka:

I'll have that team check to see if the fix is relevant there.

Re: spurious low pulse on SPI0:CS output

Posted: Wed Nov 02, 2022 7:50 pm
by MikeDmnb
Thanks Mike,
Just looking into Blinka's busio & bitbangio:
looks like it is not possible to run both SPI0 and SPI1 (on which subject where is CS1 for SPI 0 and SPI1?)
as there is no instruction as to which SPI port to use.. (noting HDMI needs to be disabled for using SPI1)
having access to both would be useful.
spi.xfer() has been replaced with write_readinto() which seems a backwards step...

I tried this with the following, and got no output:-
import time
import board
import busio
import os

os.system("config-pin P9.17 spi_cs")
os.system("config-pin P9.18 spi")
os.system("config-pin P9.21 spi")
os.system("config-pin P9.22 spi_sclk")

spi = busio.SPI(board.SCLK, board.MOSI, board.MISO)
while not spi.try_lock():

f = 0
while True:
x +=1
if x>255:



fails both with and without the os calls. (by fails, the program runs ok, but there is no output on the spi pins of the BBB.

Re: spurious low pulse on SPI0:CS output

Posted: Fri Nov 04, 2022 3:51 pm
by MikeDmnb
Interesting to note, SPIDEV3.5 does not have this issue.