Hi,
From BMI055 spec: The width of acceleration data is 12 bits given in two´s complement representation. The 12 bits for each axis are split into an MSB upper part (one byte containing bits 11 to 4) and an LSB lower part (one byte containing bits 3 to 0 of acceleration and a (ACC 0x02, 0x04, 0x06) new_data flag)
But in BMI055 reference driver: https://github.com/BoschSensortec/BMG160_driver
The caculation is:
*v_data_x_s16 = (s16)((((s32)((s8)v_data_u8[BMG160_X_MSB_DATA])) * 256) | (v_data_u8[BMG160_X_LSB_DATA]));
It is a bit confused. Could you help to clarify?
Thanks
-Austin
BMG160_RETURN_FUNCTION_TYPE bmg160_get_data_x(s16 *v_data_x_s16)
{
/* variable used to return the bus communication status*/
BMG160_RETURN_FUNCTION_TYPE comres = BMG160_INIT_VALUE;
/*Array holding the gyro data x LSB and MSB data
* v_data_u8[0] - X LSB
* v_data_u8[1] - X MSB
*/
u8 v_data_u8[BMG160_X_DATA_SIZE] = { BMG160_INIT_VALUE, BMG160_INIT_VALUE };
/* check the p_bmg160 struct pointer is NULL*/
if (p_bmg160 == BMG160_NULL)
{
return E_BMG160_NULL_PTR;
}
else
{
/* read the gyro x data */
comres = p_bmg160->BMG160_BUS_READ_FUNC(p_bmg160->dev_addr,
BMG160_RATE_X_LSB_BIT__REG,
v_data_u8,
BMG160_X_DATA_LENGTH);
v_data_u8[BMG160_X_LSB_DATA] = BMG160_GET_BIT_POS0(v_data_u8[BMG160_X_LSB_DATA], BMG160_RATE_X_LSB_BIT);
/* To avoid signed integer shifting, multiplication by the same factor of position shift is performed
* i.e 8 places have been shifted left which is equivalent to multiplying by 256 */
*v_data_x_s16 = (s16)((((s32)((s8)v_data_u8[BMG160_X_MSB_DATA])) * 256) | (v_data_u8[BMG160_X_LSB_DATA]));
}
return comres;
}