spurious low pulse on SPI0:CS output

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
MikeDmnb
 
Posts: 3
Joined: Wed Nov 02, 2022 3:12 am

spurious low pulse on SPI0:CS output

Post 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. https://github.com/doceme/py-spidev/issues/113 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!!!

Mike.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: spurious low pulse on SPI0:CS output

Post 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:

https://github.com/adafruit/Adafruit_Python_GPIO

and has been superseded by Blinka:

https://github.com/adafruit/Adafruit_Blinka

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

User avatar
MikeDmnb
 
Posts: 3
Joined: Wed Nov 02, 2022 3:12 am

Re: spurious low pulse on SPI0:CS output

Post 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():
pass
spi.configure(baudrate=100000)


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

spi.write_readinto(bytes(x),f)
print(x,f)
time.sleep(0.01)

spi.unlock()

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.
regards,
Mike.

User avatar
MikeDmnb
 
Posts: 3
Joined: Wed Nov 02, 2022 3:12 am

Re: spurious low pulse on SPI0:CS output

Post by MikeDmnb »

Interesting to note, SPIDEV3.5 does not have this issue.

Locked
Please be positive and constructive with your questions and comments.

Return to “Beagle Bone & Adafruit Beagle Bone products”