11-08-2021 02:52 AM
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;
}
Solved! Go to Solution.
11-08-2021 07:20 AM
Hello ysqcn,
For your description "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)", I would like to know do you want to read acceleration data or gyroscope data?
BMG160 was gyroscope sensor inside.
11-09-2021 09:54 AM
Thanks for pointing out that BMG160 is Gyro driver
Now I poll Accel/Gryo samples every 1 seconds. I can get reasonable Accel data, and the data only has slight change since my board is on my desk and never move. But the Gyro data keep change siginificantly. Check bellow : For Gyro the format is: combine value (msb, lsb)
Any reason behind it? Anything is wrong?
---Acc
-93
-14
-1065
---Gyro
-38 (0xff:0xda)
36 (0x0:0x24)
-58 (0xff:0xc6)
---Acc
-62
-15
-1057
---Gyro
-14 (0xff:0xf2)
12 (0x0:0xc)
50 (0x0:0x32)
---Acc
-69
-1
-1056
---Gyro
-52 (0xff:0xcc)
-34 (0xff:0xde)
56 (0x0:0x38)
---Acc
-61
-3
-1056
---Gyro
44 (0x0:0x2c)
30 (0x0:0x1e)
-104 (0xff:0x98)
---Acc
-63
-15
-1069
---Gyro
120 (0x0:0x78)
46 (0x0:0x2e)
50 (0x0:0x32)
---Acc
-78
-8
-1054
---Gyro
70 (0x0:0x46)
46 (0x0:0x2e)
100 (0x0:0x64)
---Acc
-74
-19
-1045
---Gyro
-84 (0xff:0xac)
14 (0x0:0xe)
54 (0x0:0x36)
---Acc
-78
-12
-1062
---Gyro
-38 (0xff:0xda)
22 (0x0:0x16)
50 (0x0:0x32)
The sample code I use to print the samples
static void print_sample(uint8_t lsb, uint8_t msb, uint32_t dev)
{
if (dev == IMU_Acc) {
uint8_t new_data = lsb & 1;
uint32_t reg_data = (uint32_t)(((uint16_t)(msb << 8U) | lsb) >> 4U);
int16_t sample;
if (reg_data > MAX_VAL_12BIT) {
sample = reg_data - NEG_VAL_12BIT;
} else {
sample = (int16_t)reg_data;
}
printf("%d\n", sample);
} else {
/* 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 */
int16_t sample = (int16_t)((((int32_t)((int8_t)msb)) * 256) | (lsb));
printf(" %d (0x%x:0x%x)\n", sample, msb, lsb);
}
}
11-10-2021 02:40 AM
Hi,
Any insights about how to interpret the Gyro data? The board is put on desk and never moved. Should the sample only have slight change?
---Gyro
-38 (0xff:0xda)
36 (0x0:0x24)
-58 (0xff:0xc6)
---Gyro
-14 (0xff:0xf2)
12 (0x0:0xc)
50 (0x0:0x32)
---Gyro
-52 (0xff:0xcc)
-34 (0xff:0xde)
56 (0x0:0x38)
---Gyro
44 (0x0:0x2c)
30 (0x0:0x1e)
-104 (0xff:0x98)
---Gyro
120 (0x0:0x78)
46 (0x0:0x2e)
50 (0x0:0x32)
---Gyro
70 (0x0:0x46)
46 (0x0:0x2e)
100 (0x0:0x64)
---Gyro
-84 (0xff:0xac)
14 (0x0:0xe)
54 (0x0:0x36)
---Gyro
-38 (0xff:0xda)
22 (0x0:0x16)
50 (0x0:0x32)
11-10-2021 04:22 AM
Hello ysqcn,
Could you send out your code, then we could see how do you configure BMI055?