Bosch Sensortec Community

    Showing results for 
    Search instead for 
    Did you mean: 

    BMI270 initialization issue with bmi2

    BMI270 initialization issue with bmi2



    I used the official program to initialize BMI270, but there was an error in the initialization program


    BMI270_Arduino_example_1:44:10: error: 'struct bmi2_dev' has no member named 'dev_id'
         bmi2.dev_id = BMI270_CS;




    #include <SPI.h>
    #include <bmi2.h>
    #include <bmi270.h>
    #include <bmi270_context.h>
    #include <bmi2_defs.h>
    #include <bmi2_ois.h>
    #include <Arduino.h>
    #define BMI270_CS   SS
    #define BMI270_INT1 6
    /* Callback function prototypes for the BMI270 Sensor API */
    int8_t bmi2_spi_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_t len);
    int8_t bmi2_spi_write(uint8_t dev_id, uint8_t reg_addr, const uint8_t *data, uint16_t len);
    void bmi2_delay_us(uint32_t period);
    /* Static variables */
    static struct bmi2_dev bmi2;
    static volatile bool bmi2_intr_recvd = false;
    static volatile uint32_t last_time_us = 0;
    void setup(void)
      int8_t rslt;
      while (!Serial.available()); // Wait for an input to proceed
      pinMode(LED_BUILTIN, OUTPUT);
      /* Use either the SPI or I2C configuration */
      //  /* Start of SPI configuration */
        pinMode(BMI270_CS, OUTPUT);
        digitalWrite(BMI270_CS, LOW);
        digitalWrite(BMI270_CS, HIGH); // Toggle the chip select to switch into SPI mode
        bmi2.dev_id = BMI270_CS; = bmi2_spi_read;
        bmi2.write = bmi2_spi_write;
        bmi2.delay_us = bmi2_delay_us;
        bmi2.intf = BMI2_SPI_INTERFACE;
        bmi2.read_write_len = 8192;
        bmi2.config_file_ptr = NULL; // Use the default BMI270 config file
        /* End of SPI configuration */
      rslt = bmi270_init(&bmi2);
      attachInterrupt(BMI270_INT1, bmi2_intr1_callback, RISING);
      //rslt = configure_sensor(&bmi2);




    8 REPLIES 8

    Community Moderator
    Community Moderator

    Hello Eason,


    Which example code did you refer? In struct bmi2_dev, it has no dev_id member:


    /*! Structure to define BMI2 sensor configurations */
    struct bmi2_dev
    /*! Chip id of BMI2 */
    uint8_t chip_id;

    /*! The interface pointer is used to enable the user
    * to link their interface descriptors for reference during the
    * implementation of the read and write interfaces to the
    * hardware.
    void *intf_ptr;

    /*! To store warnings */
    uint8_t info;

    /*! Type of Interface */
    enum bmi2_intf intf;

    /*! To store interface pointer error */
    BMI2_INTF_RETURN_TYPE intf_rslt;

    /*! For switching from I2C to SPI */
    uint8_t dummy_byte;

    /*! Resolution for FOC */
    uint8_t resolution;

    /*! User set read/write length */
    uint16_t read_write_len;

    /*! Pointer to the configuration data buffer address */
    const uint8_t *config_file_ptr;

    /*! To define maximum page number */
    uint8_t page_max;

    /*! To define maximum number of input sensors/features */
    uint8_t input_sens;

    /*! To define maximum number of output sensors/features */
    uint8_t out_sens;

    /*! Indicate manual enable for auxiliary communication */
    uint8_t aux_man_en;

    /*! Defines manual read burst length for auxiliary communication */
    uint8_t aux_man_rd_burst_len;

    /*! Array of feature input configuration structure */
    const struct bmi2_feature_config *feat_config;

    /*! Array of feature output configuration structure */
    const struct bmi2_feature_config *feat_output;

    /*! Structure to maintain a copy of feature out_conf values */
    struct bmi2_int_map int_map;

    /*! Structure to maintain a copy of the re-mapped axis */
    struct bmi2_axes_remap remap;

    /*! Flag to hold enable status of sensors */
    uint64_t sens_en_stat;

    /*! Read function pointer */
    bmi2_read_fptr_t read;

    /*! Write function pointer */
    bmi2_write_fptr_t write;

    /*! Delay function pointer */
    bmi2_delay_fptr_t delay_us;

    /*! To store the gyroscope cross sensitivity value */
    int16_t gyr_cross_sens_zx;

    /* gyro enable status, used as a flag in CRT enabling and aborting */
    uint8_t gyro_en : 1;

    /* advance power saving mode status, used as a flag in CRT enabling and aborting */
    uint8_t aps_status;

    /* used as a flag to enable variant specific features like crt */
    uint16_t variant_feature;

    /* To store hold the size of config file */
    uint16_t config_size;

    /*! Function pointer to get wakeup configurations */
    bmi2_wake_up_fptr_t get_wakeup_config;

    /*! Function pointer to set wakeup configurations */
    bmi2_wake_up_fptr_t set_wakeup_config;


    I use BMI270_Arduino_example.ino from  with Ardduino Meaga 2560 . Besides this, there is an error saying that the global variables are taking up 115% of dynamic memory.

    Community Moderator
    Community Moderator

    Hello Eason, 


    Some our arduino code is old fashioned, so I migrated our new API into Arduino DUE. 

    Please let me know if you have further questions. 

    Thanks 🙂 

    Community Moderator
    Community Moderator

    Hello Eason,

    In your application code, the value 8192 for read_write_len was too high.This value needed to be set according maximum length of MCU SPI HW.

    I used value 32 for read_write_len on STM32.

     bmi2.read_write_len = 8192;