Bosch Sensortec Community

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

    Unable to connect BMI270 Shuttle board using SPI

    Unable to connect BMI270 Shuttle board using SPI

    Yafra7
    New Poster

    Hi,

    We're trying to use the BMI270 shuttle board using SPI with the Nordic chip nrf52840 but the connection init keeps failing.

     

    We followed the shuttle board datasheet (https://www.bosch-sensortec.com/media/boschsensortec/downloads/shuttle_board_flyer/bst-dhw-fl040.pdf) and connected  as following :

    VDD and VDDIO to 2.8V

    SDO -> Pin 30 on the Nordic DK

    SDI -> Pin 29 on the Nordic DK

    SCK -> Pin 26 on the Nordic DK

    CSB_BMI270 -> Pin 31 on the Nordic DK

     

    We also removed all the connectors on the top of the shuttle board (since we're not sure exactly what they do).

     

    The code we used is the following , it's made with nordic sdk + the bmi270 api (https://github.com/BoschSensortec/BMI270-Sensor-API)

    #define CS_PIN 31
    #define SCK_PIN 26
    #define MOSI_PIN 29
    #define MISO_PIN 30
    
    static const nrf_drv_spi_t spi_instance = NRF_DRV_SPI_INSTANCE(0);
    
    static struct bmi2_dev bmi270_dev;
    
    static void init_bmi270()
    {
        int8_t res = BMI2_OK;
    
        bmi270_dev.chip_id = BMI270_CHIP_ID;
        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 = hdc_user_spi_read;
        bmi270_dev.write = hdc_user_spi_write;
        bmi270_dev.delay_us = hdc_user_delay_us;
        bmi270_dev.config_file_ptr = NULL;
    
    
         res = bmi270_init(&bmi270_dev);
         switch (res) {
             case BMI2_OK:
                 NRF_LOG_INFO("Init Bmi270 OK :)");
                 break;
            case BMI2_E_COM_FAIL:
                 NRF_LOG_INFO("Init Bmi270 BMI2_E_COM_FAIL");
                 break;
            case BMI2_E_NULL_PTR:
                 NRF_LOG_INFO("Init Bmi270 BMI2_E_NULL_PTR");
                 break;
            case BMI2_E_DEV_NOT_FOUND:
                NRF_LOG_INFO("Init Bmi270 BMI2_E_DEV_NOT_FOUND");
                 break;
         }
         NRF_LOG_INFO("Bmi270 init : %d", res);
    }
    
    void imu_init(void)
    {
        // init spi
        nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
        spi_config.ss_pin     = CS_PIN_IMU;
        spi_config.miso_pin   = SPI0_CONFIG_MISO_PIN;
        spi_config.sck_pin    = SPI0_CONFIG_SCK_PIN;
        spi_config.mosi_pin = SPI0_CONFIG_MOSI_PIN;
        spi_config.frequency  = NRF_DRV_SPI_FREQ_2M;
        spi_config.mode       = NRF_DRV_SPI_MODE_0;
        spi_config.bit_order  = (nrf_drv_spi_bit_order_t) NRF_SPI_BIT_ORDER_MSB_FIRST;
        uint32_t err_code = nrf_drv_spi_init(&spi_instance, &spi_config, NULL, NULL);
        APP_ERROR_CHECK(err_code);
    
        nrf_gpio_cfg_output(CS_PIN_IMU);
        nrf_gpio_pin_set(CS_PIN_IMU);
    
        init_bmi270();
    }

     

     And the we always fall in the 'case BMI2_E_NULL_PTR' after calling bmi270_init.

    Thanks for your time,

    Yohann

    5 REPLIES 5

    BSTRobin
    Community Moderator
    Community Moderator

    Hello Yafra7,

    In BMI270 driver code, there was null pointer check. You could double check your initial assignment of structure bmi270_dev.

    static int8_t null_ptr_check(const struct bmi2_dev *dev)
    {
    int8_t rslt = BMI2_OK;

    if ((dev == NULL) || (dev->read == NULL) || (dev->write == NULL) || (dev->delay_us == NULL))
    {
    /* Device structure pointer is not valid */
    rslt = BMI2_E_NULL_PTR;
    }

    return rslt;
    }

    Hello BSTRobin,

    Thanks for your answer but i don't understand which pointer you want me to check because as shown in my code I don't use any pointer.

    BSTRobin
    Community Moderator
    Community Moderator

    Hello Yafra7,

    You need to check hdc_user_spi_read, hdc_user_spi_write, hdc_user_delay_us you used. What are these function definition?

    bmi270_dev.read = hdc_user_spi_read;
        bmi270_dev.write = hdc_user_spi_write;
        bmi270_dev.delay_us = hdc_user_delay_us;

     

    Hello,

    Here are the functions definitions

    int8_t hdc_user_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *bmi270_dev)
    {
    ret_code_t ret;

    nrf_gpio_pin_clear(CS_PIN_IMU);
    ret = nrf_drv_spi_transfer(&spi_instance, &reg_addr, 1, NULL, 0);

    if(ret == NRF_SUCCESS)
    nrf_drv_spi_transfer(&spi_instance, NULL, 0, reg_data, len);
    else
    NRF_LOG_INFO("ERROR nrf_drv_spi_transfer");
    nrf_gpio_pin_set(CS_PIN_IMU);
    return (int8_t)ret;
    }

    int8_t hdc_user_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *bmi270_dev)
    {
    ret_code_t ret;

    nrf_gpio_pin_clear(CS_PIN_IMU);
    ret = nrf_drv_spi_transfer(&spi_instance, &reg_addr, 1, NULL, 0);
    if (ret == NRF_SUCCESS)
    ret = nrf_drv_spi_transfer(&spi_instance, reg_data, len, NULL, 0);
    else
    NRF_LOG_INFO("ERROR nrf_drv_spi_transfer");
    nrf_gpio_pin_set(CS_PIN_IMU);
    return (int8_t)ret;
    }

    void hdc_user_delay_us(uint32_t period, void *bmi270_dev)
    {
    nrf_delay_us(period);
    }

    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