Does the SPI interface work for anyone?
-
I abandoned a SyPy project because I can't get the SPI to work even though the peripheral works fine on an Adafruit Feather. I thought this might be due to the Sigfox component hogging the resource. I have since borrowed a WyPy and I still can't get it to work.
Does anyone have a third party peripheral working with the SPI interface using non-default pins?
-
Re: @paulm Just to note for others. a fix for the SPI issue has finally been snuck in, should be out in the next RC build
-
@alidaf I can help. Pycom's screwed-up and shockingly still-unfixed SPI library implements a read() function that totally ignores the write=parameter. At least this is not as bad as the LTE situation. Here was my workaround for an SD card using it: https://forum.pycom.io/topic/4000/fixed-broken-sdcard-py-library-previously-impossible-to-have-external-spi-usd-card-with-pycom-boards
-
My test code is:
from machine import Pin from machine import SPI #SPI pins. SPI_CS = 'P23' SPI_MOSI = 'P11' SPI_MISO = 'P22' SPI_CLK = 'P10' REGISTER_TEST = 0x00 REGISTER_WRITE_BIT = 0x80 REGISTER_READ_MASK = 0x7f SPI_LOW = 0 SPI_HIGH = 1 spi_cs = Pin(SPI_CS, mode = Pin.OUT) spi_cs.value(SPI_HIGH) spi = SPI(0, mode=SPI.MASTER, baudrate=1000000, pins=(SPI_CLK, SPI_MOSI, SPI_MISO)) # Test register should return whatever value is written to it. for data in range(0, 0x7e): spi_cs.value(SPI_LOW) print("Writing 0x{:02x} to register 0x{:02x}".format(data, REGISTER_TEST)) wbuf = bytes([REGISTER_TEST | REGISTER_WRITE_BIT, data]) # Write data into register. spi.write(wbuf) # Read data from register. #spi.write(bytes([REGISTER_TEST & REGISTER_READ_MASK])) #rbuf=spi.read(1) tbuf = bytes([REGISTER_TEST & REGISTER_READ_MASK]) rbuf = spi.read(1, write=tbuf[0]) #numRead = spi.readinto(rbuf, write=tbuf[0]) spi_cs.value(SPI_HIGH) print("Read 0x{:02x} from register 0x{:02x}".format(rbuf[0], REGISTER_TEST))
-
@danielm My init, using your pins, is:
SPI_CS = 'P10' SPI_MOSI = 'P23' SPI_MISO = 'P21' SPI_CLK = 'P22' SPI_LOW = 0 SPI_HIGH = 1 spi_cs = Pin(SPI_CS, mode = Pin.OUT) spi_cs.value(SPI_HIGH) spi = SPI(0, mode=SPI.MASTER, baudrate=1000000, pins=(SPI_CLK, SPI_MOSI, SPI_MISO))
-
@danielm Hi. Still no joy for me. What is your init command like?
-
I successfully used LoPy4 with CLK on P22, MOSI on P23 and MISO on P21.