Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    BMI270 Init SPI

    BMI270 Init SPI

    bod609
    Member

    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!

    2 REPLIES 2

    fish
    Community Moderator
    Community Moderator

    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 ID MOSI MISO
    2.2E-06 0 0x7E 0x00
    5.5E-06 0 0xB6 0x00
    0.007462 1 0x80 0x00
    0.007463 1 0x00 0x00
    0.007465 1 0x00 0x24
    0.012867 2 0xFC 0x00
    0.012868 2 0x00 0x00
    0.01287 2 0x00 0x03
    0.017612 3 0x7C 0x00
    0.017615 3 0x02 0x00
    0.023373 4 0xD9 0x00
    0.023374 4 0x00 0x00
    0.023376 4 0x00 0x00
    0.029466 5 0x59 0x00
    0.029469 5 0x00 0x00
    0.033374 6 0x5B 0x00
    0.033379 6 0x00 0x00
    0.033382 6 0x00 0x00

     

     

    Hi fish,
    Indeed my SPI functions needed re-mapping. For anybody else who runs into the same issue:

    BMI160 SPI in the format:
    int8_t user_spi_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len);
    int8_t user_spi_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len);

    BMI270 SPI in the format:
    int8_t user_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint16_t len, struct bmi2_dev *dev);
    int8_t user_spi_write(uint8_t reg_addr, uint8_t *reg_data, uint16_t len, struct bmi2_dev *dev);

    Many thanks

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist