10-23-2020 02:31 AM - edited 10-23-2020 02:31 AM
Hello,
I am running into issues with the BMI270 API. I'm following the accel.c example provided in the repository. My program never returns from bmi270_init function. Unfortunately I don't have access to proper debugging equipment on my current platform, but I've narrowed it down to occuring somewhere in the bmi2_soft_reset function. I am able to communicate with the device using my user-defined read/write functions and read the correct chip_id from them. I've attached the relevant code below. Any advice appreciated.
Thanks,
Liam
uint8_t rslt;
struct bmi2_dev bmi2_dev;
rslt = bmi2_interface_selection(&bmi2_dev);
SerialUSB.println(rslt);
//test read chip_id
uint8_t dev_addr = BMI2_I2C_PRIM_ADDR;
bmi2_dev.intf_ptr = &dev_addr;
struct bmi2_dev *bmi_ptr = &bmi2_dev;
uint8_t data = 0;
user_i2c_reg_read(0x0, &data, 1, bmi_ptr->intf_ptr);
SerialUSB.println(data,HEX);
//init function, never returns 😞
rslt = bmi270_init(&bmi2_dev);
SerialUSB.println(rslt);
delay(500);
User read/write functions:
/*!
* @brief This function is for writing the sensor's registers through I2C bus.
*/
int8_t user_i2c_reg_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
{
uint8_t addr = *(uint32_t*)intf_ptr;
Wire.beginTransmission(addr);
Wire.write(reg_addr);
for(uint16_t i = 0; i < length; i ++)
Wire.write(reg_data[i]);
Wire.endTransmission();
return(0);
/* Write to registers using I2C. Return 0 for a successful execution. */
return 0;
}
/*!
* @brief This function is for reading the sensor's registers through I2C bus.
*/
int8_t user_i2c_reg_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr)
{
uint8_t addr = *(uint32_t*)intf_ptr;
Wire.beginTransmission(addr);
Wire.write(reg_addr);
if(Wire.endTransmission() != 0) return 0;
Wire.requestFrom(addr, (uint8_t) length);
for(uint16_t i = 0; i < length; i ++)
{
reg_data[i] = Wire.read();
}
Wire.endTransmission();
/* Read from registers using I2C. Return 0 for a successful execution. */
return 0;
}
Solved! Go to Solution.
10-23-2020 03:00 AM
Hello,
If you can't read register 0x00 for chip id, it's highly related to i2c interface itself.
Sorry, I can't give you much information unless you don't have data log like logic analyzer :(.
Thanks,
10-23-2020 03:03 AM - edited 10-24-2020 01:02 AM
Hi Minhwan,
I think you misread my post. I AM able to communicate with the chip and get the correct chip ID (0x24) from register 0x00 using the user_i2c_reg_read function included above.
Liam
Edit: The issue had to do with my delay functions, resolved now.