AnsweredAssumed Answered

LIS331HH Offset in Z-direction

Question asked by brandl.mathias on Oct 19, 2016
Latest reply on Oct 25, 2016 by Miroslav B
Hello,

I have a problem with the LIS331HH Sensor.
The X and Y direction are send correctly to my microcontroller, only the Z value has an offset.
I've tried different LIS331HH and the offset is not always the same, so I don't think that I have an error in my code, and when I change the resolution, I have the same offset, e.g. 2 m/s².

Here are samples of my code:
/* Registers */
volatile static uint8_t ACCEL_ADDRESS = 0x30;
 
volatile static uint8_t CTRL_REG1 = 0x20;
volatile static uint8_t CTRL_REG4 = 0x23;
 
//CTRL_REG1
volatile static uint8_t MODE_NORMAL = 0x20;
volatile static uint8_t ODR_1000Hz = 0x18;
volatile static uint8_t Xen = 0x01;
volatile static uint8_t Yen = 0x02;
volatile static uint8_t Zen = 0x04;
 
//CTRL_REG4
volatile static uint8_t FS_24G = 0x30;
 
//For Result
volatile static uint8_t OUT_X_L = 0x28;
 
 
/* Variables */
volatile static int16_t X, Y, Z;
static uint8_t Accels[6] = { 0, 0, 0, 0, 0, 0 };
 
 
/* Init */
uint8_t ctrl_reg1 = MODE_NORMAL | ODR_1000Hz | Xen | Yen | Zen;
HAL_I2C_Mem_Write(&hi2c1, ACCEL_ADDRESS, CTRL_REG1, I2C_MEMADD_SIZE_8BIT, &ctrl_reg1, 1, 10);
 
uint8_t ctrl_reg4 = FS_24G;
HAL_I2C_Mem_Write(&hi2c1, ACCEL_ADDRESS, CTRL_REG4, I2C_MEMADD_SIZE_8BIT, &ctrl_reg4, 1, 10);
 
 
/* While */
HAL_I2C_Mem_Read(&hi2c1, ACCEL_ADDRESS, OUT_X_L | 0x80,  I2C_MEMADD_SIZE_8BIT, &Accels[0], 6,10);
X = ConvertDigitToMilliG(Accels[0], Accels[1]);
Y = ConvertDigitToMilliG(Accels[2], Accels[3]);
Z = ConvertDigitToMilliG(Accels[4], Accels[5]);
 
 
/* Functions */
int16_t ConvertDigitToMilliG(uint8_t LSB, uint8_t MSB) {
    uint8_t lsb = (uint8_t) LSB;
    int8_t msb = (int8_t) MSB;
    int16_t val = ((msb * 256 + lsb) * 3000) >> 12;
    return val;
}


I hope anybody can help me.

Greets Mathias

Outcomes