Hi, I try to read data from the ICM20948 IMU with I2C from my nRF 52840 DK.
Initialization of the device is correct, the IMU ID is sent to nRF correctly which means that the TWI protocol works fine but when I initiate the process to read the accelerometer and gyroscope data from the IMU, the following error appears in the terminal emulator app: ERROR 17 [NRF_ERROR_BUSY] at ... ... ... ICM20948.c:180.
The part of code that is pointed is line 12 in the following code snippet
void read_IMU(void){
uint8_t pinax[] = {ICM20948_ACCEL_XOUT_H};
int8_t rawData[12] = {0};
err_code = nrf_drv_twi_tx(&m_twi, ICM20948_ADDRESS, pinax, sizeof(pinax), false);
while(nrf_drv_twi_is_busy(&m_twi));
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_twi_rx(&m_twi, ICM20948_ADDRESS, &rawData[0], 12);
//while(nrf_drv_twi_is_busy(&m_twi));
APP_ERROR_CHECK(err_code); // <<<===== ERROR 17 [NRF ERROR BUSY]
accel_buffer[0] = (int16_t) ((rawData[0] << 8) | rawData[1]); // x axis raw data
accel_buffer[1] = (int16_t) ((rawData[2] << 8) | rawData[3]); // y axis raw data
accel_buffer[2] = (int16_t) ((rawData[4] << 8) | rawData[5]); // z axis raw data
gyro_buffer[0] = (int16_t) ((rawData[6] << 8) | rawData[7]); // x axis raw data
gyro_buffer[1] = (int16_t) ((rawData[8] << 8) | rawData[9]); // y axis raw data
gyro_buffer[2] = (int16_t) ((rawData[10] << 8) | rawData[11]); // z axis raw data
}
Now, if I add this line of code ---> while(nrf_drv_twi_is_busy(&m_twi)); before the APP_ERROR_CHECK() in line 11, the problem disappears
but in the next command where I want to fetch the IMU data ---> nrf_drv_twi_rx() , the SDA line stays low and no stop is produced from the nRF52840 TWI.
As a result I cannot get an RX event from the nRF. What am I doing wrong here?
Also, I cannot understand if the way that I am using nrf_drv_twi_is_busy(&m_twi) is correct or if I should use it another way
Thank you for your time