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



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



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


Log in to reply
 

Pycom on Twitter