LSM303C gives zero acceleration for z-axis when at rest
Hi,
I am trying to read Z-axis acceleration from LSM303C at rest. The device returns 0x41 for who am I register (same as datasheet). But it gives zero values for z-axis acceleration at rest. Attached is my code. Please let me know if there is an issue with the code and why it is not giving 1g for z-axis at rest. Thanks.
U8 temp_char, imuaxl, imuaxh, imuayl, imuayh, imuazl, imuazh;
U8 array_whoami[1] = {0x0F};
U8 array_control1[1] = {0x20};
U8 array_control1_value[1] = {0x9F};
U8 array_control4[1] = {0x23};
U8 array_control4_value[1] = {0x30};
SMB_DATA_OUT = array_whoami;
TARGET = 0x3A; // Target the Slave for next
SMB_Write();
SMB_Read();
SMB_DATA_OUT = array_control1_value;
TARGET = 0x3A; // Target the Slave for next
Byte_Write(0x20,0x9F);
Byte_Read(0x20);
SMB_DATA_OUT = array_control4_value;
TARGET = 0x3A; // Target the Slave for next
Byte_Write(0x23,0x30);
Byte_Read(0x23);
Byte_Read(0x2C);
imuazl = SMB0DAT;
Byte_Read(0x2D);
imuazh = SMB0DAT;
accZdata = (imuazh << 8) | imuazl;
accZdata_result = accZdata >> 4;
negative = (accZdata_result & (1 << 15)) != 0;
if (negative)
nativeInt = accZdata_result | ~((1 << 16) - 1);
else
nativeInt = accZdata_result;
