Page 1 of 1

SPI Test

Posted: Mon Mar 21, 2016 3:06 pm
by mschulz
Hello,
to test the SPI Bus, I connectet the X and Y pins.
X8 MOSI -> Y8 MOSI
X7 MISO -> Y7 MISO
X6 SCK -> Y6 SCK

With my code I want send wit SPI X a message to SPI Y and print it.

But I get an OSERROR 116. Why? Where is my mistake?
What must I do with the Slave Select (SS)?

When I connect MISO mit MOSI bei SPI X, I can send and recive a message.

Code: Select all

# main.py -- put your code here!
import pyb

print ('INIT des Schalters')
switch = pyb.Switch()

spi = pyb.SPI(1, pyb.SPI.MASTER, baudrate=600000, polarity=1, phase=0, crc=0x7)
spi2 = pyb.SPI(2, pyb.SPI.SLAVE, baudrate=600000, polarity=1, phase=0, crc=0x7)

buf = bytearray(4)
buf2 = bytearray(4)

print('send 1234 ')
spi.send(b'1234')	
#print('buf',buf)

print(' empfange in buf')	
print('buf',spi2.recv(4))

#print('send 1357 und empfange in buf')
#spi.send_recv(b'1357',buf)	
#print('buf',buf) 

Thank you for your help.

Re: SPI Test

Posted: Mon Mar 21, 2016 6:00 pm
by pythoncoder
OSError 116 is a timeout. You need to connect the master SS to the slave SS - in master mode the firmware should configure SS as an output, and in slave mode it should be an input. I'd be tempted to use a resistor (say 470 ohm to 1K) to make the connection in initial testing in case they somehow both end up as outputs. You may be treading new ground here - people have tried I2C in slave mode but I can't find any references in the forum to anyone using slave mode SPI.