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

    "Write from register" and "read from register" SPI implementation.

    Scheduled Pinned Locked Moved WiPy 2&3
    2 Posts 1 Posters 222 Views 1 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.
    • E Offline
      EngeenerAtendee
      last edited by EngeenerAtendee

      Hi guys!

      I'm trying to implement two functions mentioned in the topic.

      My code:

      def cam_spi_write(address, value, hspi, cspin):
          modebit = b'\x80'
          cspin.value(0)
          hspi.write(modebit[0])
          hspi.write(address[0])
          hspi.write(value[0])
          cspin.value(1)
      
      def cam_spi_read(address, hspi, cspin):
          cspin.value(0)
          maskbits = b'\x9f'
          hspi.write(b'\x80')
          hspi.write(address[0])
          hspi.write(maskbits[0])
          buf = hspi.read(1)
          return (buf)
      

      But it doesn't work. I've used an SPI instructions tutorial:
      Link
      But somewhere I'm wrong. Has anyone tried to do that?

      1 Reply Last reply Reply Quote 0
      • E Offline
        EngeenerAtendee
        last edited by

        I've made some steps. Code looks now like :

        def cam_spi_write_register(addrs, value, spi, cs):
            mask = b'\x80'
            addres = bytes([mask[0] | addrs[0]])
            cs.value(0)
            spi.write(addres[0])
            machin
            spi.write(value[0])
            cs.value(1)
        
        def cam_spi_read_single(addrs, spi, cs):
            cs.value(0)
            spi.write(addrs[0])
            buf = spi.read(1)
            cs.value(1)
            print(buf)
            return(buf)
        

        but it still don't work. I made it working for a while but i forgot to push it on my repo and all code is lost...

        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