cancel
Showing results for 
Search instead for 
Did you mean: 

i am using LIS3DH with STM32F410 on Nucleo board and my I2C routine can only read one byte of the time, the read is fine but i get ZOR, YOR and XOR. I am supposed to clear these bits after every read or is the read clear the bits ?

DDima.2
Associate

Do you have an I2C routine that can read two byte at a time like OUT_X_L and OUT_X H or a read routine to reada all three values X<Y and Z (6 bytes) ? I am not using HAL, i am using CMSIS.

1 REPLY 1
Eleon BORLINI
ST Employee

Hi @DDima.2​ , about this question:

>> I am supposed to clear these bits after every read or is the read clear the bits?

Do you refer to the content of the STATUS_REG (27h) register? The ZOR, YOR and XOR bits should be reset after the reading of the OUT register, but to avoid sample overrun you can set the BDU bit of CTRL_REG4 (23h) register. In this way the output registers will not be updated until MSB and LSB reading.

About this other request:

>> Do you have an I2C routine that can read two byte at a time like OUT_X_L and OUT_X H or a read routine to reada all three values X<Y and Z (6 bytes)?

You can maybe refer to the github standard C MEMS drivers for LIS3DH. Here below the part of the code for R/W I2C multiple command:

Write multiple command:

/*
 * @brief  Write generic device register (platform dependent)
 *
 * @param  handle    customizable argument. In this examples is used in
 *                   order to select the correct sensor bus handler.
 * @param  reg       register to write
 * @param  bufp      pointer to data to write in register reg
 * @param  len       number of consecutive register to write
 *
 */
static int32_t platform_write(void *handle, uint8_t reg, uint8_t *bufp,
                              uint16_t len)
{
  if (handle == &hi2c1) {
    /* Write multiple command */
    reg |= 0x80;
    HAL_I2C_Mem_Write(handle, LIS3DH_I2C_ADD_L, reg,
                      I2C_MEMADD_SIZE_8BIT, bufp, len, 1000);
  }
  return 0;
}

Read multiple command

/*
 * @brief  Read generic device register (platform dependent)
 *
 * @param  handle    customizable argument. In this examples is used in
 *                   order to select the correct sensor bus handler.
 * @param  reg       register to read
 * @param  bufp      pointer to buffer that store the data read
 * @param  len       number of consecutive register to read
 *
 */
static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,
                             uint16_t len)
{
  if (handle == &hi2c1) {
    /* Read multiple command */
    reg |= 0x80;
    HAL_I2C_Mem_Read(handle, LIS3DH_I2C_ADD_L, reg,
                     I2C_MEMADD_SIZE_8BIT, bufp, len, 1000);
  }
  return 0;
}

Regards