I need to use SPI for a project I'm working on with a Raspberry PI, but the little bit of test code I wrote doesn't seem to work.
#test program for spi
import spidev
import RPi.GPIO as GPIO
from time import sleep
bus = 0 #always 0, apparently
device = 0 #we will use our own CS pin
mode = 3 #see SPI modes
maxSpeed = 100000 #maximum clock speed in Hz
noCs = True #hardware CS
lsbFirst = False #MSB first is default
##############################################################
CS_PIN = 24 #CS pin number
WRITE_DATA = [0x4D, 0x4D, 0x4D]
##############################################################
if __name__ == '__main__':
#config GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(CS_PIN, GPIO.OUT)
GPIO.setwarnings(False)
GPIO.output(CS_PIN, True)
#config SPI
spi = spidev.SpiDev()
spi.open(bus, device)
spi.mode = mode
spi.no_cs = noCs
spi.lsbfirst = lsbFirst
spi.max_speed_hz = maxSpeed
#run SPI
GPIO.output(CS_PIN, False)
spi.xfer(WRITE_DATA)
GPIO.output(CS_PIN, True)
sleep(0.1)
#print data
'''
listLen = len(readbytes)
print("Lenght: ", listLen)
i = 0
while i < listLen:
print("Byte ", i, ": ", readbytes[i])
i += 1
'''
GPIO.cleanup()
I'm using an external CS because I need to connect multiple devices to this SPI bus. I probed the SPI signals with an oscilloscope. I see the CS go low and then high, but there is no switching activity on SCK, MOSI, or MISO, they just stay high.
I am using the Adafruit T-Cobbler Plus for RPi, and I am probing the correct pins (they shouldn't be high if they weren't the correct pins.
Can anyone help me with this?