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,®ister_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
)
... View more