2021-01-15 04:00 AM
Hello Community,
I am working on the LIS2DE12 accelerometer. using the example code by STM.
https://github.com/STMicroelectronics/STMems_Standard_C_drivers
I am making a test case with the lis2de12_filter_hp_rst_on_int.c example.
I have placed a module on the ground. still getting invalid results on the output.
pi@raspberrypi:~/test/lis2de12_STdC $ ./main.bin
tx_com : Acceleration [mg]: 15.60 -46.80 904.80 25
tx_com : Acceleration [mg]: 0.00 0.00 0.00 15
tx_com : Acceleration [mg]: 0.00 0.00 15.60 15
tx_com : Acceleration [mg]: 0.00 0.00 0.00 15
tx_com : Acceleration [mg]: 0.00 0.00 0.00 15
tx_com : Acceleration [mg]: 0.00 0.00 0.00 15
tx_com : Acceleration [mg]: 0.00 0.00 0.00 15
tx_com : Acceleration [mg]: 0.00 0.00 0.00 15
tx_com : Acceleration [mg]: 15.60 -15.60 0.00 15
tx_com : Acceleration [mg]: 15.60 -15.60 -15.60 15
tx_com : Acceleration [mg]: 0.00 0.00 0.00 15
tx_com : Acceleration [mg]: 0.00 0.00 0.00 15
tx_com : Acceleration [mg]: -15.60 -15.60 0.00 15
tx_com : Acceleration [mg]: 0.00 0.00 0.00 15
tx_com : Acceleration [mg]: 0.00 0.00 0.00 15
tx_com : Acceleration [mg]: 0.00 0.00 0.00 15
tx_com : Acceleration [mg]: 0.00 0.00 0.00 15
tx_com : Acceleration [mg]: -15.60 -15.60 0.00 15
tx_com : Acceleration [mg]: -15.60 -15.60 0.00 15
tx_com : Acceleration [mg]: 0.00 0.00 0.00 15
tx_com : Acceleration [mg]: 0.00 0.00 -15.60 15
tx_com : Acceleration [mg]: 0.00 0.00 -15.60 15
will you please help me to know,
If there is no acceleration force applied, How di I get the stable readings?
Regards,
Shiv Patil.
Solved! Go to Solution.
2021-01-27 03:59 AM
Hi Shiv,
to clear the INT1 pin you can first enable the LIR_INT1 bit of CTRL_REG5 (24h), i.e. the Latch interrupt request on INT1_SRC (31h): the INT1_SRC (31h) register can be then cleared by reading INT1_SRC (31h) itself.
You can find this description in the LIS2DE12 datasheet, p.36.
-Eleon
2021-01-18 12:24 AM
Hi Shiv @spati.1 ,
the first line looks like a standard reading: near 0g on x and y axis, near 1g on z axis and 25°C temperature.
x axis y axis z axis Temp
tx_com : Acceleration [mg]: 15.60 -46.80 904.80 25
After that, it looks like the high pass filter configured in the first part of the lis2de12_filter_hp_rst_on_int.c is active: applying a high pass filter to the output data, the output value in steady condition will be close to zero for all the 3 axis:
x axis y axis z axis Temp
tx_com : Acceleration [mg]: 0.00 0.00 0.00 15
If you remain in steady condition, this filter is not resetting since the filtered data cannot cross the threshold defined below and the interrupt is not raised. For this reason, you'll continue to see 0 data output.
/* Set interrupt threshold at ~800 mg -> 1bit = 16mg@2g */
lis2de12_int1_gen_threshold_set(&dev_ctx, 0x30);
/* Set duration to zero - 1 bit = 1/ODR */
lis2de12_int1_gen_duration_set(&dev_ctx, 0);
So it appears as the code is correctly working... you should try moving the device so that it overcomes the threshold and starts again acquiring non-filtered data.
If you are not interest in this interrupt procedure, you could simply use the lis2de12_read_data_polling.c code.
Let me know if it can explain your findings and, in case, please select this as best.
-Eleon
2021-01-18 01:37 AM
Hello @Eleon BORLINI
First of all, I would like to share my application use case.
I want to configure the LIS2DE12 accelerometer in such a way that...
whenever there is movement happens with the heavy acceleration to cross a threshold level, the LIS2DE12 should raise an interrupt condition on the INT1 pin & the data will be read at this moment only.
otherwise, the accelerometer must keep monitoring the x, y, z-axis data to cross the threshold level.
there will be no need for reading data unless the interrupt condition is not raised by the LIS2DE12
Note: t=initialy when the device is in steady-state. i.e. no acceleration applied all that x, y, z-axis must show the 0 0 0 values.
Now,
As per your suggestion, I have gone through the lis2de12_read_data_polling.c example.
if you look into the code. it's clearly mentioned that the int is not working here.
/* Read samples in polling mode (no int) */
while (1)
{
lis2de12_reg_t reg;
/* Read output only if new value available */
lis2de12_xl_data_ready_get(&dev_ctx, ®.byte);
/*
excess code.
*/
}
return 0;
Will you please help me to know the steps to configure this code to the int mode?
Regards,
Shiv Patil.
2021-01-18 05:43 AM
Hi Shiv,
please note that the interrupt (not) declared the lis2de12_read_data_polling.c code is the data-ready interrupt (and not a threshold-event interrupt as the one defined in the lis2de12_filter_hp_rst_on_int.c).
In the first code you are using, the LIS2DE12 is configured such as the high-pass filter (which cuts the DC acceleration but doesn't block the data acquisition) is reset when the interrupt threshold is reached. So basically, before the interrupt raises, you are acquiring data without the constant acceleration, while after that you are still acquiring data but together with the DC acceleration.
If you want to start acquiring data after you have detected a certain event, you should use the “Sleep-to-wake�? (and “return-to-sleep�?) function, described in the datasheet, p.17, where the device starts acquiring data in normal mode after receiving a certain configurable input.
The LIS2DE12 can be programmed to automatically switch to low-ODR mode upon recognition of a determined event. Once the event condition is over, the device returns back to the preset ODR. To enable this function the desired threshold value must be stored inside the ACT_THS (3Eh) register while the duration value is written inside the ACT_DUR (3Fh) register. When the acceleration falls below the threshold value for a period of time longer than the duration value, the device ODR automatically switches to 10 Hz ODR. During this condition, the ODR[3:0] bits inside CTRL_REG1 (20h) are not considered. As soon as the acceleration rises above threshold, the module restores the operating mode and ODRs as determined by the CTRL_REG1 (20h) register setting.
-Eleon
2021-01-18 08:35 PM
Hello @Eleon BORLINI ,
Will you please help me to know any suitable example related to the Sleep-to-wake functionality with the interrupt functionality to achieve our use case?
& also,
How to reset the configuration of LIS2DE12 to its factory reset settings?
Regards,
Shiv Patil.
2021-01-19 12:30 AM
Hi Shiv @spati.1 ,
>> Any suitable example related to the Sleep-to-wake functionality?
Since this digital feature shares the same registers of the LIS3DH device, I suggest you to check the related sample C code on Github: lis3dh_wake_up.c. In particular, the setting procedure is described from line 148 to line 179. You can reuse it, after a proper adjustment of the functions.
>> How to reset the configuration of LIS2DE12 to its factory reset settings?
If you just power off the device, you will get back to the factory configuration, since the register are written in volatile memory only.
-Eleon
2021-01-19 12:37 AM
Hello @Eleon BORLINI ,
Thanks for the information, I will make a test case & put further update.
Is it necessary to power of device for getting factory reset?
Is there any reg configurations for LIS2DE12 through which we can able to restore factory reset settings?
i.e. as the following function definition for the LIS2DS12
/* Restore default configuration */
lis2ds12_reset_set(&dev_ctx, PROPERTY_ENABLE);
Regards,
Shiv Patil.
2021-01-19 12:52 AM
Hi Shiv @spati.1 ,
differently from the LIS2DS12, unfortunately the LIS2DE12 has not the "SOFT_ RESET" function of the CTRL2 (21h) register...
So there is not a single bit able to do the chip reset when the chip is on.
If you don't want to power off the device, you can always launch a "configuration restore" procedure, a series of memory writings that overwrite the previously configured registers according to the default factory values you can find in the datasheet, p.30 (Table 20. Register address map).
-Eleon
2021-01-19 11:59 PM
Hello @Eleon BORLINI ,
As per your suggestion, I have implemented the wake-up functionality for the LIS2DE12 with reference to the LIS3DH device.
I am able to read the INT1 weak-up source.
/* Main Example --------------------------------------------------------------*/
int main(void)
{
/* Initialize mems driver interface */
uint8_t dummy;
stmdev_ctx_t dev_ctx;
lis2de12_int1_cfg_t int1_cfg;
lis2de12_ctrl_reg3_t ctrl_reg3;
dev_ctx.write_reg = platform_write;
dev_ctx.read_reg = platform_read;
#if defined(NUCLEO_F411RE) | defined(STEVAL_MKI109V3) | defined(SPC584B_DIS)
dev_ctx.handle = &SENSOR_BUS;
#elif defined(RASPBERRY_PI)
dev_ctx.handle = &file_disc;
#endif
/* Initialize platform specific hardware */
platform_init();
/* Wait sensor boot time */
platform_delay(BOOT_TIME);
/* Check device ID */
lis2de12_device_id_get(&dev_ctx, &whoamI);
if (whoamI != LIS2DE12_ID)
while (1) {
/* manage here device not found */
}
/* route HP filter output on interrupt generator 1 */
lis2de12_high_pass_int_conf_set(&dev_ctx, LIS2DE12_ON_INT1_GEN);
/* Enable HP filter for wake-up event detection
*
* Use this setting to remove gravity on data output */
lis2de12_high_pass_on_outputs_set(&dev_ctx, PROPERTY_ENABLE);
/* Enable AOI1 on int1 pin */
lis2de12_pin_int1_config_get(&dev_ctx, &ctrl_reg3);
ctrl_reg3.i1_ia1 = PROPERTY_ENABLE;
lis2de12_pin_int1_config_set(&dev_ctx, &ctrl_reg3);
/* Interrupt 1 pin latched */
lis2de12_int1_pin_notification_mode_set(&dev_ctx, LIS2DE12_INT1_PULSED);
/* Set 2g full XL scale */
lis2de12_full_scale_set(&dev_ctx, LIS2DE12_2g);
/* Set interrupt threshold to 0x10 -> 250 mg */
lis2de12_int1_gen_threshold_set(&dev_ctx, 0x10);
/* Set no time duration */
lis2de12_int1_gen_duration_set(&dev_ctx, 0x00);
/* Dummy read to force the HP filter to current acceleration value. */
lis2de12_filter_reference_set(&dev_ctx, &dummy);
/* Configure wake-up interrupt event on all axis */
lis2de12_int1_gen_conf_get(&dev_ctx, &int1_cfg);
int1_cfg.zhie = PROPERTY_ENABLE;
int1_cfg.yhie = PROPERTY_ENABLE;
int1_cfg.xhie = PROPERTY_ENABLE;
int1_cfg.aoi = PROPERTY_ENABLE;
lis2de12_int1_gen_conf_set(&dev_ctx, &int1_cfg);
// /* Set device in HR mode */
// lis3dh_operating_mode_set(&dev_ctx, LIS3DH_HR_12bit);
/* Set Output Data Rate to 100 Hz */
lis2de12_data_rate_set(&dev_ctx, LIS2DE12_ODR_100Hz);
static int16_t data_raw_acceleration[3];
static float acceleration_mg[3];
/* Wait Events */
while (1)
{
lis2de12_int1_src_t src;
/* Read INT pin 1 in polling mode
* or read src status register
*/
lis2de12_int1_gen_source_get(&dev_ctx, &src);
if (src.xh || src.yh || src.zh)
{
lis2de12_int1_gen_source_get(&dev_ctx, &src);
sprintf((char *)tx_buffer, "wake-up detected : x %d, y %d, z %d\r\n", src.xh, src.yh, src.zh);
tx_com(tx_buffer, strlen((char const *)tx_buffer));
/* Read accelerometer data */
memset(data_raw_acceleration, 0x00, 3 * sizeof(int16_t));
lis2de12_acceleration_raw_get(&dev_ctx, data_raw_acceleration);
acceleration_mg[0] =
lis2de12_from_fs2_to_mg(data_raw_acceleration[0]);
acceleration_mg[1] =
lis2de12_from_fs2_to_mg(data_raw_acceleration[1]);
acceleration_mg[2] =
lis2de12_from_fs2_to_mg(data_raw_acceleration[2]);
sprintf((char *)tx_buffer,
"Acceleration [mg]:\t%4.2f\t%4.2f\t%4.2f\r\n",
acceleration_mg[0], acceleration_mg[1], acceleration_mg[2]);
tx_com(tx_buffer, strlen((char const *)tx_buffer));
}
}
return 0;
}
Note: Here lis3dh_operating_mode_set functionality not defined for the LIS2DE12.
But the problem is,
The INT 1 Pin is getting continuously in pulled (HIGH) mode even after the INT1 has passed.
root@raspberrypi:/home/pi/test/lis2de12_STdC# ./main.bin
tx_com : wake-up detected : x 0, y 0, z 1
tx_com : Acceleration [mg]: -31.20 -62.40 -249.60
tx_com : wake-up detected : x 0, y 0, z 1
tx_com : Acceleration [mg]: -31.20 -62.40 -249.60
tx_com : wake-up detected : x 0, y 0, z 1
tx_com : Acceleration [mg]: 0.00 -46.80 -358.80
tx_com : wake-up detected : x 0, y 0, z 1
tx_com : Acceleration [mg]: 0.00 -46.80 -358.80
tx_com : wake-up detected : x 0, y 0, z 0
tx_com : Acceleration [mg]: -15.60 140.40 62.40
tx_com : wake-up detected : x 0, y 0, z 1
tx_com : Acceleration [mg]: 62.40 -46.80 546.00
tx_com : wake-up detected : x 0, y 0, z 1
tx_com : Acceleration [mg]: 62.40 -46.80 546.00
Will you please help me to know, How do I clear the INT1 pin after reading the x, y, z-axis values?
Regards,
Shiv Patil.
2021-01-27 03:59 AM
Hi Shiv,
to clear the INT1 pin you can first enable the LIR_INT1 bit of CTRL_REG5 (24h), i.e. the Latch interrupt request on INT1_SRC (31h): the INT1_SRC (31h) register can be then cleared by reading INT1_SRC (31h) itself.
You can find this description in the LIS2DE12 datasheet, p.36.
-Eleon