AnsweredAssumed Answered

I don't seem to be getting interrupt with AXL345.

Question asked by Mechif on Mar 19, 2013
Latest reply on Apr 4, 2013 by Mechif

Hello,

I have an application that is supposed to detect sudden jerks. Smooth movement should be ignored.

Below is my setup - though if anyone has a better suggestion, I'm open to hear. I decided not to use Freefall or Tap but just to check extreme values in the X,Y,Z axes. Any high value in any one of the axes should trigger an interrupt.

 

//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] = 0xFF; //XL345_DATAREADY | XL345_ACTIVITY;  // 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);

 

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

          __delay_cycles(50);

}

 

There are somethings that I don't understand - but they work - so I don't argue.

  • I added at the beginning of xl345Write() and xl345Read() a __delay_cycles(50) - but still I need additional delays in the above initialization code.
  • Also, why do I have to call the last command twice (writing the XL345_POWER_CTL)?

 

I enabled all interrupts, but I don't seem to be getting any.

There may be a HW problem - though I can read the accelerometer values at a rate of 100Hz - and they are logical (according to the motion of the board).

What am i missing/ Why am I not getting interrupts?

Thanks for any help.

Mechi

Outcomes