Hi, as many other people in this forum, I am facing problems when trying to initialize the BMI270 IC. In my case it is connected to an nRF52832 over I2C at 100kHz. I am using the c code found on github and all I had to do was to implement the read & write functions. In the beginning, while running the bmi2_soft_reset() function included in the bmi270_init() function (actually in the bmi2_sec_init()), I got back error -9: BMI2_E_CONFIG_LOAD. Digging a bit deeper I then discovered that after loading the config file, upon reading the internal status register an internal status error of type "0x02 - init_err" is returned from the INTERNAL_STATUS register. I then decided to read back the config file, after loading it and voila... I found out that, quite weirdly I must say, bytes 2 and 3 of every burst write appears to be overwritten with 0x00 instead of the bytes contained in the config file. For example, if I write this with write burst length = 4 (I substituted the real config file bytes with test bytes for the purpose of clarity) 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10 I get back 0x01, 0x00, 0x00, 0x04, 0x05, 0x00, 0x00, 0x08, 0x09, 0x00, 0x00, 0x0c, 0x0d, 0x00, 0x00, 0x10 That happens regardless of the write burst length (I saw the same with with 4 and 8 burst length). My burst read length was bigger than the burst write length, so I think we can exclude read errors. Any idea why this is happening? Can it be something wrong on the BMI270 side? I also plan to observe the I2C signals with an oscilloscope to actually see what is happening. In case it helps, this is my i2c_write function: int8_t user_i2c_reg_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
{
ret_code_t err_code = NRFX_SUCCESS;
/** Combine reg_addr and reg_data to a single tx_buffer */
uint8_t *buf = malloc((1 + length) * sizeof(uint8_t));
if (buf == NULL) {
return 1;
}
buf[0] = reg_addr;
memcpy(&buf[1], reg_data, length * sizeof(uint8_t));
/* Make sure the bus is not active */
while(nrfx_twim_is_busy(intf_ptr));
/* Set-up and do the I2C transaction */
nrfx_twim_xfer_desc_t const twim_xfer_desc =
{
.type = NRFX_TWIM_XFER_TX,
.address = dev_addr,
.primary_length = length + 1,
.p_primary_buf = buf,
};
err_code = nrfx_twim_xfer(intf_ptr, &twim_xfer_desc, 0);
free(buf);
/* Wait until transaction is over */
while(nrfx_twim_is_busy(intf_ptr));
/* Write to registers using I2C. Return 0 for a successful execution. */
if (err_code == NRFX_SUCCESS) {
return 0;
}
else {
return 1;
}
} and this is my i2c_read function: int8_t user_i2c_reg_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr)
{
ret_code_t err_code = NRFX_SUCCESS;
/* Make sure the bus is not active */
while(nrfx_twim_is_busy(intf_ptr));
/* Set-up and do the I2C transaction */
nrfx_twim_xfer_desc_t const twim_xfer_desc =
{
.type = NRFX_TWIM_XFER_TXRX,
.address = dev_addr,
.primary_length = 1,
.p_primary_buf = ®_addr,
.secondary_length = length,
.p_secondary_buf = reg_data,
};
err_code = nrfx_twim_xfer(intf_ptr, &twim_xfer_desc, 0);
/* Wait until transaction is over */
while(nrfx_twim_is_busy(intf_ptr));
/* Write to registers using I2C. Return 0 for a successful execution. */
if (err_code == NRFX_SUCCESS) {
return 0;
}
else {
return 1;
}
}
... View more