Hi Tomas,
I have also referred a sample shared by you. and updated my code.. still the output is not as expected.
the code snippet is as below:
typedef enum EAccReg{
eMMA8451_STATUS = 0x00,
eMMA8451_OUT_X_MSB,
eMMA8451_OUT_X_LSB,
eMMA8451_OUT_Y_MSB,
eMMA8451_OUT_Y_LSB,
eMMA8451_OUT_Z_MSB,
eMMA8451_OUT_Z_LSB,
eMMA8451_F_SETUP = 0x09,
eMMA8451_TRIG_CFG,
eMMA8451_SYSMOD,
eMMA8451_INT_SOURCE,
eMMA8451_WHO_AM_I,
eMMA8451_XYZ_DATA_CFG,
eMMA8451_HP_FILTER_CUTOFF,
eMMA8451_PL_STATUS,
eMMA8451_PL_CFG,
eMMA8451_PL_COUNT,
eMMA8451_PL_BF_ZCOMP,
eMMA8451_P_L_THS_REG,
eMMA8451_FF_MT_CFG,
eMMA8451_FF_MT_SRC,
eMMA8451_FF_MT_THS,
eMMA8451_FF_MT_COUNT,
eMMA8451_TRANSIENT_CFG = 0x1D,
eMMA8451_TRANSIENT_SRC,
eMMA8451_TRANSIENT_THS,
eMMA8451_TRANSIENT_COUNT,
eMMA8451_PULSE_CFG,
eMMA8451_PULSE_SRC,
eMMA8451_PULSE_THSX,
eMMA8451_PULSE_THSY,
eMMA8451_PULSE_THSZ,
eMMA8451_PULSE_TMLT,
eMMA8451_PULSE_LTCY,
eMMA8451_PULSE_WIND,
eMMA8451_ASLP_COUNT,
eMMA8451_CTRL_REG1,
eMMA8451_CTRL_REG2,
eMMA8451_CTRL_REG3,
eMMA8451_CTRL_REG4,
eMMA8451_CTRL_REG5,
eMMA8451_OFF_X,
eMMA8451_OFF_Y,
eMMA8451_OFF_Z,
eMMA8451_REG_END,
}TEAccReg;
void test()
{
unsigned char uiCTRL_REG1 = 0;
unsigned char ucBuff = 0x18;
/* Open I2c file i2c-0 */
ML_ACC_giI2cFd = I2COpen(I2C_DEV_1);
if(ML_ACC_giI2cFd < 0)
{
printf("Unable to open i2c file\n");
}
if(ioctl(ML_ACC_giI2cFd,I2C_SLAVE_FORCE, MMA8452_I2C_ADDRESS) < 0)
{
printf("\nioctl error\n");
}
else
{
printf(" ioctl success\n");
}
/* Put the device into Standby Mode */
I2CWriteRegisterVal(ML_ACC_giI2cFd,eMMA8451_CTRL_REG1,ucBuff,2,
MMA8452_I2C_ADDRESS);
ucBuff = 0xD8;
/* Set Configuration Register for Motion Detection by setting
* the “OR” condition OAE = 1, enabling X, Y, and the latch
*/
I2CWriteRegisterVal(ML_ACC_giI2cFd,eMMA8451_FF_MT_CFG,ucBuff,2,
MMA8452_I2C_ADDRESS);
ucBuff = 0x85;
// Set threshold to 312.5mg (5 x 62.5mg )
I2CWriteRegisterVal(ML_ACC_giI2cFd,eMMA8451_FF_MT_THS,ucBuff,2,MMA8452_I2C_ADDRESS);
ucBuff = 0x02;
// Latch enabled, motion detection enabled for X and Y axis
I2CWriteRegisterVal(ML_ACC_giI2cFd,eMMA8451_FF_MT_COUNT,ucBuff,2,MMA8452_I2C_ADDRESS);
ucBuff = 0x04;
/* Enable Motion/Freefall Interrupt Function in the System */
I2CWriteRegisterVal(ML_ACC_giI2cFd,eMMA8451_CTRL_REG4,ucBuff,2,MMA8452_I2C_ADDRESS);
ucBuff = 0x04;
I2CWriteRegisterVal(ML_ACC_giI2cFd,eMMA8451_CTRL_REG5,ucBuff,2,
MMA8452_I2C_ADDRESS);
/* active mode */
uiCTRL_REG1 = 0x29;
I2CWriteRegisterVal(ML_ACC_giI2cFd,eMMA8451_CTRL_REG1,uiCTRL_REG1,1,
MMA8452_I2C_ADDRESS);
while(1)
{
I2CReadRegisterVal(ML_ACC_giI2cFd,eMMA8451_INT_SOURCE,&uiIntSourceSystem,1,
MMA8452_I2C_ADDRESS);
/* Set up Case statement here to service all of the possible interrupts */
/*Perform an Action since Motion Flag has been set
* Read the Motion/Freefall Function to clear the interrupt
*/
printf("eMMA8451_INT_SOURCE = 0x%x\n",uiIntSourceSystem);
I2CReadRegisterVal(ML_ACC_giI2cFd,eMMA8451_FF_MT_SRC,&uiMotionStatus,1,
MMA8452_I2C_ADDRESS);
if(isSet(uiMotionStatus,7) == 1)
{
printf("PlayAlarm\n");
}
printf("uiMotionStatus_ofl = 0x%x\n",uiMotionStatus);
}
}
The output of abov code as below:
uiMotionStatus_ofl = 0x89
eMMA8451_INT_SOURCE = 0x4
PlayAlarm
uiMotionStatus_ofl = 0x89
eMMA8451_INT_SOURCE = 0x4
PlayAlarm
uiMotionStatus_ofl = 0x89
eMMA8451_INT_SOURCE = 0x4
PlayAlarm
uiMotionStatus_ofl = 0x88
eMMA8451_INT_SOURCE = 0x4
PlayAlarm
uiMotionStatus_ofl = 0x89
eMMA8451_INT_SOURCE = 0x4
PlayAlarm
uiMotionStatus_ofl = 0x89
eMMA8451_INT_SOURCE = 0x4
PlayAlarm
uiMotionStatus_ofl = 0x88
eMMA8451_INT_SOURCE = 0x4
Here it is detecting the movement, but I am still confused in output I am getting.. why am I getting the Play alarm in every read?
As per my understanding I should get it after device movement. Please correct me If I am wrong.
Best Regards,
Pallavi Ingole