mma8451& FIFO buffer

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

mma8451& FIFO buffer

1,622 Views
alessio31183
Contributor I

Hi,

I'm using the MMA8451 to make a tilt sensor.

Everything is Arduino based using the classic ATmega328P.

My intention is to use the FIFO buffer to get it full with 32 samples @ 800HZ in active mode without any sleep function.

In the setup function I set the register like this:

  writeRegister8(MMA8451_REG_CTRL_REG2, 0x40); // reset

  while (readRegister8(MMA8451_REG_CTRL_REG2) & 0x40);

  writeRegister8(MMA8451_REG_CTRL_REG1, 0x00);     // Standby mode (DEACTIVE) @ 800Hz
  writeRegister8(MMA8451_REG_FIFO_SETUP, 0x60);    // FIFO in circular buffer. watermark set to 32
  writeRegister8(MMA8451_REG_CTRL_REG2, 0x02);     // High resolution
  writeRegister8(MMA8451_REG_CTRL_REG3, 0x02);     // push-pull active-high
  writeRegister8(MMA8451_REG_CTRL_REG4, 0x40);     // FIFO interrupt enabled
  writeRegister8(MMA8451_REG_CTRL_REG5, 0x40);     // Interrupt is routed to INT1 pin
  writeRegister8(MMA8451_REG_CTRL_REG1, 0x01);     // Active mode and reduced noise mode. ODR = 800Hz

  attachInterrupt(0, INT0_ISR, RISING);      // for the accelerometer FIFO register reading

and at the beginning I have the interrupt where I would have to read all the 32 samples.

void INT0_ISR()
{

  // For an I2C bit rate of 400 kHz, FIFORead(32) + 3 μs = 4.878 ms.
  for (byte i=1; i<=OSR; i++)
  {
    // Read the 'raw' data in 14-bit counts
    readAcceleration(&x, &y, &z);

  }

But anything works because I'm not able to get the buffer empty reading all the values.

Basically the interrupt pin stays high forever.

Even I tried to clear the flag interrupt without success

  readRegister8(MMA8451_REG_INT_SOURCE);
  readRegister8(MMA8451_REG_FIFO_STATUS);

Then anyone is able to help me ?

Thanks in advance to everyone who spends time for this.

Labels (1)
0 Kudos
1 Reply

1,375 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Alessio,

I would recommend you to take a look at my example code. It is written for the FXLS8471, but it should be identical for the MMA8451Q.

I hope it helps.

Best regards,

Tomas

0 Kudos
%3CLINGO-SUB%20id%3D%22lingo-sub-801082%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3Emma8451%26amp%3B%20FIFO%20buffer%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-801082%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EI'm%20using%20the%20MMA8451%20to%20make%20a%20tilt%20sensor.%3C%2FP%3E%3CP%3EEverything%20is%20Arduino%20based%20using%20the%20classic%20ATmega328P.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EMy%20intention%20is%20to%20use%20the%20FIFO%20buffer%20to%20get%20it%20full%20with%2032%20samples%20%40%20800HZ%20in%20active%20mode%20without%20any%20sleep%20function.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EIn%20the%20setup%20function%20I%20set%20the%20register%20like%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%20writeRegister8(MMA8451_REG_CTRL_REG2%2C%200x40)%3B%20%2F%2F%20reset%3C%2FP%3E%3CP%3E%26nbsp%3B%20while%20(readRegister8(MMA8451_REG_CTRL_REG2)%20%26amp%3B%200x40)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20writeRegister8(MMA8451_REG_CTRL_REG1%2C%200x00)%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20Standby%20mode%20(DEACTIVE)%20%40%20800Hz%3CBR%20%2F%3E%26nbsp%3B%20writeRegister8(MMA8451_REG_FIFO_SETUP%2C%200x60)%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20FIFO%20in%20circular%20buffer.%20watermark%20set%20to%2032%3CBR%20%2F%3E%26nbsp%3B%20writeRegister8(MMA8451_REG_CTRL_REG2%2C%200x02)%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20High%20resolution%3CBR%20%2F%3E%26nbsp%3B%20writeRegister8(MMA8451_REG_CTRL_REG3%2C%200x02)%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20push-pull%20active-high%3CBR%20%2F%3E%26nbsp%3B%20writeRegister8(MMA8451_REG_CTRL_REG4%2C%200x40)%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20FIFO%20interrupt%20enabled%3CBR%20%2F%3E%26nbsp%3B%20writeRegister8(MMA8451_REG_CTRL_REG5%2C%200x40)%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20Interrupt%20is%20routed%20to%20INT1%20pin%3CBR%20%2F%3E%26nbsp%3B%20writeRegister8(MMA8451_REG_CTRL_REG1%2C%200x01)%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20Active%20mode%20and%20reduced%20noise%20mode.%20ODR%20%3D%20800Hz%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%20attachInterrupt(0%2C%20INT0_ISR%2C%20RISING)%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20for%20the%20accelerometer%20FIFO%20register%20reading%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3Eand%20at%20the%20beginning%20I%20have%20the%20interrupt%20where%20I%20would%20have%20to%20read%20all%20the%2032%20samples.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3Evoid%20INT0_ISR()%3CBR%20%2F%3E%7B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%2F%2F%20For%20an%20I2C%20bit%20rate%20of%20400%20kHz%2C%20FIFORead(32)%20%2B%203%20%CE%BCs%20%3D%204.878%20ms.%20%3CBR%20%2F%3E%26nbsp%3B%20for%20(byte%20i%3D1%3B%20i%26lt%3B%3DOSR%3B%20i%2B%2B)%3CBR%20%2F%3E%26nbsp%3B%20%7B%20%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20Read%20the%20'raw'%20data%20in%2014-bit%20counts%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20readAcceleration(%26amp%3Bx%2C%20%26amp%3By%2C%20%26amp%3Bz)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%7D%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EBut%20anything%20works%20because%20I'm%20not%20able%20to%20get%20the%20buffer%20empty%20reading%20all%20the%20values.%3C%2FP%3E%3CP%3EBasically%20the%20interrupt%20pin%20stays%20high%20forever.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EEven%20I%20tried%20to%20clear%20the%20flag%20interrupt%20without%20success%3C%2FP%3E%3CP%3E%26nbsp%3B%20readRegister8(MMA8451_REG_INT_SOURCE)%3B%3CBR%20%2F%3E%26nbsp%3B%20readRegister8(MMA8451_REG_FIFO_STATUS)%3B%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EThen%20anyone%20is%20able%20to%20help%20me%20%3F%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EThanks%20in%20advance%20to%20everyone%20who%20spends%20time%20for%20this.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-801082%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3EAccelerometers%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-801083%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20mma8451%26amp%3B%20FIFO%20buffer%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-801083%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%20Alessio%2C%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EI%20would%20recommend%20you%20to%20take%20a%20look%20at%20my%20%3CA%20_jive_internal%3D%22true%22%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Fdocs%2FDOC-173015%22%20target%3D%22_blank%22%3Eexample%20code%3C%2FA%3E.%26nbsp%3BIt%20is%20written%20for%20the%20FXLS8471%2C%20but%20it%20should%20be%20identical%20for%20the%20MMA8451Q.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EI%20hope%20it%20helps.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EBest%20regards%2C%3C%2FP%3E%3CP%3ETomas%3C%2FP%3E%3C%2FLINGO-BODY%3E