mma8451 FIFO count never reaches true value

cancel
Showing results for 
Search instead for 
Did you mean: 

mma8451 FIFO count never reaches true value

Jump to solution
391 Views
wingsof
Contributor II

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);

}

Labels (1)
Tags (4)
0 Kudos
1 Solution
129 Views
wingsof
Contributor II

Ok, i found the cause of this behavior. The reason was in i2c implementation through DMA controller on STM32F40x processor. The i2c reading through DMA when only one byte is read requires special processing. Without this special processing it reads not one byte, but two, this leads to 0x01 register reading (and one FIFO sample removal).

Hope this information helps someone in future

View solution in original post

0 Kudos
2 Replies
130 Views
wingsof
Contributor II

Ok, i found the cause of this behavior. The reason was in i2c implementation through DMA controller on STM32F40x processor. The i2c reading through DMA when only one byte is read requires special processing. Without this special processing it reads not one byte, but two, this leads to 0x01 register reading (and one FIFO sample removal).

Hope this information helps someone in future

View solution in original post

0 Kudos
129 Views
reyes
NXP TechSupport
NXP TechSupport

TomasVaverka Can you please take a look at this question?

0 Kudos