MMA8451Q motion detecion

cancel
Showing results for 
Search instead for 
Did you mean: 

MMA8451Q motion detecion

629 Views
caibai
Contributor III

hi,i want use MMA8451Q to detect move and init it as

bool MMA8451Q_Init(void){

    unsigned char val;

    /* Place the MMA8451Q in sleep mode,ODR 100HZ */
    MMA8451Q_WriteReg(0x2A,0x18);
    /* motion detection,enable XYZ */
    MMA8451Q_WriteReg(0x15,0xD8);
    /* set threshold */
    MMA8451Q_WriteReg(0x17,0x08);
    MMA8451Q_WriteReg(0x18,0x0A);
    /* enable motion dection interrupt */
    MMA8451Q_WriteReg(0x2D,0x04);
    /* set interrupt pin */
    MMA8451Q_WriteReg(0x2E,0x04);
#if 0
    /* Set on-board Acc sensor range to 8G */
    MMA8451Q_WriteReg(0x0E,0x02);
#endif
    val = MMA8451Q_ReadReg(0x2A);
    MMA8451Q_WriteReg(0x2A,val | 0x01);
    /* Acc sensor WHO_AM_I check... */
    if (0x1A == MMA8451Q_ReadReg(0x0D)){
        MMA8451Q_GpioIntInit();
        return true;
    }else{
        return false;
    }

}

after init ,i read  some of reg and print as follow

Reg addr  <-->  val

Reg 0x09 <--> 0x00
Reg 0x0a <--> 0x00
Reg 0x0b <--> 0x01
Reg 0x0c <--> 0x00
Reg 0x0d <--> 0x1a
Reg 0x0e <--> 0x00
Reg 0x0f <--> 0x00
Reg 0x10 <--> 0x00
Reg 0x11 <--> 0x80
Reg 0x12 <--> 0x00
Reg 0x13 <--> 0x44
Reg 0x14 <--> 0x84
Reg 0x15 <--> 0xd8
Reg 0x16 <--> 0x00
Reg 0x17 <--> 0x08
Reg 0x18 <--> 0x0a
Reg 0x1d <--> 0x00
Reg 0x1e <--> 0x00
Reg 0x1f <--> 0x00
Reg 0x20 <--> 0x00
Reg 0x21 <--> 0x00
Reg 0x22 <--> 0x00
Reg 0x23 <--> 0x00
Reg 0x24 <--> 0x00
Reg 0x25 <--> 0x00
Reg 0x26 <--> 0x00
Reg 0x27 <--> 0x00
Reg 0x28 <--> 0x00
Reg 0x29 <--> 0x00
Reg 0x2a <--> 0x19
Reg 0x2b <--> 0x00
Reg 0x2c <--> 0x00
Reg 0x2d <--> 0x04
Reg 0x2e <--> 0x04
Reg 0x2f <--> 0x00
Reg 0x30 <--> 0x00
Reg 0x31 <--> 0x00

iic work OK,and reg value is right,but i can't recv any interrupt signal from MMA8451Q.

i read reg 0x0C(INT_SOURCE) in a dead loop and print it,it always is 0x00.

can you help me?

Labels (2)
0 Kudos
2 Replies

100 Views
david_diaz
NXP Employee
NXP Employee

Hello,

Thank you for writing.

In order to configure the MMA8451Q in Motion Detection mode, I suggest using the following configuration:

      unsigned char reg_val = 0;

 

      I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG2, 0x40);        // Reset all registers to POR values

 

      do    // Wait for the RST bit to clear

      {

              reg_val = I2C_ReadRegister(MMA845x_I2C_ADDRESS, CTRL_REG2) & 0x40;

      }while (reg_val);

 

      I2C_WriteRegister(MMA845x_I2C_ADDRESS, XYZ_DATA_CFG_REG, 0x02); // +/-8g range

      I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG1, 0x18);                 // ODR = 100Hz, Standby mode

  

      I2C_WriteRegister(MMA845x_I2C_ADDRESS, FF_MT_CFG_REG, 0x58);       // Motion detection for X and Y axis

      I2C_WriteRegister(MMA845x_I2C_ADDRESS, FT_MT_THS_REG, 0x08);       // Threshold Setting Value for the Motion detection (0.5g)

      I2C_WriteRegister(MMA845x_I2C_ADDRESS, FF_MT_COUNT_REG, 0x05);  // Set the debounce counter to 50 ms timer (50ms)

       

      I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG4, 0x04);                // Enable Motion/Freefall Interrupt

      I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG5, 0x04);                // Motion/Freefall interrupt routed to INT1 - PTA14

 

      reg_val = I2C_ReadRegister(MMA845x_I2C_ADDRESS, CTRL_REG1);          // Put the device in active mode

      I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG1, reg_val | 1);

 

 

In case you need more details about the Auto-WAKE/SLEEP mode, I recommend the following post:

https://community.nxp.com/docs/DOC-332453

 

Please let me know if you have any further question about the code mentioned above.

Best Regards,

David

100 Views
caibai
Contributor III

it work now ,thank you very much.

0 Kudos