2019-07-31 01:51 AM
I am trying to use the lis2de12 as a activity level detector.
By reading some posts here in the community I guess I need to setup HighPass filtering and a threshold so it gives interrupts everytime there is a movement bigger then a certain force.
But I have no clue how to setup all the registers. The datasheet only describes how to setup postion detection and fifo etc. I also found a driver but that only has functions to set the registers individualy. I cannot find any samples to setup ( IA1?) motion detection
For example when I look in the datasheet for the HighPass filter there is a mode that
Autoreset on interrupt event. Do I need this ? And do I need to clear the interrupt in a register when there was one ?
2019-08-08 04:47 AM
After some more puzzling and googling I found it out:
First download the standard drivers : https://github.com/STMicroelectronics/STMems_Standard_C_drivers/tree/master/lis2de12_STdC
Then by using the drivers and some nordic nrf51 code
sd_nvic_ClearPendingIRQ(GPIOTE_IRQn);
sd_nvic_DisableIRQ(GPIOTE_IRQn);
enable_GPIO_int();
// Enable Block Data Update , not sure if needed
lis2de12_block_data_update_set(&dev_ctx, PROPERTY_ENABLE);
/* Set Output Data Rate to 100Hz */
lis2de12_data_rate_set(&dev_ctx, LIS2DE12_ODR_100Hz);
/* Set full scale to 4g */
lis2de12_full_scale_set(&dev_ctx, LIS2DE12_4g);
lis2de12_high_pass_int_conf_set((dev_ctx), LIS2DE12_ON_INT1_GEN);
// Configure INTERRUPT 1 Threshold
lis2de12_int1_gen_threshold_set((dev_ctx), 0xD); // scale = 4G so 0.032 per bit, 14*0.032 = 0.44 G threshold
// Configure INTERRUPT 1
lis2de12_int1_gen_conf_set(dev_ctx, &cfg); // lis2de12_int1_cfg_t in lis2de12_reg.h set only the high parts so xhie,zhie,zhoe, aoi also not set
lis2de12_int2_pin_notification_mode_set(dev_ctx, LIS2DE12_INT2_LATCHED);
lis2de12_int1_pin_notification_mode_set(dev_ctx, LIS2DE12_INT1_LATCHED);
// Route INTERRUPT 1 to PIN 2
lis2de12_pin_int2_config_set(dev_ctx, &ctrl6); // lis2de12_ctrl_reg6_t only set i2_ia1
uint8_t test;
lis2de12_read_reg(&dev_ctx, LIS2DE12_INT1_SRC, (uint8_t*)&test, 1); // clear any pending interrupt
sd_nvic_EnableIRQ(GPIOTE_IRQn);
I hope it helps somebody so they don't have to search hours on the internet..