cthomas
Posts: 2
Joined: Wed Mar 25, 2020 9:17 pm

How To Manually Bring Slave Select Low (SPI)

Wed Mar 25, 2020 10:54 pm

I am a beginner at raspberry pi and SPI and have two questions:
1. How do you manually bring chip select low? I am currently using a random GPIO pin that is not being used and bringing it low. I am not sure, however, if the driver will recognize that as the slave/chip select.
2. Is there a way to wait a certain amount of time between bytes during the transfer of a frame?
- I am currently using spidev but open to using any library. Is there another library more appropriate with good documentation?
- Raspberry Pi 3 Model B

This is what I currently have:

Code: Select all

import spidev
import time
import RPi.GPIO as GPIO 

GPIO.setmode(GPIO.BOARD)
GPIO.setup(37,GPIO.OUT)

spi = spidev.SpiDev()
ret = spi.open(0,0)
spi.max_speed_hz = 80000
spi.mode = 3


 
if  __name__ == "__main__":
	data_out = [0x01, 0x42, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
	while True:
		GPIO.output(37, GPIO.LOW)
		time.sleep(1/1000)
		for i in data_out:
			data_in = spi.xfer2(data_out)
			time.sleep(1/20000000)
			print(data_in)
		GPIO.output(37, GPIO.LOW)
		time.sleep(1)
Last edited by cthomas on Thu Mar 26, 2020 1:37 am, edited 1 time in total.

User avatar
DougieLawson
Posts: 37489
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: How To Manually Bring Slave Select Low

Wed Mar 25, 2020 11:49 pm

What's your SPI device?

Why don't you want to use the spi.xfer() or spi.xfer2() functions which do all the CS/MISO/MOSI stuff for you using the spidev driver?
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

cthomas
Posts: 2
Joined: Wed Mar 25, 2020 9:17 pm

Re: How To Manually Bring Slave Select Low

Thu Mar 26, 2020 1:30 am

Thanks for the response. I want to be able to wait 1ms after bringing CS low before sending the first byte of data. I am unable to do that with xfer2.

User avatar
joan
Posts: 14747
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: How To Manually Bring Slave Select Low (SPI)

Thu Mar 26, 2020 6:28 am

You need to bring the pin high after the transaction.

Return to “Interfacing (DSI, CSI, I2C, etc.)”