AnsweredAssumed Answered

mma8451 FIFO count never reaches true value

Question asked by wingsof on Mar 30, 2015
Latest reply on Mar 31, 2015 by wingsof

Hello.

I have a strange problem with my mma8451 accelerometers.

Whenever i read FIFO_CNT register value, it always returns me the value, which is one fewer than it has to.

For example, after FIFO configuration (0x80 put in F_SETUP register) it is expected, that the FIFO_CNT value after interrupt generation will be 32, but it is not, it is equal to 31. The same situation occurs when i tried to enable WATERMARK interrupt by placing 0x60 in F_SETUP register, but again, the FIFO_CNT value is equal to 31 when the interrupt was generated (but datasheet states that the interrupt is generated when F_CNT == F_WMRK).

Another issue is the last chunk of data from fifo, for example, when FIFO_CNT equal to 16 and i read exactly 16 samples the last ones from registers are 0x80.

Could someone suggest something regarding these issues? The i2c bus is ok, i have magnetometers and gyroscopes which work flawlessly.

 

There are some parts of my code:

uint8_t e_n;
uint8_t tmp1[6*32];
i2c->read(MMA8451Q_ADDR, 0x00, &e_n, 1);
// e_n number never exceeds 31 in decimal
e_n = e_n & 0x3f; 
i2c->read(MMA8451Q_ADDR, 0x0c, &tmp, 1); 
i2c->read(MMA8451Q_ADDR, MMA8451Q_OUT_X_MSB, &tmp1[0], 6 * e_n); 
int x, y, z;
for (int i = 0; i < e_n; i++)
{
     // on the last iteration the tmp[i*6+x] values equal to 0x80
     x = (int)(((int8_t)tmp1[i*6 + 0]) * 64) | ((tmp1[i*6 + 1] >> 2) & 0x3F); 
     y = (int)(((int8_t)tmp1[i*6 + 2]) * 64) | ((tmp1[i*6 + 3] >> 2) & 0x3F); 
     z = (int)(((int8_t)tmp1[i*6 + 4]) * 64) | ((tmp1[i*6 + 5] >> 2) & 0x3F);
}

Outcomes