Well... I must be blind, I didn't see the level shifters! I adapted the code now to a JM128 Coldfire V1 running at 5V, and now it works great!
One more question, I was reading AN4069 and I noticed that I have to change the calibration routine in order for it to work correctly with the mma8452 in 2g mode and 12 bits. But this isn't very clear to me.
/******************************************************************************
* Simple offset calibration
******************************************************************************/
void Calibrate (void)
{
unsigned char reg_val = 0;
while (!reg_val) // Wait for a first set of data
{
reg_val = I2C_ReadRegister(MMA845x_I2C_ADDRESS, STATUS_REG) & 0x08;
}
I2C_ReadMultiRegisters(MMA845x_I2C_ADDRESS, OUT_X_MSB_REG, 6, AccData); // Read data output registers 0x01-0x06
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
Xoffset = Xout_14_bit / 8 * (-1); // Compute X-axis offset correction value
Yoffset = Yout_14_bit / 8 * (-1); // Compute Y-axis offset correction value
Zoffset = (Zout_14_bit - SENSITIVITY_2G) / 8 * (-1); // Compute Z-axis offset correction value
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_REG3, 0x00); // Push-pull, active low interrupt
I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG4, 0x01); // Enable DRDY interrupt
I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG5, 0x01); // DRDY interrupt routed to INT1 - PTA14
I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG1, 0x3D); // ODR = 1.56Hz, Reduced noise, Active mode
}
I have made the following changes (marked in bold):
Xout_12_bit = ((short) (AccData[0]<<8 | AccData[1])) >> 4; // Compute 12-bit X-axis output value
Yout_12_bit = ((short) (AccData[2]<<8 | AccData[3])) >> 4; // Compute 12-bit Y-axis output value
Zout_12_bit = ((short) (AccData[4]<<8 | AccData[5])) >> 4; // Compute 12-bit Z-axis output value
Xoffset = Xout_12_bit / 2 * (-1); // Compute X-axis offset correction value
Yoffset = Yout_12_bit / 2 * (-1); // Compute Y-axis offset correction value
Zoffset = (Zout_12_bit - SENSITIVITY_2G) / 2 * (-1); // Compute Z-axis offset correction value
Can you please tell me if this changes are correct?
Thanks, and sorry for the troubles.