Yes, I was just following your metal bare example but I still have some problem.
Firstly: I'm in 14 bit, ODR 800, 8g mode.
Here:
Xout_14_bit = ((short) (AccData[0]<<8 | AccData[1])) >> 2; // Compute 14-bit X-axis output value
Yout_14_bit = ((short) (AccData[2]<<8 | AccData[3])) >> 2; // Compute 14-bit Y-axis output value
Zout_14_bit = ((short) (AccData[4]<<8 | AccData[5])) >> 2; // Compute 14-bit Z-axis output value
What are you doing with this shifting?
Is this equivalent to a 2's complement for XYZ no?
And are they approximated as integers no? ("short" operator)
Now I've calculated the Offset like this:
Xoffset = Xout_14_bit / 2 * (-1); // Compute X-axis offset correction value
Yoffset = Yout_14_bit / 2 * (-1); // Compute Y-axis offset correction value
Zoffset = (Zout_14_bit - 1024) / 2 * (-1); // Compute Z-axis offset correction value with 8g sensitivity
It looks correct to me..
After that I convert them as hexadecimal (ok?) and I put them into the Offset registers:
I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG1, 0x00); // Standby mode to allow writing to the offset registers
I2C_WriteRegister(MMA845x_I2C_ADDRESS, OFF_X_REG, Xoffset);
I2C_WriteRegister(MMA845x_I2C_ADDRESS, OFF_Y_REG, Yoffset);
I2C_WriteRegister(MMA845x_I2C_ADDRESS, OFF_Z_REG, Zoffset);
I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG1, 0x01); // Active mode
And it doesn't work properly anyway :/
The y and z acceleration doesn't change enough, and X acceleration doesn't change at all.
NB my stationary target is:
X=0g
Y=0g
Z=1g
Obvious my device is properly oriented.
I'm sorry if I'm annoying you too much, I'm a bit noob.
Thank you and merry Christmas.