MMA8652FC tap detection

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MMA8652FC tap detection

Jump to solution
2,209 Views
estratos
Contributor I

I'm currently working with a MMA8652FC 3-Axis, 12-bit Digital Accelerometer. I've been able to configure the sensor and read axis data (acc) from a MSP430 MCU but now I want to go a step further. This time I want the MMA8652FC to cause an interrupt whenever a tap or a double-tap is detected but I've been unable to find any related documentation or example in the web. Only AN4083 explains how to configure generic interrupts but the pulse detection seems to be much more complicated with all those partial enabling bits and threshold values.

This is how I'm configuring the sensor so far:

// Enter STANDBY mode

accel.write(MMA8652_CTRL_REG1  0);

// Dynamic range

accel.write(MMA8652_XYZ_DATA_CFG  0);  // Dynamic range = +-2g

// Enable interrupts

accel.write(MMA8652_CTRL_REG3, 0x10)   // Pulse function interrupt can wake-up system

// Enable Pulse detection

accel.write(MMA8652_CTRL_REG4, 0x04)   // Enable Pulse Detection Interrupt

// Enable pulse detection on each axis

accel.write(MMA8652_PULSE_CFG, 0x55);  // Enable single Pulse Detection on all axis

// Pulse thresholds

accel.write(MMA8652_PULSE_THSX, 0x0A); // Threshold X = 10

accel.write(MMA8652_PULSE_THSY, 0x0A); // Threshold Y = 10

accel.write(MMA8652_PULSE_THSZ, 0x0A); // Threshold Z = 10

// Enter ACTIVE mode

accel.write(MMA8652_CTRL_REG1  0x21);    // ACTIVE mode, Normal mode, data rate = 400 Hz

The above code is supposed to generate a (falling) interrupt on INT2 when a tap or double-tap event is detected but it's not the case. Is there any sample code where I could get some ideas from?

Thanks in advance for your time.

Daniel.

Tags (2)
0 Kudos
Reply
1 Solution
1,199 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Daniel,

Have you already set the INT_EN_PULSE bit by writing 0x08 to the CTRL_REG4 register? It seems like the Pulse detection interrupt has not been enabled yet.


Regards,

Tomas

View solution in original post

0 Kudos
Reply
4 Replies
1,199 Views
estratos
Contributor I

Some additional information:

PULSE_SOURCE register (0x22) does show pulses occurring on each axis.

INT_SOURCE register (0x0C) always shows value 0, which means that no event is detected.

Thanks again.

0 Kudos
Reply
1,200 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Daniel,

Have you already set the INT_EN_PULSE bit by writing 0x08 to the CTRL_REG4 register? It seems like the Pulse detection interrupt has not been enabled yet.


Regards,

Tomas

0 Kudos
Reply
1,199 Views
estratos
Contributor I

Thanks Thomas!! What a stupid mistake...

0 Kudos
Reply
1,199 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hello Daniel,

By writing 0x04 to the CTRL_REG4 register, you are actually enabling the Freefall/Motion interrupt. To enable the Pulse detection interrupt you need to set the INT_EN_PULSE bit by writing 0x08 to the CTRL_REG4 register. Then you should be able to see an active low interrupt on the INT2 pin when a tap or double-tap event on any axis is detected. Note that it is necessary to read the PULSE_SRC register to clear the SRC_PULSE bit in the INT_SOURCE register and consequently deassert the interrupt.

Attached you can find my example code written for the MMA8652FC that demonstrates how to use the auto-wake/sleep function with the pulse (tap) function used to wake up the device.

Let me know whether or not this helps, or if you have any other questions.


Regards,

Tomas


PS: If my answer helps to solve your question, please mark it as "Correct" or “Helpful”. Thank you.