cancel
Showing results for 
Search instead for 
Did you mean: 

LIS3DH output register value less than the set threshold

Andy Zh
Associate II

I use the lis3dh sensor to communicate through SPI, and the sensor settings are as follows:

lis3dh_gvWriteReg(LIS3DH_CTRL_REG0,0x90);

lis3dh_gvWriteReg(LIS3DH_CTRL_REG1,0x37);

lis3dh_gvWriteReg(LIS3DH_CTRL_REG2,0x00);

lis3dh_gvWriteReg(LIS3DH_CTRL_REG3,0x40);

lis3dh_gvWriteReg(LIS3DH_CTRL_REG4,0x30);

lis3dh_gvWriteReg(LIS3DH_CTRL_REG5,0x00);

lis3dh_gvWriteReg(LIS3DH_CTRL_REG6,0x00);

lis3dh_gvWriteReg(LIS3DH_INT1_THS,30);

lis3dh_gvWriteReg(LIS3DH_INT1_DURATION,0);

lis3dh_gvWriteReg(LIS3DH_INT1_CFG,0x2a);

Question 1:

The read acceleration value is less than the set threshold, and an interrupt occurs when it exceeds the threshold。why?

Question 2:

Why can a slight tap on the sensor detect an acceleration of 12 grams?

Question 3:

Is the conversion to acceleration values correct?

lis3dh_gvReadReg(LIS3DH_OUT_X_L, &val[0]); //28
lis3dh_gvReadReg(LIS3DH_OUT_X_H, &val[1]);

*p_x = val[0] | (val[1] << 8);
*p_x >>= 6;
*p_x *= 48;

2 REPLIES 2
Federica Bossi
ST Employee

Hi @Andy Zh ,

  1. this is because you set the registers to have this behavior. May I mask you what did you expect?
  2. I think you're doing some errors in the conversion, we expect 1.2g for a small tap, not 12g.
  3. From your settings I see you are in HR mode, you are right in shifting the value, but you have to multiply by the correct value according to your FS, as reported in table 4 on the datasheet.

If my reply answered your question, please click on Accept as Solution at the bottom of this post. This will help other users with the same issue to find the answer faster :)

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

HI @Federica Bossi 

1. LIS3DH full scale is 16g, And it works in normal mode. The trigger threshold is set to 30, and the actual acceleration trigger value is 30*186mg = 5580mg. But when the trigger interrupt occurs, the output register is read and the output acceleration value is less than 5580mg. I think it should be greater than 5580mg.  When the threshold trigger occurs, will enter the data processing function (void  DealAccData(void)) ,the debug log is shown in the following figure: 

void lis3dh_gvGetAccData(int16_t *p_x, int16_t *p_y, int16_t *p_z)
{
    uint8_t st;
    uint8_t val[6];
    lis3dh_gvReadReg(LIS3DH_STATUS_REG2, &st); //27
    if(st & 0x01)
    {
        lis3dh_gvReadReg(LIS3DH_OUT_X_L, &val[0]); //28
        lis3dh_gvReadReg(LIS3DH_OUT_X_H, &val[1]);
    }
    else
    {
        val[0] = 0;
        val[1] = 0;
    }
   if(st & 0x02)
    {
        lis3dh_gvReadReg(LIS3DH_OUT_Y_L, &val[2]); //2A
        lis3dh_gvReadReg(LIS3DH_OUT_Y_H, &val[3]);
    }
    else
    {
        val[2] = 0;
        val[3] = 0;
    }
    if(st & 0x04)
    {
        lis3dh_gvReadReg(LIS3DH_OUT_Z_L, &val[4]); //2c
        lis3dh_gvReadReg(LIS3DH_OUT_Z_H, &val[5]);
    }
    else
    {
        val[4] = 0;
        val[5] = 0;
    }

    *p_x = val[0] | (val[1] << 8);
    *p_x >>= 6;
    // convert to mg
    *p_x *= 48;

    *p_y = val[2] | (val[3] << 8);
    *p_y >>= 6;
    *p_y *= 48;

    *p_z = val[4] | (val[5] << 8);
    *p_z >>= 6;
    *p_z *= 48;

    DEBUG_PRINT("LIS3DH_STATUS_REG2 = %x\r\n",st);
}

void DealAccData(void)

{

    uint8_t reg2;

    lis3dh_gvReadReg(LIS3DH_INT1_SRC,&reg2);
    lis3dh_gvGetAccData((int16_t *)&Var_giXMaxAcc,(int16_t *)&Var_giYMaxAcc,(int16_t *)&Var_giZMaxAcc);
    DEBUG_PRINT("@X=%d mg,Y=%d mg,Z=%d mg,LIS3DH_INT1_SRC
=

                                       %x\r\n",Var_giXMaxAcc,Var_giYMaxAcc,Var_giZMaxAcc,reg2);   

}

AndyZh_1-1697767388554.png

AndyZh_0-1697765768773.png

 

2.  I think the conversion is correct because the test gravity acceleration is around 1g when the sensor is not moving.

AndyZh_2-1697768200608.png

This is the captured SPI bus data and the data printed by the device

AndyZh_1-1697794926606.jpeg

 

AndyZh_0-1697794921038.jpeg