Author Topic: Module 120 accelerometer communications  (Read 595 times)


  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Module 120 accelerometer communications
« Reply #15 on: December 13, 2016, 08:15:06 am »
Sorry for taking a while to respond, I've been busy on the road.

To answer your previous question, what this line is doing:

Code: [Select]
(accel.GetINT1ActiveInterrupt() & LIS2DH12.INT_ACTIVE) = LIS2DH12.INT_ACTIVE
This (accel.GetINT1ActiveInterrupt()) reads the INT1 register and returns the contents of the INT1 register. The INT1 register contains the bitmask that shows what caused the INT1 interrupt. I just AND it with INT1_ACTIVE (0x40 - ie bit 6 set) which will be 0x40 if the INT1 is in fact active, so comparing it with INT_ACTIVE will return TRUE if INT1 is active for any reason (and FALSE if it isn't). This reads the INT1 register, but does not tell you what caused the INT1 interrupt. In our case, I don't care what caused the interrupt, as we have configured the accelerometer to interrupt on shock, so we are assuming that is what caused the interrupt.

We then go on and reset the interrupt by resetting the trigger events with

Code: [Select]
accel.SetINT1ActiveInterrupt(LIS2DH12.INT_SRC_XH | LIS2DH12.INT_SRC_YH | LIS2DH12.INT_SRC_ZH)
Which tells the accelerometer to trigger on events in the X, Y or Z axis.

This isn't a very good way to use the accelerometer, I was just adapting the code from josh to work with my library. There are much more sensible ways of doing this.