AnsweredAssumed Answered

LIS3DH Accelerometer read commands only return data from the first register read

Question asked by Rocne Scribner on Jan 20, 2018
Latest reply on Jan 24, 2018 by Miroslav B

Hi everyone,

 

I'm working with a LIS3DH accel and having trouble reading registers. I'm able to successfully read the value from any single register, but all subsequent reads return the same value. I.e. if I read WHO_AM_I register, and then read CTRL_REG1, both read commands return the value from the WHO_AM_I register.

 

Has anyone encountered this before? I'm sure there's a small detail I'm missing.

 

Below is the code for reading a register.

uint8_t lis3dh_read_byte(const lis3dh_reg_addr_t addr) {   uint8_t cmd = 0;      cmd |= LIS3DH_SPI_READ_MASK;   cmd |= (LIS3DH_SPI_ADDRESS_MASK & addr);      HAL_StatusTypeDef status = HAL_ERROR;      while(status == HAL_ERROR)   {     status = HAL_SPI_TransmitReceive(spi, &cmd, rx_buf, 1, SPI_TIMEOUT);   }    return rx_buf[0]; }

 

Here is the datasheet

 

Thanks for any help you can offer!

Outcomes