AnsweredAssumed Answered

Reading out 32 FIFO X,Y,Z values - are they all current?

Question asked by Mechif on Mar 20, 2013
Latest reply on Mar 20, 2013 by neilzhao

Hello,

If I read the Accelerometer FIFO values 10-100 times a second, I want to read out all of the 32 FIFO values and check them.

How do I know when I've reached the most current value and the rest are garbage?

Is there a way to zero-out the FIFO values so I can ensure that on the next read I'm getting new ones?

Thanks,

Mechi

 

Here's my init code:

//ADXL345 Initialization, Register Configuration

void ADXL345_Initiate()

{

          buf[0] = XL345_RATE_100;                                                            //Output Data Rate: 100Hz

          xl345Write(1, XL345_BW_RATE, buf);

 

          buf[0] = XL345_FULL_RESOLUTION | XL345_RANGE_16G;//Data Format: +/-16g range, right justified,  256->1g

          xl345Write(1, XL345_DATA_FORMAT, (unsigned char *)buf);

 

          buf[0] = XL345_FIFO_MODE_STREAM | 5;

          xl345Write(1, XL345_FIFO_CTL, (unsigned char *)buf);

 

          buf[0] = 0xFD; // x offset -4

          xl345Write(1, XL345_OFSX, (unsigned char *)buf);

 

          //Delay between each transaction

          __delay_cycles(50);

 

          buf[0] = 0xFF; // y offset 0

          xl345Write(1, XL345_OFSY, (unsigned char *)buf);

          xl345Read(1, XL345_OFSY , buf);  // offset Y

 

          //Delay between each transaction

          __delay_cycles(50);

          buf[0] = 0x3E; // z offset 64//

          xl345Write(1, XL345_OFSZ, (unsigned char *)buf);

 

          //Delay between each transaction

          __delay_cycles(50);

          buf[0] = 0;                                        // disable TAP mode

          xl345Write(1, XL345_DUR, (unsigned char *)buf);

 

          buf[0] = 0;                                        // disable TAP mode

          xl345Write(1, XL345_LATENT, (unsigned char *)buf);

 

          buf[0] = 5;                                        // set THRESH for activity

          xl345Write(1, XL345_THRESH_ACT, (unsigned char *)buf);

 

          buf[0] = 0;  //all interrupts on PIN1 (P2.4)

          xl345Write(1, XL345_INT_MAP, (unsigned char *)buf);

 

          buf[0] = XL345_DATAREADY | XL345_ACTIVITY;  // 0xFF; //clear other interrupts - just DATA of X, Y, Z

          xl345Write(1, XL345_INT_ENABLE, (unsigned char *)buf);

 

          buf[0] = XL345_MEASURE;                                        //Power CTL: Measure mode

          xl345Write(1, XL345_POWER_CTL, (unsigned char *)buf);

 

          xl345Read(1, XL345_POWER_CTL , buf);  // XL345_POWER_CTL

 

          // send this msg AGAIN to start

          buf[0] = XL345_MEASURE;                                        //Power CTL: Measure mode

          xl345Write(1, XL345_POWER_CTL, (unsigned char *)buf);

 

          // clear any pending interrupts

          xl345Read(1, XL345_INT_SOURCE , buf);  // XL345_POWER_CTL

 

          //xl345Read(1, XL345_POWER_CTL , buf);  // XL345_POWER_CTL

          __delay_cycles(50);

}

Outcomes