gercha2 wrote: ↑Sun Mar 26, 2017 7:48 pm
Thank you!!!, I solved it. At last I got: "/x01/x02/x03/x04"
I didn´t know where to put (spi.deinit), because I got a Type Error. So fortunately your ad was very useful. I missed where SPI stops reading for synchronization. Then I follow some procedures described in:
https://docs.micropython.org/en/latest/ ... b.SPI.html
Pyboard as Slave receiving data from Raspberry pi 2(SPI - Master):
1. import SPI from pyb
2. SPI initialization (e.g. spi = SPI(2,SPI.SLAVE, baudrate=16000000, polarity=0, phase=0,...); I pesonally used SPI(2)
(Important to both MASTER and SLAVE be matched in Polarity and phase) as mention Turbinenreiter:
Conclusion:
* make sure you are using the same mode on both devices
* deinit the spi object before you reload the script with a changed SPI mode
3. receive data from Master (Depend on the number of bytes to receive)
4. spi.deinit()
5. print(data)
Hi, gercha2, i meet the same problem with you, i have set both SPI-Master(Raspberry) and SPI-Slave(Pyb) work on SPI mode 0, and close it after receive, but it still error:
1. if the master send b'1234', then the slave receive b'4123'
2. if the master send b'abcdefgh', then the slave receive b'habcdefg'
Besides, i found that spi.recv() of pyb can't work in the callback function, i can only use it with while loop, can you paste both of your error code and the correct code after change?
here is my code that with the same problem:
from pyb import SPI, ExtInt, Pin
import time
spi = pyb.SPI(2)
trg = pyb.Pin(pyb.Pin.cpu.A6, Pin.IN, pull=Pin.PULL_UP)
def spi_recv(spi_slave=spi):
spi_slave.init(pyb.SPI.SLAVE, polarity=0, phase=0,bits=8, firstbit=SPI.MSB, crc=None)
buf = spi_slave.recv(8,timeout=5000)
print(buf)
spi_slave.deinit()
while True:
while not trg.value():
spi_recv()
time.sleep_us(1000)