12-19-2019 09:49 AM - edited 12-19-2019 09:50 AM
I'm not able to successfully load init data into BMI270 chip using the code below. Since maximum bytes is 255, I load 32 bytes at the time. I get 0x02 as a result from reading 0x21 (status). I do not have any available SPI ports.
These are the first register readouts:
24200010000000000000000000000000000000000000000026960101000000000002adff00008000800
242000100000000000000000000000000000000000000000fcc40100000000000002310000008000800
242000100000000000000000000000000000000000000000c7f30100000000000002310000008000800
242000100000000000000000000000000000000000000000a222020000000000000200800000800080
2420001000000000000000000000000000000000000000007551020000000000000200800000800080
Any obvious errors? Greatful for any hints or trixes.
uint16_t i;
uint16_t j;
uint32_t err_code;
uint8_t d[33];
uint32_t addr;
nrf_delay_us(500);
bmi270_write(BMI2_PWR_CONF_ADDR, 0x00); // Power on
nrf_delay_us(500);
bmi270_write(BMI2_CMD_REG_ADDR, 0xb6); // Reset
nrf_delay_ms(500);
bmi270_write(BMI2_INIT_CTRL_ADDR, 0x00); // init start
nrf_delay_us(500);
for(i = 0; i < 256; i++)
{
bmi270_write(BMI2_INIT_ADDR_0, 0);
bmi270_write(BMI2_INIT_ADDR_1, i);
d[0] = BMI2_INIT_DATA_ADDR;
addr = i << 5;
for(j = 0; j < 32; j++)
{
d[j+1] = bmi270_config_file[addr + j];
}
err_code = nrf_drv_twi_tx(&m_twi, BMI2_I2C_PRIM_ADDR, d, 33, false);
nrf_delay_us(500);
}
nrf_delay_ms(500);
bmi270_write(BMI2_INIT_CTRL_ADDR, 0x01);
nrf_delay_ms(500);
bmi270_write(BMI2_PWR_CONF_ADDR, 0x00); // Power on
nrf_delay_us(500);
bmi270_write(BMI2_PWR_CTRL_ADDR, 0x0e); // Accelerometer and gyroscope on
nrf_delay_us(500);
bmi270_write(BMI2_FIFO_CONFIG_1_ADDR, 0x00); // FIFO off
nrf_delay_us(500);
bmi270_write(BMI2_PWR_CTRL_ADDR, 0x0e); // Accelerometer and gyroscope on
bmi270_write(BMI2_ACC_CONF_ADDR, 0xbb); // Performance, Avg32, 100Hz
bmi270_write(BMI2_ACC_RANGE_ADDR,0x00); // Range +- 2g
bmi270_write(BMI2_GYR_CONF_ADDR, 0xcb); // Performance, normal operation, 200Hz
bmi270_write(BMI2_GYR_RANGE_ADDR, 0x04); // Gyre range +- 125dps
bmi270_write(BMI2_FIFO_DOWNS_ADDR, 0x00); // Filtering off
bmi270_write(BMI2_FIFO_CONFIG_1_ADDR, 0xd0); // Store acc and Gyro in FIFO
03-20-2023 01:02 PM
This is working for me now:
uint16_t i;
uint16_t j;
uint32_t err_code;
uint8_t d[33];
uint32_t addr;
nrf_delay_us(1000);
bmi270_write(BMI2_CMD_REG_ADDR, 0xb6); // Reset
nrf_delay_ms(500);
bmi270_write(BMI2_PWR_CONF_ADDR, 0x00); // Power on
nrf_delay_us(500);
bmi270_write(BMI2_INIT_CTRL_ADDR, 0x00); // init start
nrf_delay_us(500);
for(i = 0; i < 256; i++)
{
bmi270_write(BMI2_INIT_ADDR_0, 0);
bmi270_write(BMI2_INIT_ADDR_1, i);
d[0] = BMI2_INIT_DATA_ADDR;
addr = i << 5;
for(j = 0; j < 32; j++)
{
d[j+1] = bmi270_config_file[addr + j];
}
err_code = nrf_drv_twi_tx(&m_twi, BMI2_I2C_PRIM_ADDR, d, 33, false);
nrf_delay_us(500);
}
nrf_delay_ms(500);
bmi270_write(BMI2_INIT_CTRL_ADDR, 0x01);
while((bmi270_read(BMI2_INTERNAL_STATUS_ADDR) & 0x07) != 0x01)
{
nrf_delay_us(1000);
}
bmi270_write(BMI2_PWR_CONF_ADDR, 0x04); // Power on
bmi270_write(BMI2_PWR_CTRL_ADDR, 0x0e); // Accelerometer and gyroscope on
bmi270_write(BMI2_ACC_CONF_ADDR, 0xb9); // Performance, Avg128, 200Hz
bmi270_write(BMI2_ACC_RANGE_ADDR,0x00); // Range +- 2g
bmi270_write(BMI2_GYR_CONF_ADDR, 0xc9); // Performance, normal operation, 200 Hz
bmi270_write(BMI2_GYR_RANGE_ADDR, 0x03); // Gyre range +- 250 dps
03-20-2023 01:57 PM - edited 03-20-2023 02:06 PM
Thanks for your fast response, I was surprised you answered even with this post beeing over 3 years old.
Sorry to ask again, but regarding your code how does your bmi270_write() function look like?
I am still a beginner in this area and not sure if the BMI270 would be a good IMU to start with in my situation, but I explained my problem in detail over here:
https://community.bosch-sensortec.com/t5/MEMS-sensors-forum/BMI270-I2C-with-Raspberry-Pi-3B/m-p/7214...
Sadly didn't get enough help to resolve this issue. (which is understandable with that much text to read)
I saw in another post of yours in here that you defined i2c_reg_read() and i2c_reg_write() as well as delay_us() and changed the dev struct. So according to this I figure that you were using the officlal BMI270-Sensor-API on github?
In short I wanted to manually write the Bytes of the bmi270_config_file to the BMI2_INIT_CTRL_ADDR to load the config because I didn't have any success setting up the BMI270-Sensor-API on their git with COINES. So in total I would only use two files: base.cpp and bmi2_defs.h.
My question is what else would need to be done if not just i2cReadByteData() in while() or for() loop to load the values of the config file for example?
Regards
03-21-2023 01:19 PM
uint8_t bmi270_read(uint8_t reg)
{
uint8_t d;
(void)nrf_drv_twi_tx(&m_twi, BMI2_I2C_PRIM_ADDR, ®, 1, true);
(void)nrf_drv_twi_rx(&m_twi, BMI2_I2C_PRIM_ADDR, &d, 1);
return d;
}
void bmi270_write(uint8_t reg, uint8_t data)
{
uint8_t r[2];
r[0] = reg;
r[1] = data;
(void)nrf_drv_twi_tx(&m_twi, BMI2_I2C_PRIM_ADDR, r, 2, false);
}
The setup in last post will give interrupt. Interrupt handler is:
void data_ready_interrupt(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
int16_t dta[6];
int16_t accx;
int16_t accy;
int16_t accz;
int16_t gyrox;
int16_t gyroy;
int16_t gyroz;
dta[0] = 0x0c;
(void)nrf_drv_twi_tx(&m_twi, BMI2_I2C_PRIM_ADDR, (uint8_t *)dta, 1, true);
(void)nrf_drv_twi_rx(&m_twi, BMI2_I2C_PRIM_ADDR, (uint8_t *)dta, 12);
accx = *(dta + 0);
gyrox = *(dta + 3);
accy = *(dta + 1);
gyroy = *(dta + 4);
accz = *(dta + 2);
gyroz = *(dta + 5);
}
Main loop:
while(1);