AnsweredAssumed Answered

MMA8452Q accelerometer

Question asked by Bryan Bennett on May 15, 2015

I am using the the MMA8452Q Breakout board from Spark Fun (SparkFun Triple Axis Accelerometer Breakout - MMA8452Q - SEN-12756 - SparkFun Electronics)

I have followed the steps exactly on page 11 of "Motion and Freefall Detection Using the MMA8451, 2, 3Q" (http://cache.freescale.com/files/sensors/doc/app_note/AN4070.pdf), but my MMA8452Q accelerometer continues to indicate motion detection even when it is completely still.

 

My C code is:

 

 

#define MMA8452Q_ADDR  0x3A  //0b 0011 1010 (accelerometer device I2C address (0x1D) plus 0 LSb for R/W bit)

 

#define INT_SOURCE 0x0C  // system interrupt status register

#define FF_MT_CFG  0x15  // motion configuration register address

#define FF_MT_SRC 0x16   // motion source register

#define FF_MT_THS  0x17  // motion threshold register address

#define FF_MT_COUNT 0x18 // motion debounce counter register address

#define CTRL_REG1  0x2A  // system control 1 register address

#define CTRL_REG4  0x2D  // system control 4 register address

#define CTRL_REG5  0x2E  // system control 5 register address

 

 

volatile int FFMT_IntSourceReg_data; // holds data from FF_MT_SRC register in accelerometer MMA8452Q

 

volatile int IntSourceSystemRegData; // holds data from INT_SOURCE register in accelerometer MMA8452Q

 

int main (void)

{

 

 

  consecutive = 0;

 

  n = 0;

  configI2C1(400); // configure I2C baud rate for 400 KHz

  write2I2C1(MMA8452Q_ADDR, CTRL_REG1, 0x18); // ODR=100Hz, LNOISE=1, F_READ=0, ACTIVE=0

  write2I2C1(MMA8452Q_ADDR, FF_MT_CFG, 0xD8); // ELE=1, OAE=1, ZEFE=0, YEFE=1, XEFE=1

  write2I2C1(MMA8452Q_ADDR, FF_MT_THS, 0x30); // 3g/0.063g=47.6 (round up to 48), Threshold > 3g

  write2I2C1(MMA8452Q_ADDR, FF_MT_COUNT, 0x0A); // set debounce counter to eliminate false readings for 100Hz sample rate with requirement of 100 ms timer

  write2I2C1(MMA8452Q_ADDR, CTRL_REG4, 0x04); // disable auto SLEEP/WAKE interrupt, enable FF_MT interrupt

  write2I2C1(MMA8452Q_ADDR, CTRL_REG5, 0x04); // FF_MT interrupt output signal assigned to INT1 pin of MMA8452Q

  write2I2C1(MMA8452Q_ADDR, CTRL_REG1, 0x19); // put MMA8452Q in ACTIVE mode

 

 

if (TimerCount % 1000 == 0)

 

   {

    write1I2C1(MMA8452Q_ADDR, INT_SOURCE);

    read1I2C1(MMA8452Q_ADDR, &IntSourceSystemRegData);  

    if ((IntSourceSystemRegData & 0x04)==0x04)

     { 

        n++;

        consecutive = -3;

        readRTCC(); // read real time clock and calendar

        printf("MOTION DETECTION n=%d consecutive=%3d %02d:%02d:%02d\n",n,consecutive,HOUR,MIN,SEC);

        write1I2C1(MMA8452Q_ADDR, FF_MT_SRC);

        read1I2C1(MMA8452Q_ADDR, &FFMT_IntSourceReg_data); // read the FF_MT_SRC register to clear the interrupt

     }

       

   }

   

} // end of main

 

My "TimerCount" variable just assures that the INT_SOURCE register will be read and checked for an indication of motion every second.

 

I have actually run the above program with 2 different MMA8452Q accelerometers, and I get the same results with both accelerometers: Every second the accelerometer claims that motion has occurred (i.e., "MOTION DETECTION" is printed) even though the accelerometer is perfectly still. I am only trying to detect when motion occurs in a sleeping subject; I am not interested in the specifics of the motion; however, I also ran a program that looked at the values of the OUT_X_MSB, OUT_Y_MSB, and OUT_Z_MSB registers, and they displayed a constant value of 255 even when no motion was occurring.

 

Can someone please tell me what I am doing wrong?

 

Thanks,

 

Bryan Bennett

Outcomes