I am using an ADXL345 Accelerometer for a Tilt Sensing application.
The Z-Values at the 2g range seem to be locked on a single value (511 in decimal).
4g, 8g and 16g ranges work perfectly (but with lower sensitivities).
Ive followed recommendations on the datasheet and played around quite a bit with Power Modes, Data Rates, Communication Protocols, etc. but to no avail.
I see there are already several questions asked for the same problem, but no solutions were there in the answers. (they mostly tried changes in initialization, power, etc...but that isnt the problem. neither is soldering or chip damage)
Below is how i extract the value of Z Axis:
char POWER_CTL = 0x2D; //Power Control Register
char DATA_FORMAT = 0x31;
char FIFO_CTL = 0x38;
char BW_RATE = 0x2C; //tried all data rates from 100 to 1600Hz
char DATAZ0 = 0x36; //Z-Axis Data 0
char DATAZ1 = 0x37; //Z-Axis Data 1
//The ADXL345 gives 10-bit acceleration values, but they are stored as bytes (8-bits). To get the full value, two bytes must be combined for each axis.
//The X value is stored in values and values.
//The Z value is stored in values and values.
z = ((int)values<<8)|(int)values;
Serial.print(x, DEC); // is giving me 511 continuously. Other Axes work fine and in range as expected.
Would Appreciate any help.