10-30-2019 08:34 AM
Hello,
I setup a small system with a couple of sensors including BMI270. THe system is based on an Adafruit Feather M0. I wasn't able to get the github driver working in Arduino so I started writing my own driver following the routines from the datasheet (page 19 following). Communication test (a) works, initialization step (b) seems to work too but while checking the initialization status I get 0x2 instead of 0x1 from the init status registers (0x21).
My assumption is that the config file might be wrong. I'm using the byte sequence (const uint8_t bmi270_config_file[]) provided in the github repository in file "bmi270.c".
Is that the correct one?
Thanks and best regards,
Christoph
Solved! Go to Solution.
03-30-2020 07:29 AM
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.
11-16-2020 12:20 AM
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.
11-17-2020 12:05 AM
11-17-2020 08:07 PM
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.
11-18-2020 12:55 AM
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;
}