2021-05-15 04:44 PM
I have a project with LIS2DH accelerometer and I want to measure values each 20 seconds, turning LIS2DH off between measurements.
So, I tried to turn power on, wait 5ms, write 0x10 to CTRL_REG3 (turn on DRDY on INT1), then 0x1F to CTRL_REG1.
Then I wait for pulse in INT1 (and getting it almost immediately) and read data from OUT_X_L to OUT_Z_H. But - all data is zeroes. Writing registers in different direction, i.e. from REG1 to REG6 gives same result.
Datasheet for LIS2DH gives no information about how DRDY works (and, for example, which is minimum time allowed between two SPI reads/writes, but I read in datasheet for LIS2DH12 (newer accelerometer), that "In order to be sure to have the first DRDY rising edge synchronous with the selected ODR (avoid condition in Figure 2: "DRDY signal synchronization") set the I1_ ZYXDA bit to ‘1’ before enabling the ODR."
No luck.
Can you give me an advice how to read valid data from LIS2DH in a minimum time from powering it up?
Thank you in advance!
Solved! Go to Solution.
2021-05-20 05:13 AM
Hi @oleg239955_st ,
glad to see you solved your first communication issue!
Let me try to answer to your next questions:
If my reply answered your question, please click on Select as Best at the bottom of this post. This will help other users with the same issue to find the answer faster.
-Eleon
2021-05-18 07:24 AM
Hi @oleg239955_st ,
the timings you are using look ok.
Is the SPI pattern OK too?
Since I believe that also in polling mode you are receiving zero data, I would suggest you to add some more configuration as suggested in the C drivers on Github (lis2dh_read_data_polling.c), for example enabling the BDU bit.
/* Enable Block Data Update. */
lis2dh_block_data_update_set(&dev_ctx, PROPERTY_ENABLE);
/* Set Output Data Rate to 1Hz. */
lis2dh_data_rate_set(&dev_ctx, LIS2DH_ODR_1Hz);
/* Set full scale to 2g. */
lis2dh_full_scale_set(&dev_ctx, LIS2DH_2g);
/* Enable temperature sensor. */
lis2dh_temperature_meas_set(&dev_ctx, LIS2DH_TEMP_ENABLE);
/* Set device in continuous mode with 12 bit resol. */
lis2dh_operating_mode_set(&dev_ctx, LIS2DH_HR_12bit);
Try also polling the INT1_SRC (31h) IA bit to see whether the interrupt has been raised, and let me know.
-Eleon
2021-05-18 12:10 PM
Thank you for answering me!
This was my mistake :(
I have tested SPI exchange with logic analyzer and found it. As I using same SPI lines for accelerometer and transmitter, I found that there was extra pulse on clock line (while reconfiguring SPI inside MCU). So I missed that extra pulse, and found it only when I tuned analyzer to very high speed. I changed initialization procedure, and now I getting value from accelerometer.
But I still want to make measurement as fast as it can be possible, so I have several questions:
Thank you!
2021-05-20 05:13 AM
Hi @oleg239955_st ,
glad to see you solved your first communication issue!
Let me try to answer to your next questions:
If my reply answered your question, please click on Select as Best at the bottom of this post. This will help other users with the same issue to find the answer faster.
-Eleon
2021-05-20 09:11 PM
Thank you!
But can you clarify something (I definitely mean that reading data from OUT registers should have place only when INT pin raised or ZYXDA flag in STATUS_REG is set).
So, as I understand, to get fastest result available, I should power LIS2DH on, and immediately start reading WHO_AM_I via SPI until I will read 0x33. Then I should configure LIS2DH with ODR='1001b' (to get second result faster) and set BDU flag, and then start polling STATUS_REG until I will see ZYXDA flag set. Then I can get this sample (read all OUT registers) and this values will be valid? Or I should repeat last step (poll STATUS_REG then read OUT registers) again to get second value, and use that second value to sure that it is definitely valid?
Thanks!