Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BMI270 init with I2C

    BMI270 init with I2C

    Eason
    Member

    Hallo

    I try to use this programm.When I use SPI, BMI runs normally.But in the process of using IIC, there was a problem. In the setup program, the value of rslt is not equal to the BMI_OK value.This means this connection was not successful.

     

     

    09:58:59.151 rslt-> -2 
    09:58:59.151 BMI_OK-> 0

     

     

    This is my setup program, what went wrong. Thank you very much

     

     

    void setup() {
    
    
      /* Variable to define result */
      int8_t rslt;
      pinMode(BMI270_CS, OUTPUT);
      pinMode(interruptPin, INPUT_PULLUP);
      digitalWrite(BMI270_CS, HIGH);
      //  Wire.setModule(0);
      Serial.begin(115200);
    
      i2c_bus = 0x68;
     // spi_bus = BMI270_CS;
      /* To initialize the hal function */
    
      //SPI.begin();
      Wire.begin();
      bmi2.intf_ptr = &i2c_bus;
      bmi2.intf = BMI2_I2C_INTF;
      bmi2.read = bmi2xy_hal_i2c_bus_read;
      bmi2.write = bmi2xy_hal_i2c_bus_write;
      bmi2.read_write_len = 32;
      bmi2.delay_us = bmi2xy_hal_delay_usec;
    
      /* Config file pointer should be assigned to NULL, so that default file address is assigned in bmi270_init */
      bmi2.config_file_ptr = NULL;
    
      /* Initialize bmi270 */
      rslt = bmi270_init(&bmi2);
    
      Serial.println("bmi270_init done");
    
      rslt = bmi2_accel_gyro_set_config(&bmi2);
      Serial.println(rslt);
      Serial.println(BMI2_OK);
      if (rslt == BMI2_OK)
      {
        Serial.println("Accel data Ready : X Y Z ");
        Serial.println("Gyro data Ready : X Y Z ");
      }
      
      delay(250);
      // Interrupt PINs configuration
      struct bmi2_int_pin_config data_int_cfg;
      data_int_cfg.pin_type = BMI2_INT1;
      data_int_cfg.int_latch = BMI2_INT_NON_LATCH;
      data_int_cfg.pin_cfg[0].output_en = BMI2_INT_OUTPUT_ENABLE; // Output enabled
      data_int_cfg.pin_cfg[0].od = BMI2_INT_PUSH_PULL;      // OpenDrain disabled
      data_int_cfg.pin_cfg[0].lvl = BMI2_INT_ACTIVE_LOW;      // Signal Low Active
      data_int_cfg.pin_cfg[0].input_en = BMI2_INT_INPUT_DISABLE;  // Input Disabled
    
      rslt =  bmi2_set_int_pin_config( &data_int_cfg, &bmi2);
    
      pinMode(interruptPin, INPUT);
      attachInterrupt(digitalPinToInterrupt(interruptPin), RawDataHandler, FALLING);
    
    }

     

    5 REPLIES 5

    Minhwan
    Community Moderator
    Community Moderator

    Hello Eason, 

     

    Please try with this example code. 

    I tested with Arduino Due. 

    Thanks, 

     

    Minhwan Oh

    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