Bosch Sensortec Community

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

    BMI270 initialization issue with PIC32MZ204BEFH064

    BMI270 initialization issue with PIC32MZ204BEFH064

    yosibuc
    New Poster

    Hi,

    I'm working with the BMI270 with PIC32MZ204BEFH064 over SPI. I'm using the Gihub driver and I have problems with the initialization of the devide.
    Debugging the code I noticed that the initialization fails when reading for the config files back after writing.

    The "INTERNAL_STATUS (0x21)" value is 0x02 = init_err
    The error I get is always `BMI2_E_CONFIG_LOAD`.

    Following my initialization code:

    #define SPI_BUFF_SZ (8+1)

    void user_delay_us(uint32_t period_us, void *intf_ptr)
    {
    /* Wait for a period amount of microseconds. */
    DelayUs((unsigned long int)period_us);
    }

    /*!
    * @brief This function is for writing the sensor's registers through SPI bus.
    */
    int8_t user_spi_reg_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
    {
    /* Write to registers using SPI. Return 0 for a successful execution. */
    int i;
    uint8_t tmp_TX_buf[SPI_BUFF_SZ];

    // if( length > (SPI_BUFF_SZ-1) )
    // {
    // return -1; //YOSSI TODO- implement Error_Handler();
    // }

    tmp_TX_buf[0] = k_SPI_WRITE_REG_VAL | reg_addr;
    memcpy(tmp_TX_buf + 1, reg_data, length);

    LATEbits.LATE4 = 0; //CS BMI270 = 0;
    TP4 = 0;
    //FREEing THE SPI BUF
    while (SPI2STATbits.SPIRBF)
    {
    tmp_TX_buf[0] = SPI2BUF;
    }

    SPI2BUF = tmp_TX_buf[0] & 0xFF;
    while(!SPI2STATbits.SPIRBF);
    tmp_TX_buf[0] = SPI2BUF;

    for(i=0; i<length; i++)
    {
    SPI2BUF = tmp_TX_buf[1+i] & 0xFF;
    while(!SPI2STATbits.SPIRBF);
    tmp_TX_buf[1+i] = SPI2BUF;
    }

    LATEbits.LATE4 = 1; //CS BMI270 = 1;
    TP4 = 1;

    return 0;
    }

    /*!
    * @brief This function is for reading the sensor's registers through SPI bus.
    */

    int8_t user_spi_reg_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr)
    {
    /* Read from registers using SPI. Return 0 for a successful execution. */
    int i;
    uint8_t tmp_TX_buf[10];//,CRM_RX_buf[100];

    LATEbits.LATE4 = 0; //CS BMI270 = 0;
    TP4 = 0;
    tmp_TX_buf[0] = k_SPI_READ_REG_VAL | reg_addr;

    //FREEing THE SPI BUF
    while (SPI2STATbits.SPIRBF)
    {
    reg_data[0] = SPI2BUF;
    }

    SPI2BUF = tmp_TX_buf[0] & 0xFF;
    while(!SPI2STATbits.SPIRBF);
    reg_data[0] = SPI2BUF; //

    for(i=0;i<length;i++)
    {
    SPI2BUF = tmp_TX_buf[i] & 0xFF;
    while(!SPI2STATbits.SPIRBF);
    reg_data[i] = SPI2BUF; //
    }

    //BMI270 = 1;
    LATEbits.LATE4 = 1;
    TP4 = 1;

    return 0;
    }

    int8_t bmi2_interface_selection(struct bmi2_dev *dev)
    {
    int8_t rslt = BMI2_OK;

    if (dev != NULL)
    {
    /* Select the interface for execution
    * For I2C : BMI2_I2C_INTF
    * For SPI : BMI2_SPI_INTF
    */
    dev->intf = BMI2_SPI_INTF;

    ....

    6 REPLIES 6

    yosibuc_0-1596372342095.png

    FYI..... but still thanks pointing me to the issue.

     

    BSTRobin
    Community Moderator
    Community Moderator
    It is good, your program runs normally.
    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