Accelerometer data inverted

Hello everyone! I am using the LSM303DLH with Odroid c4. Below the measurement I have. In this case the Z-axis is pointing in sky but I have positive acceleration value (In general I get inverted accelerometer data in every axis).

Acceleration in X-Axis: -48
Acceleration in Y-Axis: 88
Acceleration in Z-Axis: 1089
Magnetic field in X-Axis: 164
Magnetic field in Y-Axis: 271
Magnetic field in Z-Axis: -388

Here is how I read the incoming byte:

        // Read xAccl lsb data from register(0x28)
        char reg[1] = {OUT_X_L_A};
        write(file, reg, 1);
        char data[1] = {0};
        if(read(file, data, 1) != 1)
                printf("Erorr : Input/output Erorr \n");
        char data_0 = data[0]; 

        // Read xAccl msb data from register(0x29)
        reg[0] = OUT_X_H_A;
        write(file, reg, 1);
        read(file, data, 1);
        char data_1 = data[0];

and than:

accelValue[X] = (int16_t) (data_1 << 8) + data_0 >> 4;

There is something wrong in how I read the byte?


Are you sure your acceleration readings are inverted? The sensor will detect gravity as an upward acceleration (away from the ground), so if you have the board oriented with the components facing up, you should expect the acceleration to be in the positive Z direction.