03-28-2020 11:51 AM - edited 03-28-2020 12:31 PM
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!
Solved! Go to Solution.
03-28-2020 02:36 PM
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).
03-28-2020 03:12 PM
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);
}
03-28-2020 05:12 PM
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.
03-28-2020 08:01 PM
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!!