class LIS2DH_Class(object): mySpi = 0 def __init__(self): self.spi = spidev.SpiDev() self.spi.open(0,0) self.spi.max_speed_hz = 10000000 #10 Mhz is max limit on LIS2DH SPI communication def whoAmI(self): resp = self.spi.xfer2([0x8f,0x8f]) return resp print accel.whoAmI()
above is the code i wrote for an LIS2DH accelerometer. 0x0F is the whoami register. I'm bitwise OR with 0x80 to send a read command, followed by the register address. see protocol below;
this code above will return [255,51]
51 is the expected value, 255 is garbage. How can i reduce a read command to just sending 1 byte?