BMI055 interrupts

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