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