Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Does the SPI interface work for anyone?

    Scheduled Pinned Locked Moved Getting Started
    spi
    7 Posts 4 Posters 1.1k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A Offline
      alidaf
      last edited by

      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?

      A 1 Reply Last reply Reply Quote 0
      • D Offline
        danielm
        last edited by

        I successfully used LoPy4 with CLK on P22, MOSI on P23 and MISO on P21.

        A 1 Reply Last reply Reply Quote 0
        • A Offline
          alidaf @danielm
          last edited by

          @danielm Hi. Still no joy for me. What is your init command like?

          1 Reply Last reply Reply Quote 0
          • A Offline
            alidaf
            last edited by

            @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))
            
            1 Reply Last reply Reply Quote 0
            • A Offline
              alidaf @alidaf
              last edited by

              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))
              
              P 1 Reply Last reply Reply Quote 0
              • P Offline
                PaulM @alidaf
                last edited by

                @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

                P 1 Reply Last reply Reply Quote 0
                • P Offline
                  Paul Thornton @PaulM
                  last edited by

                  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

                  1 Reply Last reply Reply Quote 1

                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                  With your input, this post could be even better 💗

                  Register Login
                  • 1 / 1
                  • First post
                    Last post

                  Pycom on Twitter

                  Pycom