cancel
Showing results for 
Search instead for 
Did you mean: 

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

Rocne Scribner
Associate
Posted on January 20, 2018 at 00:04

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]; }

http://www.st.com/content/ccc/resource/technical/document/datasheet/3c/ae/50/85/d6/b1/46/fe/CD00274221.pdf/files/CD00274221.pdf/jcr:content/translations/en.CD00274221.pdf

Thanks for any help you can offer!

#lis3dh-spi #lis3dh #lis3dh-read
1 REPLY 1
Miroslav BATEK
ST Employee
Posted on January 24, 2018 at 11:27

I think the problem is related tho the microcontroller in particular to the SPI, not to the sensor.

Can you please try to use two commands  HAL_SPI_Transmit and HAL_SPI_Receive instead of HAL_SPI_TransmitReceive.