How to set a freefall interrupt for MMA7455L and set it to an external interrupt on LPC1769?

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

How to set a freefall interrupt for MMA7455L and set it to an external interrupt on LPC1769?

646 Views
muhammadarifbi1
Contributor I

I want to trigger an interrupt when the board is in freefall. I've read the data sheet on the accelerometer but its as clear as mud. I want to set it to trigger an external interrupt. On my board, INT1/DRDY is set to P2.5 and INT2 is set to P1.8. So far, here is my code in the limited accelerometer library I was given:

 

void acc_setInterrupt() {
uint8_t buf[2];

buf[0] = ACC_ADDR_CTL1;
buf[1] = (0 << 1);

I2CWrite(ACC_I2C_ADDR, buf, 2);

}

void freefall_detection() {
uint8_t buf[2];

buf[0] = ACC_ADDR_CTL1;
buf[1] = (1<<6);
I2CWrite(ACC_I2C_ADDR, buf, 2);

uint8_t buf1[2];

buf1[0] = ACC_ADDR_CTL2;
buf1[1] = (1<<0);
I2CWrite(ACC_I2C_ADDR, buf1, 2);

uint8_t buf2[2];

buf2[0] = ACC_ADDR_LDTH;
buf2[1] = (7 & 0xff);
I2CWrite(ACC_I2C_ADDR, buf2, 2);
}

Original Attachment has been moved to: acc.c.zip

Labels (1)
0 Kudos
2 Replies

430 Views
darioarias
NXP Employee
NXP Employee

Hello Muhammad,

I have reviewed the code, but I could not find anything wrong with it, however there are a few ting that you may want to try.

First of all, I would try to increase the threshold value in the 0x1A register, this way, even small changes can create an interrupt, and you can try modifying register 0x16  (mode control) inside the function freefall_detection(); To make sure that you have the accelerometer in level detection mode.

Another point to consider is that, the device will enter a linear freefall condition only if the acceleration on all three axes are determined to be at 0g with a predefined margin. The MMA7455L has internal logic to detect linear freefall using either the Level detection or the Pulse Detection modes. The level detection (the one you are using) is not as robust because it does not have any timers associated with it. It simply detects any resultant output of X&&Y&&Z < Set Threshold. The pulse detection freefall condition is more robust because it has a timer. The pulse detection freefall algorithm looks at X&&Y&&Z < Threshold for > Latency Timer. The timer in the pulse detection helps avoid false readings.  I recommend you to use Pulse Detection instead.

Also, I would like to share with you the following application note The MMA745xL Digital Accelerometer, it has a detailed explanation on configuring the interrupts and some example code for I2C and SPI.

Dario

430 Views
muhammadarifbi1
Contributor I

Hi Dario,

Thanks, I have reviewed that application note and found it very helpful. I've changed it to pulse detection mode now and as soon as I have figured out timers, I'll probably get it working. Thanks again.

0 Kudos