Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    BMI270 initialization issue with Arduino M0

    Member

    Re: BMI270 initialization issue with Arduino M0

    Hi,
    II have to reopen this thread because actually I am having a similar problem.
    I couldn't change the library in the way you mentioned to get arduino code compiled.
    Could you post/attach the part of the library you have changed?

    The message I received after compiling is same as yours:

    BMI270-Sensor-API-bmi270_v2.46.1/bmi2.h:1341:2: error: #endif without #if
    
     #endif /* BMI2_H_ */



    I am also able able to detect correct chip ID (0x24) but accelerometer output independet of axis is still zero.




    Member

    Re: BMI270 initialization issue with Arduino M0

    Hi,

    I'm also trying to get the config file loaded correctly. Copied your gist example code into arduino, but it gives me error "'struct bmi2_dev' has no member named 'dev_id'"  on line 61 and "'BMI2_I2C_INTERFACE' was not declared in this scope " on line 65. Not sure how to fix this.

    Any help appreciated. 

    Best regards.

    Community Moderator

    Re: BMI270 initialization issue with Arduino M0

    Hello, 

     

    We used dev_id in previous API, but not anymore. 

    Please test with my attached file. 

    Thanks 🙂  

    Member

    Re: BMI270 initialization issue with Arduino M0

    Hi again, thanks for the quick reply 🙂

    I forgot to write that I am trying to communicate via I2C to a Teensy 3.2 MCU. I tried changing your program to enable I2C and it doesn't give any errors, but the serial moniter isn't showing anything (not even the "bmi270_init done" in setup()). 

    There are some warnings when declaring bmi2.read and bm2.write, but I can't get rid of them. Is there a similar example for I2C?

    I've attached the program where I tried to enable I2C.

    Best regards.

     

    Community Moderator

    Re: BMI270 initialization issue with Arduino M0

    Hello paraas, 

     

    Unfortuantely, we don't have example code for Teensy 3.2 MCU. 

    However, here is the my i2c example for arduino. 

    bmi2xy_hal_i2c_bus_read and bmi2xy_hal_i2c_bus_write are put to bmi2 function pointers as below. 

    Thanks,


    bmi2.read = bmi2xy_hal_i2c_bus_read;
    bmi2.write = bmi2xy_hal_i2c_bus_write;

    /*! This API is used to perform I2C read operation with sensor */
    int8_t bmi2xy_hal_i2c_bus_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr)
    {
    int8_t rslt = 0;
    //uint8_t dev_id = 0x68;
    uint8_t* dev_id = (uint8_t *)intf_ptr;

    rslt = BMI270_read_i2c(*dev_id, reg_addr, reg_data, length);

    return rslt;
    }

    /*! This API is used to perform I2C write operations with sensor */
    int8_t bmi2xy_hal_i2c_bus_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
    {
    int8_t rslt = 0;
    // uint8_t dev_id = 0x68;

    uint8_t* dev_id = (uint8_t *)intf_ptr;
    rslt = BMI270_write_i2c(*dev_id, reg_addr, (uint8_t *)reg_data, length);

    return rslt;
    }

    int8_t BMI270_read_i2c(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t count)
    {
    /* dev_addr: I2C device address.
    reg_addr: Starting address for writing the data.
    reg_data: Data to be written.
    count: Number of bytes to write */
    // Begin I2C communication with provided I2C address
    Wire.beginTransmission(dev_addr);
    Wire.write(reg_addr);
    // Done writting, end the transmission
    int8_t returned = Wire.endTransmission();

    if (returned)
    {
    return returned;
    }

    // Requests the required number of bytes from the sensor
    Wire.requestFrom((int)dev_addr, (int)count);

    uint16_t i;
    // Reads the requested number of bytes into the provided array
    for (i = 0; (i < count) && Wire.available(); i++)
    {
    reg_data[i] = Wire.read(); // This is for the modern Wire library
    }

    // This must return 0 on success, any other value will be interpreted as a communication failure.
    return 0;
    }

    int8_t BMI270_write_i2c(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t count)
    {
    /* dev_addr: I2C device address.
    reg_addr: Starting address for reading the data.
    reg_data: Buffer to take up the read data.
    count: Number of bytes to read. */
    // Begin I2C communication with provided I2C address
    Wire.beginTransmission(dev_addr);
    Wire.write(reg_addr);

    uint16_t i;
    // Writes the requested number of bytes from the provided array
    for (i = 0; i < count; i++)
    {
    Wire.write(reg_data[i]); // This is for the modern Wire library
    }
    // Done writting, end the transmission
    int8_t returned = Wire.endTransmission();
    return returned;
    }

    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