AnsweredAssumed Answered

MMA8452 interrupt stays high forever

Question asked by Sreejith Chandrasekharan on Dec 30, 2013
Latest reply on Oct 28, 2015 by Anthony Duhamel

Hi,

I'm using the MMA8452Q for one of my projects and it stays at high at the pin2 (Arduino Uno) (int0?) always. Following are the configurations that we have for the chip. Please note that only one interrupt which is INT_TRANS is enabled. We read the INT_SOURCE register and we can see the corresponding interrupt bit is set. In order to clear the interrupt we are reading the TRANSIENT_SRC register. 

Can you please tell us what is wrong with the our code? Have you ever seen any similar issue with the interrupts on this chips?

 

Thanks a lot in advance. Would really appreciate a swift response.

Sree

 

 

// The SparkFun breakout board defaults to 1, set to 0 if SA0 jumper on the bottom of the board is set

#define MMA8452_ADDRESS 0x1D  // 0x1D if SA0 is high, 0x1C if low

 

 

//Define a few of the registers that we will be accessing on the MMA8452

#define OUT_X_MSB 0x01

#define XYZ_DATA_CFG  0x0E

#define WHO_AM_I   0x0D

 

 

// Control registers

#define CTRL_REG1  0x2A

#define CTRL_REG2  0x2B

#define CTRL_REG3  0x2C

#define CTRL_REG4  0x2D

#define CTRL_REG5  0x2E

#define ASLP_COUNT  0x29

 

 

// Iniitial values of Control Registers

#define ASLP_12_5_HZ  0x40

#define ODR_50_HZ  0x20

#define LNOISE_DEFAULT  0x00

#define F_READ_DEFAULT  0x00

 

 

#define SLPE  0x04 

#define SMODS_LOW_POW  0x18

#define MODS_NORMAL_POW  0x00

#define ST_DEFAULT  0x00

#define RST_DEFAULT  0x00

 

 

 

 

#define WAKE_FF_MT  0x08

#define WAKE_TRANS  0x40 

#define IPOL_DEFAULT 0x00

#define PP_OD_DEFAULT 0x00

 

 

#define INT_EN_FF_MT  0x04

#define INT_EN_TRANS  0x20

#define INT_EN_ASLP  0x80

 

 

#define INT_CFG_FF_MT  0x04

#define INT_CFG_TRANS  0x20

 

 

#define ASLP_COUNT_50_HZ_960_MS  0x03

 

#define ELE  0x80

#define OAE_MOTION  0x40

#define XYZ_EFE 0x18

 

 

#define DBCNTM_MOTION  0x00

#define THS_0_2_G  0x0B

 

 

#define FF_MT_DEBOUNCE_50_HZ_20_MS  0x0A

 

 

#define ELE  0x10

#define XYZ_EFE 0x06

#define HPF_BYP 0x00

 

 

#define DBCNTM_TRANS  0x00

#define TRANS_THS_0_5_G  0x05

 

 

#define TRANS_DEBOUNCE_50_HZ_20_MS  0x03

 

 

//The SRC registers for clearing and reading status of interrupts

#define SYSMOD 0x0B

#define TRANSIENT_SRC 0x1E    

#define FF_MT_SRC 0x16 

 

 

// Motion Detection registers

#define FF_MT_CFG  0x15

#define FF_MT_SRC  0x16

#define FF_MT_THS  0x17

#define FF_MT_COUNT  0x18

 

 

//Transient registers

#define TRANSIENT_CFG 0x1D

#define TRANSIENT_THS 0x1F

#define TRANSIENT_COUNT 0x20

 

 

#define INT_SOURCE  0x0C

 

 

void setup()

{

 

  /* ACCELEROMETER setup */

  pinMode(11,OUTPUT);

  pinMode(10,OUTPUT);

  pinMode(9,OUTPUT);

  pinMode(3,OUTPUT);

  pinMode(2,OUTPUT); 

 

  Wire.begin(); //Join the bus as a master

  initMMA8452(); //Test and intialize the MMA8452 

 

  Serial.println("Attaching the interrupt lines");

  attachInterrupt(0, int0_bh, CHANGE);

  attachInterrupt(1, int1_bh, CHANGE);

  Serial.println("Attaching interrupt lines was successful!!!");

}

 

 

void initMMA8452()

{

  byte val = readRegister(WHO_AM_I);  // Read WHO_AM_I register

  if (val == 0x2A) // WHO_AM_I should always be 0x2A

  { 

    Serial.println("M is online...");

  }

  else

  {

    Serial.print("Could not connect to MMA8452Q: 0x");

    Serial.println(val, HEX);

    while(1) ; // Loop forever if communication doesn't happen

  }

 

 

  MMA8452Standby();  // Must be in standby to change registers

 

 

  // Initialize GSCALE

  val = GSCALE;

  if(val > 8) val = 8; //Easy error check

  val >>= 2; // Neat trick, see page 22. 00 = 2G, 01 = 4A, 10 = 8G

  writeRegister(XYZ_DATA_CFG, val);

 

 

  val = (ASLP_12_5_HZ | ODR_50_HZ | LNOISE_DEFAULT | F_READ_DEFAULT);

  writeRegister(CTRL_REG1, val);

 

  val = (ST_DEFAULT | RST_DEFAULT | SMODS_LOW_POW | SLPE | MODS_NORMAL_POW);

  writeRegister(CTRL_REG2, val);

 

 

  val = (WAKE_TRANS | 0x02 | PP_OD_DEFAULT);

  writeRegister(CTRL_REG3, val);

 

  val = 0;

  writeRegister(CTRL_REG5, val); 

 

  val = ASLP_COUNT_50_HZ_960_MS;

  writeRegister(ASLP_COUNT, val);

 

 

  val = (ELE | XYZ_EFE | HPF_BYP);

  writeRegister(TRANSIENT_CFG, val);

 

  val = (DBCNTM_TRANS | TRANS_THS_0_5_G);

  writeRegister(TRANSIENT_THS, val);

 

  val = TRANS_DEBOUNCE_50_HZ_20_MS;

  writeRegister(TRANSIENT_COUNT, val);   

 

 

  //The default data rate is 800Hz and we don't modify it in this example code

 

  val = (INT_EN_TRANS);

  writeRegister(CTRL_REG4, val);

 

 

  MMA8452Active();  // Set to active to start reading

}

 

 

// Sets the MMA8452 to standby mode. It must be in standby to change most register settings

void MMA8452Standby()

{

  byte c = readRegister(CTRL_REG1);

  writeRegister(CTRL_REG1, c & ~(0x01)); //Clear the active bit to go into standby

}

 

 

// Sets the MMA8452 to active mode. Needs to be in this mode to output data

void MMA8452Active()

{

  byte c = readRegister(CTRL_REG1);

  writeRegister(CTRL_REG1, c | 0x01); //Set the active bit to begin detection

}

Outcomes