Value of ADXL345 sensor not change

Hi.
That is my first post and I hope that you can help me.
Well, my problem is with my sensor. I can communicate with this, but the sensor value don’t change for anything.
In my last code I try to implement de self test proposed here: application_notes_AN-1077.pdf

I follow these step but my result isn’t good because I always receive the same value (with the self-test enable and disable). My code is this:

#include "Wire.h"

#define DEVICE (0x53)
byte byte1,POWER_CTL,DATA_FORMAT,INT_ENABLE,DATA_RATE;
byte buff_x[2];
byte buff_z[2];
int aux = 0;
int final = 0;
float promedio,acumulado;
void setup(){
  Wire.begin();
  #ifndef cbi
  #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
  #endif
  cbi(PORTC,5);
  cbi(PORTC,4);
  Serial.begin(9600);
  
}

void loop(){
  //************** check the communication ******************
  Wire.beginTransmission(DEVICE);
  Wire.write(0x00); // special register
  Wire.endTransmission();
  Wire.requestFrom(DEVICE,1);
  byte1 = Wire.read();
  // taste the correct data 
  if(byte1 == 0xE5){
    Serial.println("Communication is OK");
    Serial.println(byte1,HEX);
  }
  delay(2000);
  //********************************************************
  //************* initial step *****************
  // Format of transmition
  Wire.beginTransmission(DEVICE);
  Wire.write(0x31); // Format data register
  Wire.write(0x0B); 
  Wire.endTransmission();
  // Start transmition
  Wire.beginTransmission(DEVICE);
  Wire.write(0x2D); //POWER_CTL
  Wire.write(0x08); // Measure mode
  Wire.endTransmission();
  //Enable interruptions
  Wire.beginTransmission(DEVICE);
  Wire.write(0x2E); //INT_ENABLE
  Wire.write(0x80);
  Wire.endTransmission();
  //change data rate
  Wire.beginTransmission(DEVICE);
  Wire.write(0x2C); //DATA_RATE
  Wire.write(0x0D); // output rate 800Hz
  Wire.endTransmission();
 
  // *****************get configuration ****************
  Wire.beginTransmission(DEVICE);
  Wire.write(0x31); // Format data register
  Wire.endTransmission();
  Wire.requestFrom(DEVICE,1);
  DATA_FORMAT = Wire.read();
  
  Wire.beginTransmission(DEVICE);
  Wire.write(0x2D); //POWER_CTL
  Wire.endTransmission();
  Wire.requestFrom(DEVICE,1);
  POWER_CTL = Wire.read();
 
  Wire.beginTransmission(DEVICE);
  Wire.write(0x2E); //INT_ENABLE
  Wire.endTransmission();
  Wire.requestFrom(DEVICE,1);
  INT_ENABLE = Wire.read();
  
  Wire.beginTransmission(DEVICE);
  Wire.write(0x2C); //DATA_RATE
  Wire.endTransmission();
  Wire.requestFrom(DEVICE,1);
  DATA_RATE = Wire.read();
  Serial.print("Data format: ");
  Serial.println(DATA_FORMAT,HEX);
  Serial.print("Control poder: ");
  Serial.println(POWER_CTL,HEX);
  Serial.print("interrupciones: ");
  Serial.println(INT_ENABLE,HEX);
  Serial.print("Data rate: ");
  Serial.println(DATA_RATE,HEX);
  delay(2000);
  //**********************************************************
  //********************* get data *************************
  while(1){
    for(int j=1;j<=100;j++){
      // Iniciar transmisión
      Wire.beginTransmission(DEVICE);
      // Establer registro a leer
      Wire.write(0x36);
      // Enviar dato al dispositivo
      Wire.endTransmission();
      // Solicitar 2 byte al dispositivo desde el registro a leer
      Wire.requestFrom(DEVICE,2);
      // Obtener bytes recividos
      int number = Wire.available();
      int i=0;
      // Leer la información
      while(Wire.available()) // device may send less than requested (abnormal)
      {
        buff_z[i] = Wire.read(); // receive a byte
        i++;
      }
      // Finalizar la transmisión una vez leído todos los registros
      Wire.endTransmission(); // end transmission
      buff_z[1] = buff_z[1] & 0x0F;
      aux = buff_z[1];
      aux = aux << 8;
      final = aux | buff_z[0];
      acumulado = acumulado + final;
      delay(50);
    }
    promedio = acumulado/100;
    Serial.print("Mean result z: ");
    Serial.println(promedio);
    acumulado = 0;
    delay(5000);
    Wire.beginTransmission(DEVICE);
    Wire.write(0x31); // Format data register
    Wire.write(0x8B); //Enable self-test
    Wire.endTransmission();
    delay(100);
    for(int j=1;j<=100;j++){
      // Iniciar transmisión
      Wire.beginTransmission(DEVICE);
      // Establer registro a leer
      Wire.write(0x36);
      // Enviar dato al dispositivo
      Wire.endTransmission();
      // Solicitar 2 byte al dispositivo desde el registro a leer
      Wire.requestFrom(DEVICE,2);
      // Obtener bytes recividos
      int number = Wire.available();
      int i=0;
      // Leer la información
      while(Wire.available()) // device may send less than requested (abnormal)
      {
        buff_z[i] = Wire.read(); // receive a byte
        i++;
      }
      // Finalizar la transmisión una vez leído todos los registros
      Wire.endTransmission(); // end transmission
      buff_z[1] = buff_z[1] & 0x0F;
      aux = buff_z[1];
      aux = aux << 8;
      final = aux | buff_z[0];
      acumulado = acumulado + final;
    }
    promedio = acumulado/100;
    Serial.print("mean result z, self test: ");
    Serial.println(promedio);
    acumulado = 0;
    delay(5000);
    Wire.beginTransmission(DEVICE);
    Wire.write(0x31); // Format data register
    Wire.write(0x0B); //Disable self-test
    Wire.endTransmission();
    delay(100);
  }
}

I would like know if I make one mistake or if maybe my sensor is the problem.
I add 2 pictures, the first one is with the connections and the second is with the results in the serial monitor.
Thanks for your time. :smiley:
Regards.

Resultados.png

I suggest to try everything out first with code that is known to work. There are several examples, like this one.

Hi, thanks for you suggestion, but I already probe all knowing codes.
That is only one example, also I probe the code of adafruit, and this: ABC del acelerometro.
In all these case the sensor value never changed. The 3-axis send different values but always the same (for each case). For that I try to implement the self-test.
What do you think?
Regads.

The sensor could certainly be defective. Try another one?

That would be the easy way to corroborate if the sensor is defective. I buy it in Dealextreme so if I buy other sensor I have wait long time.
The last question: The code for self-test is OK?
Regards.

I've received some real junk from Dealextreme, stuff I actually threw away, but it was certainly inexpensive!

:grin: well I think that is the price for buy cheap things.
Thanks for your advice.
Regards.