BMI270 Init SPI

Hello all,
I am trying to migrate my project from BMI160 to BMI270 but so far I am unable to initialise the device.
I began with some code which works for BMI160 (ATSAM M0+, Atmel studio) and am trying to migrate using the reference API :https://github.com/BoschSensortec/BMI270-Sensor-API.
Hopefully someone can help point me in the right direction.

1) Firstly I should point out that SPI communication works with BMI270 using my user spi read/write functions directly:

static uint8_t read_test_buff[2] = {0, 0};
static uint8_t write_test_buff[2] = {0x11, 0x12}; // some random data
static uint8_t read_test_buff2[2] = {0, 0, 0};

// READ TEST //
user_spi_read(0, BMI2_CHIP_ID_ADDR, read_test_buff, 2);
//updates as expected: read_test_buff = {0, 0x24, 0}; // SUCCESS

// WRITE TEST //
user_spi_write(0, BMI2_ACC_OFF_COMP_0_ADDR, write_test_buff, 2); // write to accelerometer offset x & y registers
user_spi_read(0, BMI2_ACC_OFF_COMP_0_ADDR, read_test_buff2, 3); // read accelerometer offset x & y registers
//updates as expected: read_test_buff2 = {0, 0x11, 0x12}; // SUCCESS

QUESTION: Is this output format correct?
Or should I be getting something like read_test_buff={0x24, 0} and read_test_buff2={ 0x23, 0x24, 0},
or something else ?

2) Here's my code to initialise the sensor:

struct bmi2_dev bmi270_dev;

int8_t BMI270_sensor_init(void)
{
     int8_t rslt = BMI2_OK;

     // Set SPI interface parameters
     bmi270_dev.chip_id = BMI270_CHIP_ID; // also tried chip_id =0
     bmi270_dev.dummy_byte = 1;
     bmi270_dev.read_write_len = 32; // also tried read_write_len= 8192  as in github arduino gist
     bmi270_dev.intf = BMI2_SPI_INTF;
     bmi270_dev.read = user_spi_read;
     bmi270_dev.write = user_spi_write;
     bmi270_dev.delay_us = user_delay_us;
     bmi270_dev.config_file_ptr = NULL;

     rslt = bmi270_init(&bmi270_dev);
     return rslt;
}

Whilst debugging I have followed initiation through to bmi2_soft_reset(...). More specifically to the line:
/* Reset bmi2 device */
rslt = bmi2_set_regs(BMI2_CMD_REG_ADDR, &data, 1, dev);
This calls 'user_spi_write', however it throws an error.
There seems to be a similar issue when bmi2_get_regs(...) is called. (rslt = BMI2_E_COM_FAIL).

Any help would be much appreciated!

Best reply by fish

Hi

Please read chip id to confirm the SPI communication is ok. If you could read chip id success, and then to run the bmi270_init() success.

We offer COINES examples code to help customer learn how to run BMI270. Pleas install coines, refer to bmi270_read_accel.c.

(1) you need remap your spi read/write to API fucntion.

(2) I can't find out any issue.

(3) After run bmi270_read_accel.c, I log some SPI data from Logic

Time [s]Packet IDMOSIMISO2.2E-0600x7E0x005.5E-0600xB60x000.00746210x800x000.00746310x000x000.00746510x000x240.01286720xFC0x000.01286820x000x000.0128720x000x030.01761230x7C0x000.01761530x020x000.02337340xD90x000.02337440x000x000.02337640x000x000.02946650x590x000.02946950x000x000.03337460x5B0x000.03337960x000x000.03338260x000x00

 

 

View original
2 replies
Resolved