I am trying to use a new raspi 4 to talk with another microprocessor. I would like to use the SPI protocol to communicate. I am having issues with the spidev trans and trans2 functions when sending out simple values ( like number ascii in hex 0X31 ). With or without the wires connected to the microprocessor there is a second chip select pulse. I have tried looking at the raspi forums, and stackoverflow, but I can’t seem to find a solution. I have looked and searched in core electronic forums, and did not see anything there. I don’t want to use a “gpio pin” for the chip select due to the amount of time it takes for the pin to toggle on and off ( what should be 60usec for spi, turns into almost 115 usec with second pulse, which turns into 185 usec using a gpio pin).
I have just started using the raspi 4 boards after I watched the oakd video, and purchased an oak d to put on my rover, so I am not that great at programming in Python, but it is a very simple test to see if all of the spi functions are working. This is the code:
import spidev
import time
import RPi.GPIO as GPIO
spi = spidev.SpiDev() # create spi object
#GPIO.setmode(GPIO.BCM)
#GPIO.setmode(GPIO.BOARD)
#GPIO.setup(22, GPIO.OUT, initial=GPIO.HIGH)
spi.open(0, 0) # open spi port 0, device (CS) 1
#spi.max_speed_hz =1000000
spi.max_speed_hz =500000
#try:
#GPIO.setup(22, GPIO.OUT)
#GPIO.output(22, GPIO.HIGH)
while True:
#GPIO.output(22, GPIO.LOW)
# resp = spi.xfer2([0x35,0x41,0x42]) # transfer one byte
# resp = spi.xfer2([0x35,0x41,0x42],1) # transfer one byte
# time.sleep(0.0001) # sleep for 0.1 seconds
resp = spi.xfer([0x36]) # transfer one byte
#resp = spi.xfer([0x44]) # transfer one byte
#resp = spi.xfer([0x45]) # transfer one byte
# GPIO.output(22, GPIO.HIGH)
time.sleep(.5) # sleep for 0.1 seconds
# GPIO.output(22, GPIO.LOW)
# resp = spi.xfer2([0x35,0x41,0x42]) # transfer one byte
# resp = spi.xfer2([0x35,0x41,0x42],1) # transfer one byte
# time.sleep(0.0001) # sleep for 0.1 seconds
resp = spi.xfer([0x31]) # transfer one byte
#resp = spi.xfer([0x44]) # transfer one byte
#resp = spi.xfer([0x45]) # transfer one byte
# GPIO.output(22, GPIO.HIGH)
time.sleep(.5) # sleep for 0.1 seconds
# GPIO.output(22, GPIO.LOW)
# resp = spi.xfer2([0x35,0x41,0x42]) # transfer one byte
# resp = spi.xfer2([0x35,0x41,0x42],1) # transfer one byte
# time.sleep(0.0001) # sleep for 0.1 seconds
resp = spi.xfer([0x32]) # transfer one byte
#resp = spi.xfer([0x44]) # transfer one byte
#resp = spi.xfer([0x45]) # transfer one byte
# GPIO.output(22, GPIO.HIGH)
time.sleep(.5) # sleep for 0.1 seconds
#end while
#except KeyboardInterrupt: # Ctrl+C pressed, so…
spi.close() # … close the port before exit
#end try
Again, just trying to send simple hex values out. This appears to be a very old problem, possibly dating back to 2012, but I still can’t seem to find a solution–that I can implement.