Bosch Sensortec Community

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

    BMI088 accel data sync

    BMI088 accel data sync

    jorgazam
    Established Member

    Hello.

    I've followed the data synchronization guide from GitHub and I've used the example as a reference to work with this sensor.

    I've configured the interrupts as indicated in the example, with the difference that I'm working with the STM32, so I'm not using the COINES library.

    while (1)
    {
    previous_time = sensor_time * BMI08X_SENSORTIME_RESOLUTION;

    rslt = bmi08a_get_synchronized_data(&bmi08x_accel, &bmi08x_gyro, &bmi08xdev);

    rslt = bmi08a_get_sensor_time(&bmi08xdev, &sensor_time);
    elapsed_time = sensor_time * BMI08X_SENSORTIME_RESOLUTION;
    duration = (elapsed_time - previous_time) * 1000;
    }

    The problem I have is that when I run the function to obtain the data from the sensors, the accelerometer is always reading the same data. The gyroscope appears to work correctly. When I read the data separately, I mean without using synchronization, I have no problem reading the data of both sensors.

    /* Read accel x,y sensor data */
    reg_addr = BMI08X_REG_ACCEL_GP_0;
    rslt = bmi08a_get_regs(reg_addr, &data[0], 4, dev);

    ...

    /* Read accel sensor data */
    reg_addr = BMI08X_REG_ACCEL_GP_4;
    rslt = bmi08a_get_regs(reg_addr, &data[4], 2, dev);

    I've noticed that the bmi08a_get_synchronized_data function reads different registers than the bmi08a_get_data function does. It does the reading of two general purpose registers, so I see first of length 4 and then of length 2. I assume to read x and y first, and then z. The problem here is that I've observed that even though it's performing the SPI reading correctly, it always reads the same values in the data array.

    /* Read accel sensor data */
    rslt = bmi08a_get_regs(BMI08X_REG_ACCEL_X_LSB, data, 6, dev);

    So, I tried to modify the bmi08a_get_synchronized_data function in order to make the SPI reading in the same register as the bmi08a_get_data function, as shown above. This way, it's reading the accelerometer data correctly. The problem with doing something like this is that I'm not supposed to modify the library, so I don't know if that means there is no longer synchronization in reading the data from both sensors, since it's reading it in a different register.

    I attach the file with the initialization functions. I've followed the examples, so it shouldn't make any difference how I did it.

    4 REPLIES 4

    BSTRobin
    Community Moderator
    Community Moderator

    Hi jorgazam,

    For read_synchronized_data_mcu example, there was example code on STM32 attached for your reference.

    jorgazam
    Established Member

    I've tried to follow the example attatched in your reply. As you can see in the gifs the problem persists, I get the same data all the time in the accelerometer. It makes the register reading, but it seems that it's always the same exact data.

    I'll attach the project, the main files are the common and the main, where I've done the same as in the example. I definitely don't understand where the problem is, because I've tried different boards and the same problem occurs on all of them.

    BSTRobin
    Community Moderator
    Community Moderator

    Hi jorgazam,

    You could modify SPI clock frequency and test it again.

    If your CPU frequency was set to 64 MHz, then the following SPI clock frequency will be too high.
    hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;

    SPI clock frequency should be configured bellow 10 MHz.

    jorgazam
    Established Member

    Hello,

    Thanks for answering, it's useful to know what you have said, but this is not the case, since if you check the project that I attached in the previous answer, the clock is set to 4 MHz.

    The solution I used to obtain the simultaneous reading has been to create my own function that combines the reading functions of the accelerometer and gyroscope from the Bosch library, in addition to the sensor time. This seems to work the way I wanted, so I'll end this post. Thanks for the answers.

    Edit: I'm going to add the function, it has nothing new, it's just a combination of those from the library.

    BMI08X_INTF_RET_TYPE bmi08x_get_data(struct bmi08x_sensor_data *accel, struct bmi08x_sensor_data *gyro, uint32_t *sensor_time, struct bmi08x_dev *dev)
    {
    int8_t rslt;
    uint8_t data[9] = { 0 };

    uint8_t lsb, msb;
    uint16_t msblsb;
    uint32_t byte2, byte1, byte0;

    /* Proceed if null check is fine */
    if ((accel != NULL) && (sensor_time != NULL))
    {
    /* Read accel sensor data & sensor time */
    rslt = bmi08a_get_regs(BMI08X_REG_ACCEL_X_LSB, data, 9, dev);

    if (rslt == BMI08X_OK)
    {
    lsb = data[0];
    msb = data[1];
    msblsb = (msb << 8 ) | lsb;
    accel->x = ((int16_t) msblsb); /* Data in X axis */

    lsb = data[2];
    msb = data[3];
    msblsb = (msb << 8 ) | lsb;
    accel->y = ((int16_t) msblsb); /* Data in Y axis */

    lsb = data[4];
    msb = data[5];
    msblsb = (msb << 8 ) | lsb;
    accel->z = ((int16_t) msblsb); /* Data in Z axis */

    byte0 = data[6]; /* Lower byte */
    byte1 = (data[7] << 8); /* Middle byte */
    byte2 = (data[8] << 16); /* Higher byte */

    /* Sensor time */
    *sensor_time = (byte2 | byte1 | byte0);

    /* Read gyro sensor data */
    rslt = bmi08g_get_data(gyro, dev);
    }
    }
    else
    {
    rslt = BMI08X_E_NULL_PTR;
    }

    return rslt;
    }

    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