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.
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