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,

    Thanks for your inquiry.

    You only enabled DRDY interrupt for BMI055 accel and gyro. But you did not map these two DRDY interrupt signals to INT pins such as INT1 and INT3. After you do this, you should be able to see the interrupt signal on those two INT pins.

    Thanks.

    Thank you very much for the reply.

    I thought that these two functions should map the PINs to INT1 and INT3:

     

        // Set register 0x19 to INT1 in new-data
        com_rslt += bma2x2_set_new_data(0, 0x01);
        // 1. Interrupt on Data is on INT3 or INT4 on register 0x18
        com_rslt_2 += bmg160_set_intr_data(0, BMG160_ENABLE);

     

     

    /*!
     *  @brief This API is used to set
     *  the data interrupt1 and interrupt2(int1_data and int2_data)
     *  in the register 0x18
     *  @note INT1 -> bit 0
     *  @note INT2 -> bit 7
     *
     *  @param  v_axis_u8: data interrupt selection
     *    v_axis_u8 | Data interrupt
     *  ------------|--------------
     *      0       |   BMG160_INTR1_DATA
     *      1       |   BMG160_INTR2_DATA
     *
     *  @param  v_intr_data_u8: The value of data interrupt1 or interrupt2
     *   value    |  Description
     * -----------|---------------
     *    1       |  BMG160_ENABLE
     *    0       |  BMG160_DISABLE
     *
     *  @return results of bus communication function
     *  @retval 0 -> Success
     *  @retval -1 -> ERROR2
     *
     *
     */
    BMG160_RETURN_FUNCTION_TYPE bmg160_set_intr_data(u8 v_axis_u8, u8 v_intr_data_u8)

     

     

    /*!
     * @brief This API is used to set
     * the interrupt status of new data in the register 0x19
     * @note INTR1_data -> register 0x19 bit 0
     * @note INTR2_data -> register 0x19 bit 7
     *
     *
     *
     *  @param channel_u8: The value of new data interrupt select
     *        channel_u8     |   result
     *       ----------------- | ------------------
     *              0          | BMA2x2_ACCEL_INTR1_NEWDATA
     *              1          | BMA2x2_ACCEL_INTR2_NEWDATA
     *
     *	@param intr_newdata_u8: The new data interrupt enable value
     *       intr_newdata_u8          |    result
     *       ------------------------ | ------------------
     *              0x00              | INTR_DISABLE
     *              0x01              | INTR_ENABLE
     *
     *
     *	@return results of bus communication function
     *	@retval 0 -> Success
     *	@retval -1 -> Error
     *
     *
     */
    BMA2x2_RETURN_FUNCTION_TYPE bma2x2_set_new_data(u8 channel_u8,
                                                    u8 intr_newdata_u8)

     

    If I'm wrong, can you please provide me a tip on how to do it correctly?

    Thank you very much again.

    FAE_CA1
    Community Moderator
    Community Moderator

    Hi,

    To map BMI055 accel DRDY interrupt to INT1 pin you need to write valus of 0x01 to register 0x1A, not 0x19.

    To map BMI055 gyro DRDY to INT3 pin, it is correct to write value of 0x01 to register 0x18. But the interrupt should be set to push-pull and active-high meaning that you need to write value of 0x05 to register 0x16.

    Thanks.

    I changed the initialization as you suggested but the problem still remains. In particular, after the initialization of the two sensors, the gyroscope interrupt seems not to work anymore. The same setup, without the accelerometer, works well.

    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