SPI slave device help



  • 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!!



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



  • 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?¿



  • @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.



  • 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


Log in to reply
 

Pycom on Twitter