0

I am currently attempting to send and receive data from SPI0 to SPI1 on a singular raspberry pi.

My Current code is as follows;

from multiprocessing import Process
import spidev
import time
import sys
import RPi.GPIO as GPIO
import pigpio

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)

GPIO.setup(27, GPIO.OUT)
GPIO.setup(22, GPIO.OUT)
GPIO.output(27, GPIO.LOW)
GPIO.output(22, GPIO.HIGH)

master_spi = spidev.SpiDev()
slave_spi = spidev.SpiDev()

def master():
master_spi = spi.SpiDev()
master_spi.open(0, 0)

while True:
master_spi.max_speed_hz = 900000

def slave():
slave_spi = spidev.SpiDev()
slave_spi.open(1, 0)

while True:
resp = slave_spi.xfer([255])
print(resp[0])
time.sleep(1)

if __name__ == "__main__":
p1 = Process(target = master)
p2 = Process(target = slave)
p1.start()
p2.start()

At the moment, although both the slave and master can run at the same time, being able to send and recieve data between the two cannot happen.

Currently, the pins are connected as follows:

SPI0 MOSI (GPIO10) - SPI1 MOSI (GPIO20)
SPI0 MISO (GPIO9) - SPI1 MISO (GPIO19)
SPI0 SCLK (GPIO11) - SPI1 SCLK (GPIO21)
SPI0 CS0 (GPIO8) - SPI1 CS0 (GPIO16) 

Any pointers, suggestions, or help would be great. Thank you.

3
  • 2
    Can't be done. The Pi's hardware/software only supports SPI master mode. To communicate one end needs to be the master and the other end needs to be a slave.
    – joan
    Commented Jan 11 at 20:17
  • What are you actually trying to do. Sending to itself seems pointless.
    – Milliways
    Commented Jan 11 at 23:00
  • Does this answer your question? SPI sending and receiving data
    – Dougie
    Commented Jan 12 at 0:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.