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

    Using SPI on SyPy

    Scheduled Pinned Locked Moved Discussion
    spisypy
    6 Posts 2 Posters 863 Views 2 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 just can't seem to get SPI working on the SyPy. I am trying to use I2C as well but due to the conflicting pins, I have shifted the I2C pins to P8 and P9 and it works fine.

      For CS I have tried P12 and P23. Using P12 causes problems when uploading code probably because it keeps the pin high, which causes a firmware downgrade. Pins 13-18 are input only so can't be used. Pins 5-7 are SPI but connected to the Sigfox module. I don't think I can use pins 0-4 either so it doesn't leave much room for manoeuvre.

      I am using the default pins for CLK, MOSI and MISO, i.e. 10, 11 & 14.

      Is there some other connectivity that I am missing?

      robert-hhR 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @alidaf
        last edited by

        @alidaf Pins 10,11,14 should work. Pin 14 has no internal pull-up, so you have to supply an external one.

        A 1 Reply Last reply Reply Quote 0
        • A Offline
          alidaf @robert-hh
          last edited by

          @robert-hh I've moved MISO to pin 21 but still no joy.

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

            I am testing with the following code:

            from machine import Pin
            from machine import SPI
            
            #import binascii
            
            #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))
            
            
            robert-hhR 1 Reply Last reply Reply Quote 0
            • robert-hhR Offline
              robert-hh @alidaf
              last edited by

              @alidaf Strange. Dou you have a means of testing the communication, like a logic analyzer (Saleae clone?)

              A 1 Reply Last reply Reply Quote 0
              • A Offline
                alidaf @robert-hh
                last edited by

                @robert-hh Unfortunately not although I have converted the code to Arduino C++ and used it on an Adafruit Feather with no problem.

                1 Reply Last reply Reply Quote 0

                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