I am facing some issue while writing to i2c. On first i2c write , device is working but after that when i tries to write anything, code is stucking in loop.
void sensor_sleep_mode(void)
{
ret_code_t err_code;
uint8_t buff[2]={0x06, 0x01};
err_code = nrf_drv_twi_tx(&m_twi, ICM20648_ADDR, buff, sizeof(buff), true);
APP_ERROR_CHECK(err_code);
while (m_xfer_done == false);
}
when i call above function only. Device is working fine, I am able to read any register of the i2c device.
void sensor_usr_ctrl(void)
{
ret_code_t err_code;
m_xfer_done = false;
uint8_t buff[2]={0x03, 0x10};
err_code = nrf_drv_twi_tx(&m_twi, ICM20648_ADDR, buff, sizeof(buff), true);
APP_ERROR_CHECK(err_code);
while (m_xfer_done == false);
}
but when i tries to write anything, like above command on the i2c. Code is stucking in sensor_sleep_mode while loop. Do i need to add something before writing another i2c command? I also tried with add some delay before i2c write, but still same issue.
I debug code more and find out that device is coming last in this case NRF_DRV_TWI_EVT_ADDRESS_NACK: