2018-07-04 03:06 AM
I intend to use the LIS3DH as a very low power activity detector but have had no success in getting its interrupt output to behave in my application: I can make it stay always on or always off but never does it react to motion.
To retain my sanity, I have gone back to the application note and written code which does exactly what the application note (section 6.3.3) says but I can't make that work either: I can see the X/Y/Z values changing but the IA bit in INT1_SRC is never set, no matter how violently I shake the chip (which is on an STEVAL-MKI105V1 board attached via I2C). What am I doing wrong? Help!
My code (in mbed-os, running on an STM32F437VG) is attached to this post, its output is below:
Read I_AM_LIS3DH (0x0f): 0x33.
Write CTRL_REG1 (0x20): 0x57.
Write CTRL_REG2 (0x21): 0x09.
Write CTRL_REG3 (0x22): 0x40.
Write CTRL_REG4 (0x23): 0x00.
Write CTRL_REG5 (0x24): 0x08.
Write INT1_THS (0x32): 0x10.
Write INT1_DURATION (0x33): 0x00.
Read REFERENCE (0x26): 0x00.
Write INT1_CFG (0x34): 0x2a.
Read INT1_SRC (0x31): 0x00.
Read X 64 Y 64 Z 65472.
Read INT1_SRC (0x31): 0x00.
Read X 65472 Y 65472 Z 0.
Read INT1_SRC (0x31): 0x00.
Read X 64 Y 0 Z 65472.
Read INT1_SRC (0x31): 0x00.
Read X 0 Y 65472 Z 0.
Read INT1_SRC (0x31): 0x00.
Read X 0 Y 0 Z 65472.
Read INT1_SRC (0x31): 0x00.
Read X 0 Y 64 Z 65472.
Read INT1_SRC (0x31): 0x00.
Read X 0 Y 65408 Z 0.
Read INT1_SRC (0x31): 0x00.
Read X 65472 Y 0 Z 0.
Read INT1_SRC (0x31): 0x00.
Read X 65408 Y 0 Z 65472.
Read INT1_SRC (0x31): 0x00.
...
Read X 0 Y 64960 Z 1088.
Read INT1_SRC (0x31): 0x00.
Read X 1088 Y 2496 Z 65088.
Read INT1_SRC (0x31): 0x00.
Read X 1216 Y 64832 Z 63808.
Read INT1_SRC (0x31): 0x00.
Read X 1408 Y 1280 Z 63424.
Read INT1_SRC (0x31): 0x00.
Read X 1792 Y 4608 Z 63168.
Read INT1_SRC (0x31): 0x00.
Read X 65472 Y 0 Z 64320.
Read INT1_SRC (0x31): 0x00.
Read X 256 Y 768 Z 1600.
Read INT1_SRC (0x31): 0x00.
Read X 1792 Y 3520 Z 2688.
Read INT1_SRC (0x31): 0x00.
Read X 128 Y 1216 Z 64576.
Read INT1_SRC (0x31): 0x00.
...
Rob
#lis3dh2018-07-04 08:53 AM
Your sensor configuration is OK, I have tested it and the interrupt is triggered.
Can you check the INT pin with scope or logic analyzer?
2018-07-04 11:07 AM
Ooo, hi, thanks very much for doing that. I have a logic analyzer connected to INT1 waiting for a rising edge but it never sees one, INT1 is always low. And of course INT_SRC always returns zero. Did you really see an interrupt being generated with my sample code? How hard did you have to shove the device to make the interrupt occur?
2018-07-04 11:14 AM
I did not test your sample code, I'm not much familiar with mbed, but I used exactly your sensor configuration, and it is OK.
Gentle movement was needed to trigger the interrupt.
Maybe you can try to read back all the configuration.
2018-07-04 11:30 AM
OK: could you send me your code so that I could cross-check what I'm doing? I've added a set of read-backs at the end of my configuration-writes and all the registers seem to have the expected values (see below). CouldI be doing things in the wrong order somehow? For the avoidance of doubt, I have power-cycled the board so that there is no lingering configuration from a previous test.
Read I_AM_LIS3DH (0x0f): 0x
Write CTRL_REG1 (0x20): 0x
Write CTRL_REG2 (0x21): 0x
Write CTRL_REG3 (0x22): 0x
Write CTRL_REG4 (0x23): 0x00.
Write CTRL_REG5 (0x24): 0x
Write INT1_THS (0x32): 0x
Write INT1_DURATION (0x33): 0x00.
Read CTRL_REG1 (0x20): 0x
Read CTRL_REG2 (0x21): 0x
Read CTRL_REG3 (0x22): 0x
Read CTRL_REG4 (0x23): 0x00.
Read CTRL_REG5 (0x24): 0x
Read INT1_THS (0x32): 0x
Read INT1_DURATION (0x33): 0x00.
Read REFERENCE (0x26): 0x00.
Write INT1_CFG (0x34): 0x2a.
Read INT1_CFG (0x34): 0x2a.
Read X 0 Y 1 Z 0.
Read X 0 Y -1 Z -1.
Read X -1 Y -1 Z 0.
Read X -2 Y 0 Z -1.
Read X -1 Y -1 Z 0.
Read X 117 Y -131 Z
Read X 13 Y -39 Z -5.
Read X 0 Y -8 Z 4.
Read X 0 Y -1 Z -1.
Read X -1 Y -1 Z 1.
Read X 0 Y 1 Z 1.
Read X -1 Y 1 Z 0.
Read X -1 Y -2 Z -1.
Read X -47 Y 63 Z -
Read X 44 Y 5 Z -8.
Read X -10 Y -1 Z 2.
Read X 39 Y 78 Z
Read X 12 Y 20 Z 1.
Read X -1 Y 1 Z 0.
Read X 0 Y 0 Z 0.
Read X 0 Y 0 Z 0.
Read X 0 Y 0 Z 1.
Read X -1 Y -1 Z 1.
Read X -1 Y -1 Z -1.
Read X 1 Y 1 Z 1.
Read X 1 Y -2 Z -2.
Read X 0 Y 0 Z 0.
Read X -1 Y -1 Z 0.
Read X 1 Y 1 Z 0.
Read X -1 Y 0 Z 1.
Read X -1 Y 0 Z -1.
Read X 0 Y 0 Z 0.
Read X 1 Y -1 Z 0.
Read X 1 Y -1 Z 0.
Read X 1 Y -1 Z 0.
Read X 2 Y 0 Z 1.
Read X 0 Y -1 Z -2.
Read X 1 Y 1 Z 0.
Read X -57 Y 78 Z 4.
Read X -1 Y -1 Z -1.
Read X 2 Y -2 Z -1.
Read X 0 Y -2 Z 0.
Read X -1 Y -2 Z 1.
Read X -1 Y 0 Z -1.
________________ Attachments : main.cpp.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HxRp&d=%2Fa%2F0X0000000ayA%2F4da.Ij.bL8xF3GQpwcL9udfPNT5j.v8n2_JCr9k.qsY&asPdf=false2018-07-05 03:42 AM
One more point of information: if I read INT1_SRC on a regular basis it is always 0, so it's not just the IA bit (and the INT1 output) that is not being set, there is no interrupt source at all (code attached that does this). Something must be wrong with my configuration somehow. Could there be a timing thing going on?
Read I_AM_LIS3DH (0x0f): 0x
Write CTRL_REG1 (0x20): 0x
Write CTRL_REG2 (0x21): 0x
Write CTRL_REG3 (0x22): 0x
Write CTRL_REG4 (0x23): 0x00.
Write CTRL_REG5 (0x24): 0x
Write INT1_THS (0x32): 0x
Write INT1_DURATION (0x33): 0x00.
Read CTRL_REG1 (0x20): 0x
Read CTRL_REG2 (0x21): 0x
Read CTRL_REG3 (0x22): 0x
Read CTRL_REG4 (0x23): 0x00.
Read CTRL_REG5 (0x24): 0x
Read INT1_THS (0x32): 0x
Read INT1_DURATION (0x33): 0x00.
Read REFERENCE (0x26): 0x00.
Write INT1_CFG (0x34): 0x2a.
Read INT1_CFG (0x34): 0x2a.
Read INT1_SRC (0x31): 0x00.
Read X 0 Y 0 Z 0.
Read INT1_SRC (0x31): 0x00.
Read X 0 Y 1 Z 1.
Read INT1_SRC (0x31): 0x00.
Read X -1 Y 0 Z -1.
Read INT1_SRC (0x31): 0x00.
Read X 0 Y 0 Z 1.
Read INT1_SRC (0x31): 0x00.
Read X -2 Y -2 Z 4.
Read INT1_SRC (0x31): 0x00.
Read X 22 Y 179 Z -
Read INT1_SRC (0x31): 0x00.
Read X -3 Y -1 Z -1.
...
________________ Attachments : main.cpp.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HxRk&d=%2Fa%2F0X0000000ay9%2F6b97sEGfD4jrbvqnruzDxz_P9sxOGhCulJtZPmkS4xk&asPdf=false2018-07-06 01:15 AM
Sorted it! Checking and double-checking, in my simple code I was writing to INT2_CFG (0x34) not INT1_CFG (0x30). Write to the correct register and it works. Of course, this mistake is only in my sample code posted here, my real target code is writing to the correct register, but at least I have an example to work from now.
Thanks for all your help
Batek.Miroslav
!Rob
2018-07-06 03:26 AM
In case it helps anyone else, I've now got to the bottom of the problem in my real target code. It was down to understanding the meaning of the 6 interrupt enable bits in INTx_CFG. I had thought that if I set a threshold of, say 16, then if I set, for instance, the ZHIE and ZLIE bits
in INTx_CFG
, then I would get an interrupt if the Z axis acceleration went above +16 or below -16. What I now understand it that it will give me an interrupt if the Z axis acceleration goes above 16 or below 16, hence it goes off all the time. So the resolution is to set just the xHIE bits, which is what the example code does.