Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BMI270 initialization issue with bmi2

    BMI270 initialization issue with bmi2

    Eason
    Member

    Hi

    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;
      Serial.begin(115200);
      while (!Serial.available()); // Wait for an input to proceed
      pinMode(LED_BUILTIN, OUTPUT);
    
      /* Use either the SPI or I2C configuration */
    
      //  /* Start of SPI configuration */
        SPI.begin();
        pinMode(BMI270_CS, OUTPUT);
        digitalWrite(BMI270_CS, LOW);
        delay(1);
        digitalWrite(BMI270_CS, HIGH); // Toggle the chip select to switch into SPI mode
        delay(10);
        
        bmi2.dev_id = BMI270_CS;
        bmi2.read = 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);
      print_rslt(rslt);
    
      attachInterrupt(BMI270_INT1, bmi2_intr1_callback, RISING);
    
      //rslt = configure_sensor(&bmi2);
      //print_rslt(rslt);
    }

     

     

     

    8 REPLIES 8

    BSTRobin
    Community Moderator
    Community Moderator

    Hello Eason,

     

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

    bmi2_defs.h

    /*! 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;
    };

    Eason
    Member

    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.

    Minhwan
    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 🙂 

    BSTRobin
    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;

     

    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