Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    BMI055 reference driver for acceleration data

    BMI055 reference driver for acceleration data

    ysqcn
    Established Member

    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;
    }

     

    7 REPLIES 7

    BSTRobin
    Community Moderator
    Community Moderator

    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.

    ysqcn
    Established Member

    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);
        }
    }

     

    ysqcn
    Established Member

    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)

     

    BSTRobin
    Community Moderator
    Community Moderator

    Hello ysqcn,

    Could you send out your code, then we could see how do you configure BMI055?

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist