Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BMI270 initialization problem with nRF52840

    BMI270 initialization problem with nRF52840

    Shinicy99
    New Poster

    Hello everyone, as i read in other topic on this forum i am also struggling to use BMI270 sensor, especially for initialization process.

    I'm using nRF52840 SoC and i connected it to the IMU by using twi/i2c intarface. 

    Here i attach my code for initialization:

    //INIT FUNCTION FOR BMI270
    bool BMI270_init(void)
    {
      bool init_succ=true;
      
      //following datasheet  
      if(!BMI270_verify_product_id())
      {
       init_succ=false;
      }
      
      if(!BMI270_register_write(0x7C,0x00))
      {
        init_succ=false;
      }
      nrf_delay_us(800);
      if(!BMI270_register_write(0x59,0x00))
      {
        init_succ=false;
      }
    
    // load configuration file from github repo
      while(BMI270_conf_file_init())
      {}
    
     if(!BMI270_register_write(0x59,0x01)){
        init_succ=false;// it seems that main problem is in this step
      }
    
      return init_succ;
    }

     and these are the code for writing and reading registers:

    bool BMI270_register_write(uint8_t register_address , uint8_t value)
    {
      ret_code_t err_code;
      uint8_t tx_buff[BMI2_ADDRESS_LEN+1];
    
      tx_buff[0]=register_address;
      tx_buff[1]=value;
    
      m_xfer_done=false;
    
      //transimt data
      err_code=nrf_drv_twi_tx(&m_twi,BMI2_I2C_PRIM_ADDR,tx_buff,BMI2_ADDRESS_LEN+1,false);
      
      while(m_xfer_done==false)
      {
      }
    
      if(err_code != NRF_SUCCESS)
      {
        return false;
      }
    
      return true;
    }
    
    bool BMI270_register_read(uint8_t register_address,uint8_t *destination,uint8_t number_of_bytes)
    {
      ret_code_t err_code;
      //flag for check receive
      m_xfer_done=false;
      //writing address we want to read
      err_code=nrf_drv_twi_tx(&m_twi,BMI2_I2C_PRIM_ADDR,&register_address,1,true);
    
      while(m_xfer_done==false){}
      
      if(err_code != NRF_SUCCESS)
      {
          return false;
      }
    
      m_xfer_done=false;
      //read data
      err_code=nrf_drv_twi_rx(&m_twi,BMI2_I2C_PRIM_ADDR,destination,number_of_bytes);
    
      while(m_xfer_done==false){}
    
       if(err_code != NRF_SUCCESS)
       {
          return false;
       }
    
       return true;
    }

    For burst write the config file i wrote an external function that rewrite on i2c bus the byte from config file:

    bool BMI270_conf_file_init(void)
    {
       uint8_t buff[2];
       int a;
       ret_code_t err_code;
    
    
       for(a=0;a<(sizeof(bmi270_context_config_file)-1);a++)
       {
         buff[0]=0x5E;
         buff[1]=bmi270_context_config_file[a];
         err_code=nrf_drv_twi_tx(&m_twi,BMI2_I2C_PRIM_ADDR,buff,2,true);
         while(m_xfer_done==false){}
    
        if(err_code != NRF_SUCCESS)
            {
                return false;
            }
      
               
       }
       
         buff[0]=0x5E;
         buff[1]=bmi270_context_config_file[sizeof(bmi270_context_config_file)-1];
         err_code=nrf_drv_twi_tx(&m_twi,BMI2_I2C_PRIM_ADDR,buff,2,false);
         while(m_xfer_done==false){}
    
        if(err_code != NRF_SUCCESS)
            {
                return false;
            }
       
    
       return true;
        
    }

     The fact is that as i commented in the first code the initialization works until the last step where the function give me a false, also by bypassing that return false, it seems that reading the 0x5E register at the end of initialization the value does not correspond to the last byte of bmi270_context_config_file.

    I know that are present on the github the API's for this sensor but i didn't understand how i can replace my writing and reading function to implement it.

    Is there any way to overcome initialization burst write? And if it's not possible, how can i solve it?

     

    PS: these are the declaration of the type fucntion used to write and read using twi of the SoC:

    //reading function
    ret_code_t nrf_drv_twi_rx	(	nrf_drv_twi_t const * 	p_instance,
    uint8_t 	address,
    uint8_t * 	p_data,
    uint8_t 	length 
    )	
    
    //writing function
    
    ret_code_t nrf_drv_twi_tx	(	nrf_drv_twi_t const * 	p_instance,
    uint8_t 	address,
    uint8_t const * 	p_data,
    uint8_t 	length,
    bool 	no_stop 
    )	
    3 REPLIES 3

    BSTRobin
    Community Moderator
    Community Moderator

    Hi Shinicy99,

    You can fully refer to the BMI270 example code(https://github.com/boschsensortec/BMI270-Sensor-API/blob/master/bmi270_examples/accel_gyro/accel_gyr...), follow the example code procedure and replace the I2C read and write interface with the nRF52840 interface, and try again.

    Did you mean by replacing directly on code example bmi2.c:

    dev->intf_rslt = dev->write((uint8_t)((uint16_t)reg_addr + loop), &data[loop], 1, dev->intf_ptr);

      on line 2038 for writing function and:

    dev->intf_rslt = dev->read(reg_addr, temp_buf, (len + dev->dummy_byte), dev->intf_ptr);

     line 1980 for reading function with the one expressed for nrf?

    There are others changes that i have to deal with? Because i didn't find any guide for using these API.

    BSTRobin
    Community Moderator
    Community Moderator

    Hi Shinicy99,

    No. You don't need to modify bmi2.c.
    I mean you can refer to accel_gyro.c which will call bmi2_interface_init() in the code. You can implement the content of this function based on your hardware platform.

    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