"Write from register" and "read from register" SPI implementation.
I'm trying to implement two functions mentioned in the topic.
def cam_spi_write(address, value, hspi, cspin): modebit = b'\x80' cspin.value(0) hspi.write(modebit) hspi.write(address) hspi.write(value) cspin.value(1) def cam_spi_read(address, hspi, cspin): cspin.value(0) maskbits = b'\x9f' hspi.write(b'\x80') hspi.write(address) hspi.write(maskbits) buf = hspi.read(1) return (buf)
But it doesn't work. I've used an SPI instructions tutorial:
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 | addrs]) cs.value(0) spi.write(addres) machin spi.write(value) cs.value(1) def cam_spi_read_single(addrs, spi, cs): cs.value(0) spi.write(addrs) 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...