problem with value of output adxl345 connect i2c for arduino

i am beginner
I connect adxl345 to Arduino Uno via I2C.the . if fixed the adxl345 in board and i want the value of axis z=1g and x=0 y=0.the ouput in z give me 511 so i used the normalization method in z give me 20.4
in logique the ouput in z you should be 1g
I2C mode:
CS ->3V3
SDA ->A4
SCL -> A5
VCC ->3V3

//float gravityFactor=9,81;
// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#include "Wire.h"

// I2Cdev and ADXL345 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include "I2Cdev.h"
#include "ADXL345.h"

// class default I2C address is 0x53
// specific I2C addresses may be passed as a parameter here
// ALT low = 0x53 (default for SparkFun 6DOF board)
// ALT high = 0x1D
ADXL345 accel;
int i=0;
int16_t ax, ay, az;
double nx,ny,nz;

void setup() {
// join I2C bus (I2Cdev library doesn't do this automatically)
// initialize serial communication
// (38400 chosen because it works as well at 8MHz as it does at 16MHz, but
// it's really up to you depending on your project)

// initialize device
Serial.println("Initializing I2C devices...");

// accel.setTapDetectionXYZ(1);
// verify connection
Serial.println("Testing device connections...");
Serial.println(accel.testConnection() ? "ADXL345 connection successful" : "ADXL345 connection failed");


void loop() {
// read raw accel measurements from device
accel.getAcceleration(&ax, &ay, &az);

nx = ax * 0.004 * 9.8;
ny = ay * 0.004 * 9.8;
nz = az * 0.004 * 9.8;

// display tab-separated accel x/y/z values
Serial.print(" accel:\t");
Serial.print(nx); Serial.print("\t");
Serial.print(ny); Serial.print("\t");


any help to get x=0 y=0 and z=1g ?

any help to get x=0 y=0 and z=1g ?

One way (probably not the best):

    nx = 0; // ax * 0.004 * 9.8;
    ny = 0; // ay * 0.004 * 9.8;
    nz = 1; // az * 0.004 * 9.8;

Now, what numbers are you getting? Where did this formula come from?

thnx pauls but I don't understand

I don't understand

In my code snippet, I simply hardcoded the results you wanted.

That, obviously is not the right answer.

So, we need to understand why you are getting other answers.

Is there a way to normalization ?