cancel
Showing results for 
Search instead for 
Did you mean: 

LIS3DH Accelerometer interrupt to STM32L151

akp25i
Associate II
Posted on August 30, 2013 at 00:22

I am trying to interface LIS3DH Accelerometer over I2C to STM32l151rx series microcontroller , I am able to Read  X,Y,Z register  content , but i want to use the inbuilt motion detection interrupt feature of LIS3DH ,using INT1 output , here is an example of doing this

http://www.ecnmag.com/articles/2013/04/one-accelerometer-interrupt-pin-both-wakeup-and-non-motion-detection

Write 27h into CTRL_REG1;      // Turn on the sensor with ODR = 10Hz normal mode.  Write 01h into CTRL_REG2;      // High-pass filter (HPF) enabled with 0.2Hz cut-off                         frequency for INT1 (AOI1) interrupt generation only.

Write 40h into CTRL_REG3;      // ACC AOI1 interrupt signal is routed to INT1 pin.

Write 88h into CTRL_REG4;      // Full Scale = +/-2 g with BDU and HR bits enabled.

Write 00h into CTRL_REG5;      // Default value. Interrupt signals on INT1 pin is not                         latched. Users don’t need to read the INT1_SRC                         register     to clear the interrupt signal.

  

    // configurations for wakeup and motionless detection

Write 08h into INT1_THS;          // Threshold (THS) = 8LSBs * 15.625mg/LSB = 125mg.

Write 32h into INT1_DURATION;      // Duration = 50LSBs * (1/10Hz) = 5s.

Write 95h into INT1_CFG;          // Enable XLIE, YLIE and ZLIE interrupt generation,

When i do this initialization it does not works , the Interrupt pin from Accelerometer  signals at nearly 1hz par second , and not based on motion , but this interrupt even comes when  no Initialization is  done for Accelerometer , why is it interrupting   at 1 Hz by default ,

while searching on this forum i found this thread

''

iNEMO MEMS/STM32 Board

''

where author says

'' I have found the solution for this.In the application note CTRL_REG3 is metioned as the register to configure interruppt on INT1 pin but the correct configuration is use CTRL_REG6 bit 7 and bit 6(I2_CLICKen and I2_INT1) will enable tap and double tap interruppts on INT2 pin.(Tip:for tuning increase sampling rate (CTRL-REG1) increase time-limit value).''

Is there really an error in datasheet , and the example given above is wrong ?  the above st forum thread talks about Tap Detection , while i want settings for Motion detection interrupt .

3 REPLIES 3
akp25i
Associate II
Posted on August 31, 2013 at 17:32

Have checked it by Reading back  from initialization registers , all the values are being stored in Accelerometer registers correctly ,

Also i monitored the Interrupt  signal on GPIO line on Scope  , it is Constantly high as soon as Power is  enabled to the Accelerometer , i am using INT1 output of Accelerometer , In Scope it is shown as constantly High and  still  in Firmware  in debugger its interrupting  Once Per Second  ,

Here is the Initialization code for GPIO interrupts for Accelerometer 

void GPIO_InitAccelometerPins(void)

{

    GPIO_InitTypeDef GPIO_InitStructure;

    // Configure ACC_INT1/2 input

    GPIO_InitStructure.GPIO_Pin = GPIO_ACC_INT1 | GPIO_ACC_INT2;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;

    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; // Force low from start

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;

    GPIO_Init(GPIO_ACC_INT_PORT, &GPIO_InitStructure);

}

void GPIO_InitInterrupts(void)

{

__IO uint8_t PreemptionPriorityValue = 0x0F;

    __IO uint8_t SubPriorityValue = 0x0F;

    EXTI_InitTypeDef EXTI_InitStructure;

    NVIC_InitTypeDef NVIC_InitStructure;

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

        

        

    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, GPIO_ACC_INT1);

       

                // Configure Accelerometer int 1

        EXTI_InitStructure.EXTI_Line = EXTI_Line0;

        EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;

        EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;

        EXTI_InitStructure.EXTI_LineCmd = ENABLE;

        EXTI_Init(&EXTI_InitStructure);

        SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, GPIO_ACC_INT2);

 

                    // Configure Accelerometer int 2

        EXTI_InitStructure.EXTI_Line = EXTI_Line1;

        EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;

        EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;

        EXTI_InitStructure.EXTI_LineCmd = ENABLE;

        EXTI_Init(&EXTI_InitStructure);

        

        

        

        // Enable the Accelerometer Interrupt

        NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; //

        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = PreemptionPriorityValue;

        NVIC_InitStructure.NVIC_IRQChannelSubPriority = SubPriorityValue;

        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

        NVIC_Init(&NVIC_InitStructure);

        

        

           // Enable the Accelerometer Interrupt 2

        NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn; //

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =PreemptionPriorityValue;

        NVIC_InitStructure.NVIC_IRQChannelSubPriority = SubPriorityValue;

        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

        NVIC_Init(&NVIC_InitStructure);

       

        }

akp25i
Associate II
Posted on September 17, 2013 at 13:17

Finally i managed to enable interrupts  , i use the  application note  AN3308 sequence for wakeup detection 

1 Write A7h into CTRL_REG1

// Turn on the sensor and enable X, Y, and Z

// ODR = 100 Hz

2 Write 00h into CTRL_REG2 // High-pass filter disabled

3 Write 40h into CTRL_REG3 // Interrupt driven to INT1 pad

4 Write 00h into CTRL_REG4 // FS = 2 g

5 Write 08h into CTRL_REG5 // Interrupt latched

6 Write10h into INT1_THS // Threshold = 250 mg

7 Write 00h into INT1_DURATION // Duration = 0

8 Write 0Ah into INT1_CFG // Enable XH and YH interrupt generation  

In my case interrupts are not latched  so  00h in CTRL_REG5

I am getting these interrupt on INT2 and not INT1 pin , i can see the interrupts  coming on INT1  in scope , but they dont generate a GPIO inerrupt on  MC ,perhaps some problem with board ,  but when INT2 is enabled ( 0x40h in CTRL_REG6  of Accelerometer)   i will get same signal on INT2 and  INT1 perhaps same signal is duplicated on INT2 and i get this on GPIO interrupts ,

so far its detecting motion only when the  PCB board is  oriented in a position parallel to earths surface , but when it is kept vertical and moved along x or y axis no interrupts are generated . 

0690X00000602ppQAA.jpg

I have tried enabling  6D etc while the Datasheet says that  ''AOI-6D = ?01? is movement recognition. An interrupt is generate when orientation move from

unknown zone to known zone.''  But  Its only Orientation Detection , and not Motion Detection   

Also i have tried different combination on XYZ higl low enable bits in INT1_CFG but nothing seems to work for  motion detection when orientation is vertical 

davidgregory9
Associate
Posted on April 10, 2015 at 16:32

Here are the setting I am using and they seem to work well.

#define      ACCL_CTRL_REG1_DEFAULT     0x007F 

#define      ACCL_CTRL_REG2_DEFAULT     0x00A0

 

#define      ACCL_CTRL_REG3_DEFAULT     0x0040

 

#define      ACCL_CTRL_REG4_DEFAULT     0x0000

#define      ACCL_CTRL_REG5_DEFAULT     0x0004

#define      ACCL_INT1_CFG_DEFAULT      0x007F  

 

#define      ACCL_INT1_THS_DEFAULT      0x0008  // valid values are 2, 4, 8, 16

#define      ACCL_INT1_DUR_DEFAULT      0x0010