2018-01-19 03:04 PM
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]; }
Thanks for any help you can offer!
#lis3dh-spi #lis3dh #lis3dh-read2018-01-24 02:27 AM
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.