You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello again ,
I make read write function separately reading all register giving me just right value except b0_control reg of bank 0 and B0_EXT_SLV_SENS_DATA_00 , B0_EXT_SLV_SENS_DATA_00 giving me zero value again and again , I am just verifying whoiam of magnetometer . I am adding all codes here please give a small review on that .
Hello again ,
I make read write function separately reading all register giving me just right value except b0_control reg of bank 0 and B0_EXT_SLV_SENS_DATA_00 , B0_EXT_SLV_SENS_DATA_00 giving me zero value again and again , I am just verifying whoiam of magnetometer . I am adding all codes here please give a small review on that .
static void magnetometer()
{
select_bank(0);
read_data(0,B0_USER_CTRL);
write_data(0,B0_USER_CTRL,0x22,2);
read_data(0,B0_USER_CTRL);
write_data(0,B0_USER_CTRL,0x22,2);
read_data(3,B3_I2C_MST_CTRL);
write_data(3,B3_I2C_MST_CTRL,0x07,2);
read_data(3,B3_I2C_MST_CTRL);
write_data(3,B3_I2C_SLV0_ADDR,0x8C,2);
read_data(3,B3_I2C_SLV0_ADDR);
write_data(3,B3_I2C_SLV0_REG,0x01,2);
read_data(3,B3_I2C_SLV0_REG);
write_data(3,B3_I2C_MST_CTRL,0x81,2);
read_data(3,B3_I2C_MST_CTRL);
nrf_delay_ms(10);
select_bank(0);
read_data(0,B0_EXT_SLV_SENS_DATA_00);
}
void write_data(uint8_t ub , uint8_t regaddress , uint8_t regdata , uint8_t size)
{
writeregaddress=regaddress;
writeregdata=regdata;
len = size;
writeub=ub;
nrf_delay_ms(10);
select_bank(writeub);
nrf_delay_ms(10);
uint8_t writedata[2] = {writeregaddress , writeregdata};
err_code = nrf_drv_twi_tx(&m_twi, ICM20948addr ,writedata,len, true);
APP_ERROR_CHECK(err_code);
}
void read_data(uint8_t ub , uint8_t regaddress)
{
writeub=ub;
readregaddress=regaddress;
nrf_delay_ms(10);
select_bank(writeub);
nrf_delay_ms(10);
err_code = nrf_drv_twi_tx(&m_twi, ICM20948addr ,&readregaddress,1, true);
APP_ERROR_CHECK(err_code);
nrf_delay_ms(10);
read_sensor_data();
}
void select_bank(uint8_t bankselectvalue)
{
funbankselect=bankselectvalue;
shifted_value=funbankselect<<4;
bank[0]=bankselect;
bank[1]=shifted_value;
err_code = nrf_drv_twi_tx(&m_twi, ICM20948addr,bank,2, false);
APP_ERROR_CHECK(err_code);
}
void read_sensor_data()
{
m_xfer_done = false;
//NRF_LOG_INFO("1");
//NRF_LOG_FLUSH();
/* Read 1 byte from the specified address - skip 3 bits dedicated for fractional part of temperature. */
ret_code_t err_code = nrf_drv_twi_rx(&m_twi,ICM20948addr ,& m_sample, 1);
APP_ERROR_CHECK(err_code);
NRF_LOG_INFO("%x",m_sample);
NRF_LOG_FLUSH();
}
int main()
{
APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
NRF_LOG_DEFAULT_BACKENDS_INIT();
NRF_LOG_INFO("\r\nTWI sensor example started.");
NRF_LOG_FLUSH();
twi_init();
NRF_LOG_INFO("1");
NRF_LOG_FLUSH();
//ICM();
magnetometer();
NRF_LOG_INFO("end icm");
NRF_LOG_FLUSH();
}
and these are logs
app:
TWI sensor example started.
app: 1
app: 0
app: Register value = 32
app: 20
app: Register value = 32
app: 20
app: Register value = 129
app: 81
app: Register value = 7
app: 7
app: Register value = 140
app: 8C
app: Register value = 1
app: 1
app: Register value = 129
app: 81
app: Register value = 0
app: end icm
please reply , Thanks in advance.
The text was updated successfully, but these errors were encountered: