Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BMI055 interrupts

    BMI055 interrupts

    Usaf
    New Poster

    Hello,

    I am writing a code to initialize the BMI055 IMU on my STM32F765. To do so I am using the HAL libraries to enable the SPI connection through DMA and the drivers provided by Bosch: bma2x2 and bmg160.

     The two sensors work perfectly when only one of the two is enabled, but together they don't work.

     

    // Init Gyro
    int32_t bmg160_sensor_init(void)
    {
        SPI_routine_gyro();
    
        com_rslt_2 = bmg160_init(&bmg160);
    
        com_rslt_2 += bmg160_set_power_mode(BMG160_MODE_NORMAL);
    
        v_bw_u8 = C_BMG160_BW_230HZ_U8X; /* set gyro bandwidth of 230Hz*/
        com_rslt_2 += bmg160_set_bw(v_bw_u8);
    
        /* This API used to read back the written value of bandwidth for gyro*/
        com_rslt_2 += bmg160_get_bw(&v_gyro_value_u8);
    
        bmg160_set_intr_output_type(BMG160_INTR1, 0);
    
        // 1. Interrupt on Data is on INT1 or INT2 on register 0x18
        com_rslt_2 += bmg160_set_intr_data(0, BMG160_ENABLE);
    
        // ENABLE INTERRUPT
        // 2. Set the interrupt mode to new-data on register 0x15
        com_rslt_2 += bmg160_set_data_enable(BMG160_ENABLE);
    
        return com_rslt_2;
    }

     

     

     

    // Init Accelerometer
    int32_t bma2x2_sensor_init(void)
    {
        SPI_routine_acc();
    
        com_rslt = bma2x2_init(&bma2x2);
    
        com_rslt += bma2x2_set_power_mode(BMA2x2_MODE_NORMAL);
    
        /* This API used to read back the written value of bandwidth*/
        com_rslt += bma2x2_get_bw(&banwid);
    
        // Set source to new-data
        com_rslt += bma2x2_set_source(5, 0x01);
    
        // Set register 0x19 to INT1 in new-data
        com_rslt += bma2x2_set_new_data(0, 0x01);
    
        // Enable interrupt for new-data
        com_rslt += bma2x2_set_intr_enable(BMA2x2_DATA_ENABLE, 0x01);
    
        return com_rslt;
    }

     

     

    The transmit and receive is similar for the accelerometer (chip select: PG10) and the gyroscope (chip select: PF4):

     

    s8 BMA2x2_SPI_bus_write(u8 dev_addr, u8 reg_addr, u8* reg_data, u8 cnt)
    {
        s32 iError = BMA2x2_INIT_VALUE;
        u8  array[SPI_BUFFER_LEN * 2];
        u8  stringpos = BMA2x2_INIT_VALUE;
    
        for (stringpos = BMA2x2_INIT_VALUE; stringpos < cnt; stringpos++)
        {
            array[stringpos * 2] = (reg_addr++) & BMA2x2_SPI_BUS_WRITE_CONTROL_BYTE;
            array[stringpos * 2 + BMA2x2_BUS_READ_WRITE_ARRAY_INDEX]
                = *(reg_data + stringpos);
        }
    
        HAL_GPIO_WritePin(GPIOG, GPIO_PIN_10, RESET);
        iError = HAL_SPI_Transmit_DMA(&hspi1, array, cnt * 2);
        while (HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY)
            ;
        HAL_GPIO_WritePin(GPIOG, GPIO_PIN_10, SET);
        return (s8) iError;
    }
    //--------------------------------------------------------------
    s8 BMA2x2_SPI_bus_read(u8 dev_addr, u8 reg_addr, u8* reg_data, u8 cnt)
    {
        s32 iError                = BMA2x2_INIT_VALUE;
        u8  array[SPI_BUFFER_LEN] = { 0xFF };
        u8  stringpos;
        /*	For the SPI mode only 7 bits of register addresses are used.
        The MSB of register address is declared the bit what functionality it is
        read/write (read as 1/write as 0)*/
        array[BMA2x2_INIT_VALUE] = reg_addr | BMA2x2_SPI_BUS_READ_CONTROL_BYTE;
    
        HAL_GPIO_WritePin(GPIOG, GPIO_PIN_10, RESET);
        iError = HAL_SPI_Receive_DMA(&hspi1, array, cnt + 1);
        while (HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY)
            ;
        HAL_GPIO_WritePin(GPIOG, GPIO_PIN_10, SET);
    
        for (stringpos = BMA2x2_INIT_VALUE; stringpos < cnt; stringpos++)
        {
            *(reg_data + stringpos)
                = array[stringpos + BMA2x2_BUS_READ_WRITE_ARRAY_INDEX];
        }
        return (s8) iError;
    }

     

     

    For brevity, I'm not writing here also the gpio initialization, the spi etc. However, when only one sensor is enabled, everything works. When together, problems start at the initialization level: I can't read back for example a proper bandwidth for one of the two sensors.

    I'm not sure if the problem is at the sensor level (so the way I am initializing the peripherals) or at the microcontroller level (maybe some errors in the spi initialization, etc).

    I hope someone can help to find the problem.

    NOTE: The code posted shows this series of events:

    1. initialize bmg160
    2. enable new data interrupt for bmg160
    3. initialize bma2x2
    4. enable new data interrupt for bma2x2

    But I've also tried:

    1. initialize bmg160
    2. initialize bma2x2
    3. enable new data interrupt for bmg160
    4. enable new data interrupt for bma2x2

    but nothing changed.

    Thanks in advance.

    9 REPLIES 9

    FAE_CA1
    Community Moderator
    Community Moderator

    Hi,

    After power on by default BMI055 accel will be working in normal mode with +/-2g full scale range and 2000Hz ODR (output data rate) and BMI055 gyro will be working in normal mode with +/-2000dps full scale range and 2000Hz ODR.

    In order to see accel DRDY interrupt on INT1 pin and gyro DRDY interrupt on INT3 pin, you can use SPI registers write directly without API. For example, you can do the following:

    // accel DRDY on INT1 pin

    Write value of 0x01 to register 0x1A;  // map DRDY to INT1 pin

    Write value of 0x10 to register 0x17;  // enable DRDY inerrupt

    // gyro DRDY on INT3 pin

    Write value of 0x05 to register 0x16;  // set INT3 pin to push-pull and active high

    Write value of 0x01 to register 0x18;  // map DRDY to INT3 pin

    Write value of 0x80 to register 0x15;  // enable DRDY inerrupt

    Please check if you can see these DRDY signals or not.

    Thanks.

    DRDY signal for the accelerometer works well but the gyro still does not work when initialized with the accelerometer.

    FAE_CA1
    Community Moderator
    Community Moderator

    Hi,

    Inside BMI055 the accel and gyro are independent to each other which means that they work on themselves and don't talk to each other. I tried the above registers' writing (2 writes for accel and 3 writes for gyro) and I can see both DRDY signals as shown below on the BMI055 shuttle board at https://www.bosch-sensortec.com/media/boschsensortec/downloads/shuttle_board_flyer/bst-dhw-fl020.pdf pin-21 (acc DRDY) and pin-22 (gyro DRDY) respectively.

    FAE_CA1_0-1619107124504.png

    Please use your logic analyzer to monitor SPI transactions to see if you have successfully written to the registers by reading values back from those registers after writing.

    Thanks.

    Accelerometer, INT1

    accelerometer.jpeg

    INT1 works very well while gyroscope INT3 is completely inconsistent. Sometimes it works (wave same as the INT1), but most of the time there is only noise on the pin.

    FAE_CA1
    Community Moderator
    Community Moderator

    Hi,

    This is strange. Are you testing BMI055 on your own PCB? If yes, then I would like to suggest that you test BMI055 shuttle board using your MCU.

    BMI055 shuttle board schematics is available online at https://www.bosch-sensortec.com/media/boschsensortec/downloads/shuttle_board_flyer/bst-dhw-fl020.pdf. Pin-21 is INT1A for accel DRDY and pin-22 INT1G for gyro DRDY. You can connect VDD&VDDIO, GND, SPI bus from your MCU to BMI055 shuttle board and ignore those CODxxx pins because these pins are used for shuttle ID for the application base board to recognize each shuttle board.

    Please send me a private message with your shipping address. I will then ship one BMI055 shuttle board to you for your testing.

    Thanks.

    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