Bosch Sensortec Community

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

    Problem reading BMI270 Accelerometer data

    Problem reading BMI270 Accelerometer data

    Menedee
    Member

    Hi,
    actually I want to read data from BMI270 of accelerometer with Arduino Nano.
    First of all I tried reading data by using this .ino file from github and the corresponding libraries.
    Unfortunately there is an error occurring while compiling which I am not getting solved.

     

    bmi2.h:1341:2: error: #endif without #if
    
    #endif /* BMI2_H_ */

     

    So I decided to try using just wire.h library.
    The I2C device is getting recocnised, when asking for ID I receive 0x24 which is correct too.


    I followed the instructions for normal power mode on page 23 of datasheet.
    I read the register values and they are written correct but the accelerometer values are still zero.
    This is the code I use for reading the LSB of the arduino:

     

    #include <Wire.h> //I2C Arduino Library
    
    #define address 0x69 //I2C 7bit address
    
    int response;
    
    void setup(){
    //Initialize Serial and I2C communications
    Serial.begin(9600);
    Wire.begin();
    delay(100);
    Wire.setClock(400000UL);
    
    // setting IMU270 in normal mode
    Wire.beginTransmission(address);
    Wire.write(0x7D); //PWR_Control Register
    Wire.write(0x0E); // enable acquistion of acc,gyro and temp
    Wire.endTransmission();
    
    Wire.beginTransmission(address);
    Wire.write(0x40); // Acc config
    Wire.write(0xA8); //
    Wire.endTransmission();
    
    Wire.beginTransmission(address);
    Wire.write(0x42); // Gyro config
    Wire.write(0xA9);
    Wire.endTransmission();
    
    Wire.beginTransmission(address); //
    Wire.write(0x7C); // PWR config
    Wire.write(0x02);
    Wire.endTransmission();
    }
    
    void loop()
    {
    Wire.beginTransmission(address);
    Wire.write(0x0C); // reading LSB of Acc
    Wire.requestFrom(address,1);
    
    if(Wire.available()<=1)
    {
    response = Wire.read();
    }
    Wire.endTransmission();
    Serial.println(response);
    delay(500);
    }

     

    Thanks in advance!

    7 REPLIES 7

    etracer
    Established Member

    I haven't tried reading only the LSB. Try reading both the LSB and MSB. Reading only the LSB might be preventing the register from getting updated. From the datasheet:

    Reading the acceleration data registers shall always start with the LSB part. In order to ensure the integrity of the acceleration data, the content of an MSB register is locked by reading the corresponding LSB register (shadowing procedure).

    Thanks for your response but unfortunately I coulndn't solve the problem.
    I changed the code as follows but output is still zero.

    #include <Wire.h> //I2C Arduino Library
    
    #define address 0x69 //I2C 7bit address
    
    int response;
    
    void setup(){
      //Initialize Serial and I2C communications
      Serial.begin(9600);
      Wire.begin();
      delay(100);
    //  Wire.setClock(400000UL);
     
    // setting IMU270 in normal mode
      Wire.beginTransmission(address);  
      Wire.write(0x7D); //PWR_Control Register
      Wire.write(0x0E); // enable acquistion of acc,gyro and temp
      Wire.endTransmission();
        delay(100);
    
      Wire.beginTransmission(address);
      Wire.write(0x40);   // Acc config
      Wire.write(0xA8);   // 
      Wire.endTransmission();
      delay(100);
    
      Wire.beginTransmission(address);  
      Wire.write(0x42);   // Gyro config
      Wire.write(0xA9);
      Wire.endTransmission();
      delay(100);
    
      Wire.beginTransmission(address); // 
      Wire.write(0x7C);   // PWR config
      Wire.write(0x02);
      Wire.endTransmission();
      delay(100);
    
    //  Wire.beginTransmission(address); 
    //  Wire.write(0x7E);   // soft reset in CMD
    //  Wire.write(0xb6);
    //  Wire.endTransmission();
    }     
    
    void loop()
    {
      Wire.beginTransmission(address);
      Wire.write(0x0C);    // reading LSB of Acc
      Wire.endTransmission();
      Wire.requestFrom(address,2); 
      if(2<= Wire.available())
      {
          response = Wire.read()<<8|Wire.read();
      }
    
      Serial.println(response);
      delay(500);
    }

     

    etracer
    Established Member

    Well first your logic is incorrect. The data order is LSB then MSB so this is wrong:

    response = Wire.read()<<8|Wire.read();

     

    Also realize that you're reading the X axis which would basically be 0 if the device was sitting level on the table. Try reading the Z axis and you should get about 1G.

    Oh you are right.
    Thanks for the information.

    But output also shouldn't be zero although I am reading the x-axis on account of the noise.
    After asking for z-axis acceleration and shifting the eight MSB about one byte result is still zero 🤔.

    void loop()
    {
      Wire.beginTransmission(address);
      Wire.write(0x10);    // reading LSB of Acc
      Wire.endTransmission();
      Wire.requestFrom(address,2); 
      if(2<= Wire.available())
      {
          response = Wire.read()|Wire.read()<<8;
      }
    
      Serial.println(response);
    }


    Thanks so far!!
     

    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