cancel
Showing results for 
Search instead for 
Did you mean: 

LIS2DW12 latched mode

farshad
Associate II

Hi Experts,

I am using lis2dw12 accelerometer connected to esp32s3 and recently have got a situation which is blocking for esp32s3 to read status registers of accelerometer when LIR =1 (latched mode). I put accelerometer on stationary  mode and routing the intruppt to INT1 which resets my esp32. Interrupt is working fine but when I want to read tap_source or wakeup_source or in general ALL_INT_SRC ( not pulling them. only one time) to detect the reset reason on my esp32 side, It will be hanged sometimes until esp32 watchdog happens and from that point the status register are readable since i2c is reinitiated I guess. Whould you mind please help me to underestand why acccelerometer get frozen?

Here is my configurations:

write2i2c(acc_addr, LIS2DW12_CTRL1, 0x10, 1)
write2i2c(acc_addr, LIS2DW12_WAKE_UP_DUR, 0x30, 1)
write2i2c(acc_addr, LIS2DW12_WAKE_UP_THS, 0x42, 1)
write2i2c(acc_addr, LIS2DW12_CTRL4_INT1_PAD_CTRL, 0x20, 1)
write2i2c(acc_addr, LIS2DW12_CTRL_REG7, 0x20, 1)
write2i2c(acc_addr, LIS2DW12_CTRL3, 0x10, 1)

 

and after reboot which takes only 10ms I try to read:

readfromi2c(LIS2DW12_I2C_ADDRESS, 0x27)
readfromi2c(LIS2DW12_I2C_ADDRESS, 0x39)
readfromi2c(LIS2DW12_I2C_ADDRESS, 0x3b)

then If it does not crash I will put accelerometer again in stationary mode again. but sometimes it get stucked in reading process above. it is worth mentioning that it only happend when Iam in latched mode.




 

10 REPLIES 10
Federica Bossi
ST Employee

Hi @farshad ,

Welcome to ST Community!

When you reset your esp32, is the lis2dw12 always powered on?

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.

Yes it has seperated 3.3 voltage source which is always on. I may need to send him to stationary or double tap mode after esp32 reboot( if the wake up reason was INT1 trigger from accelerometer)

Yes it has seperated 3.3 voltage source which is always on. I may need to send him to stationary or double tap mode after esp32 reboot( if the wake up reason was INT1 trigger from accelerometer)

Perfect. Are you sure that the i2c is ready to read the sensor, when the micro reboots? you need to understand what is the difference between the first read that does not return anything and the one after the watchdog triggers... you could try to read the whoami register to see if there are problems with that register or the whole sensor.

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.

I have already tried reading whoamI and seems it get stuck reading from accelerometer while I am sure I2c is reinitiated after each reboot and ready to be used since there is and rtc module also reading from i2c and is functional( they dont have any interference).

It is worth mentioning it randomly happen and for example if you lift the senor and keep it face up for a while it likely stopps before reading form I2C process(like accelerometer is hanged somewhere, Write process is also not working). I even tried a loop to read status register after reboot to see if the value of flags change but they are somehow froozen sometimes. Is not it related to happening two WU_IA in a row before reading the wake_up source register or all_int_src register?

Which interrupt routine are you using for ESP32S3?

The interrupt routine must be as short as possible in order to avoid the watchdog to start. All the readings after the interrupt should be done in a separate routine.

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.

Interrupts routine is so short and fast. INT1 pin is connected to PWR_ON pin of ESP32S3 and As I said before reboot time take a couples of 10ms until we start to read from I2C. I insiste to say when LIR=0 every read from I2C , at the same API call level, will work but when LIR=1 esp32 watchdog reset happens. Could you please check the differences between this two working mode? I guess LIS2DW12 needs to write event flags in NVS which can leads to not being responding during that process or.....

Hi @farshad ,

The difference between latched and pulsed should be only the duration of the interrupt signal level to stay high but we will do further analysis to try to replicate your issues.

However, can you provide us your project schematic (which ESP32 pin are you using to communicate with our sensor), and the line code in which you detect the interrupt event and the following few lines?

Moreover, it can be helpful for us to read the esp32 message about reboot and watchdog Timer. When does the reboot of 10ms happen? Thanks.

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,

Sorry for my late response due to the holidays. I actually found the problem but I have no proper explanation for the reason of that. As I mentioned above I only try to put the accelerometer in the stationary after each esp32s3 power on. Accelerometer can wake up the esp32s3 since the INT pin is connected to esp_pwr_on pin( you can see in the schematic). The faulty scenario happens when I set accelerometer in stationary + latched mode enabled(LIR = 1).

Faulty scenario: while I bring the accelerometer out of latched mode (LIR=0) and wait for wakeup source register clean up through polling loop, If I shake the sensor during reconfiguration, it will finally come out of the polling loop and Accelerometer goes to latched mode again( here something happens) and I will not be able to read or write from/to accelerometer until shaking stops for next configuration.

*****after every power on of esp32 I have the following code immediately:

write2i2c(acc_addr, LIS2DW12_CTRL3, 0x10, 1)
 // wait until WU_IA and TAP_IA flag is reseted otherwise it will stay set
do
{
        wakeup_source_reg = readfromi2c(acc_addr, 39h)
 } while ((wakeup_source_reg & 0x0f));

========================================> I have noticed that when execution reaches here, there should not be any movement for accelerometer( wakeup_source_reg = 00) and not any interrupt should not happen before configuration. I am sure about that since I have tried a lot to keep the accelerometer stationery before this line execution and it will never crashes================= >

write2i2c(acc_addr, LIS2DW12_CTRL10x101)                                     
write2i2c(acc_addr, LIS2DW12_WAKE_UP_DUR0x301)                     
write2i2c(acc_addr, LIS2DW12_WAKE_UP_THS0x421)
write2i2c(acc_addr, LIS2DW12_CTRL4_INT1_PAD_CTRL0x201)
write2i2c(acc_addr, LIS2DW12_CTRL_REG70x201)
write2i2c(acc_addr, LIS2DW12_CTRL3, 0x10, 1)
========================================> if  accelerometer is not steady( still shaking) when execution is here then it will latched one or two consecutive  WU_IA and for the next power on when we want to read the wakeup source register the watchdog trigger in the esp side happens  ================= >

 +++++I is worth mentioning if accelerometer is steady within the above execution until esp32 goes to power down, any movement powers on the esp and if accelerometer gets steady before the above code execution it will never crashes

farshad_0-1704295437095.png esp_en goes to esp32s3 pwr_en pin