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

    SPI slave device help

    Scheduled Pinned Locked Moved MicroPython
    spi
    5 Posts 2 Posters 59 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.
    • DualMaticD Offline
      DualMatic
      last edited by

      Hello guys, I'm seeking help or advice regarding SPI device regs reading or writing.
      I'm struggling with this device:
      https://fscdn.rohm.com/en/products/databook/datasheet/ic/motor/dc/bd16938aefv-c-e.pdf

      I have no experience with SPI devices before and I don't know how to proceed in order to read/write this device specific registers or if I must write before reading an specific register.
      I think my problem is related to understanding the datasheet SPI part explanation (about registers)
      I have the device connected correctly, because read function gives me \ff if disabled and \x0 if enabled (by the devices EN pin.

      Maybe someone here is so kind to point me or give me some advice regarding this device (or help me understand what the datasheet says for this particular device?

      Regards!!

      1 Reply Last reply Reply Quote 0
      • DualMaticD Offline
        DualMatic
        last edited by

        This is my current snippet to read a register by SPI, I don't know if i'm 100% sure if this is a correct way for reading register:

        def reg_read(reg):
            buf = bytearray(1)
            cs(0)
            spi.readinto(buf, write=reg)
            spi.readinto(buf)
            cs(1)
            return buf[0]
        

        So reg_read(0x80) returns 15 but the value returned doesn't correspond with any register on datasheet, I know I'm reading the device because if i remove one of the power rails, the SPI returns 0xFF in all registers

        J 1 Reply Last reply Reply Quote 0
        • J Offline
          jcaron @DualMatic
          last edited by

          @DualMatic apparently that chip uses 16-bit SPI words, did you set bits=16 in your SPI constructor or init?

          Also in your code the second readinto will overwrite the contents of buf.

          1 Reply Last reply Reply Quote 1
          • DualMaticD Offline
            DualMatic
            last edited by

            Hello @jcaron! First,, thank you for your reply.
            I have tried both suggestions but still no-go, I have results on returning buffers but I don't find any result that mimics datasheet default values for registers.

            As my limited SPI knowledge thinks, following the manufacturer datasheet I understand that the device have two write addresses, and 4 read addresses. I'm using the known state (or initial value) in datasheet of the read adresses for comparison.
            As an example for me, the address is defined as:
            404abf4f-c5d9-47d1-a66b-59b59c289da4-image.png
            In this case, I'm using address 0 on my reg_read function

            And with this screenshot:
            3181a300-e69c-4688-8508-8217c1a445a7-image.png
            I'm using address 8192(int) or 0x2000(hex) and the funcion is returning 96(int), so no coincidence with datasheet.

            My SPI understood flow is that I need to put the address as write parameter under instruction spi.readinto() but maybe here is my error?¿

            J 1 Reply Last reply Reply Quote 0
            • J Offline
              jcaron @DualMatic
              last edited by

              @DualMatic since the chip using 16-bit words you should provide a 2-byte buffer for the data being read.

              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