tdk-invn-oss / motion.arduino.ICM42670P

Arduino Driver for TDK InvenSense consumer motion sensor ICM42670P
https://invensense.tdk.com/smartmotion
BSD 3-Clause "New" or "Revised" License
31 stars 3 forks source link

IMU.begin() fails to starts #6

Closed Lapporatory992 closed 4 months ago

Lapporatory992 commented 1 year ago

Using Adafruit Nordic nrf52 / nrf52832 Wire What is causing i2c to hang? Absence of NACK?


Remote debugging using localhost:2331 0x00026830 in TwoWire::endTransmission (stopBit=true, this=0x20004870 ) at /home/pi/.platformio/packages/framework-arduinoadafruitnrf52/libraries/Wire/Wire_nRF52.cpp:230 230 while(!_p_twim->EVENTS_LASTTX && !_p_twim->EVENTS_ERROR);


where line 230 https://github.com/adafruit/Adafruit_nRF52_Arduino/blob/master/libraries/Wire/Wire_nRF52.cpp


code:

include "Arduino.h"/** \file main.cpp

include "main.h"

include

/* First sensor Wire class / TwoWire i2cWire0 = TwoWire(NRF_TWIM0, NRF_TWIS0, SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn, SDA1, SCL1); /* Second sensor Wire class / TwoWire i2cWire1 = TwoWire(NRF_TWIM1, NRF_TWIS1, SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn, SDA2, SCL2);

// Initializing the ICM42670P I2C bus 0 with address 0x68 ICM42670P IMU(i2cWire1, 0); int status; bool imuSetupFailed = false;

void setup() { int ret; pinMode(LED_BUILTIN, OUTPUT); //digitalWrite(BLUE_LED, HIGH); digitalWrite(LED_BUILTIN, HIGH); pinMode(PWR_KEEP, OUTPUT); digitalWrite(PWR_KEEP, HIGH); Serial.begin(115200); while(!Serial) {} // Initializing the ICM42670P ret = IMU.begin(); if (ret != 0) { Serial.print("ICM42670P initialization failed: "); Serial.println(ret); while(1); } // Accel ODR = 100 Hz and Full Scale Range = 16G IMU.startAccel(100,16); // Gyro ODR = 100 Hz and Full Scale Range = 2000 dps IMU.startGyro(100,2000); // Wait IMU to start delay(100); // Plotter axis header Serial.println("AccelX,AccelY,AccelZ,GyroX,GyroY,GyroZ,Temperature"); }

void loop() {

  inv_imu_sensor_event_t imu_event;

  // Get last event
  IMU.getDataFromRegisters(&imu_event);

  // Format data for Serial Plotter
  Serial.print(imu_event.accel[0]);
  Serial.print(",");
  Serial.print(imu_event.accel[1]);
  Serial.print(",");
  Serial.print(imu_event.accel[2]);
  Serial.print(",");
  Serial.print(imu_event.gyro[0]);
  Serial.print(",");
  Serial.print(imu_event.gyro[1]);
  Serial.print(",");
  Serial.print(imu_event.gyro[2]);
  Serial.print(",");
  Serial.println(imu_event.temperature);

  // Run @ ODR 100Hz
  delay(10);
}
rbuisson-invn commented 1 year ago

Your code seems correct. Something might be wrong at hardware level, could you please observe the I2C signals? And share here the captured signals if the issue is not obvious?

rbuisson-invn commented 1 year ago

Meanwhile, can you also share a picture of your setup and a pin description?

Lapporatory992 commented 1 year ago

Hi M. Buisson,

First, thank you very much for looking into the issue, much appreciated.

Please find enclosed a picture of the schematics (old references to 9DOF but of course it's 6DOF, our prior board was using older MPU9250 now EOL so replacing it with newer ICM42670P).

I will try again to get ICM to work on stand-alone basis using the example code and after that will try reading from 2 different i2c sensors at the same time (the 2nd sensor is a PPG/heart rate sensor). The MCU is a nRF52832 chip from Nordic. Any comments / suggestions welcome as we're kind of stuck at this point.

Kind regards, Matt

On Tue, May 9, 2023 at 5:51 AM rbuisson-invn @.***> wrote:

Meanwhile, can you also share a picture of your setup and a pin description?

— Reply to this email directly, view it on GitHub https://github.com/InvenSenseInc/arduino.ICM42670P/issues/6#issuecomment-1539801686, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOPIWZCITGDKU5FG5SV7C23XFIHSJANCNFSM6AAAAAAXYRWE6U . You are receiving this because you authored the thread.Message ID: @.***>

sriccardi-invn commented 1 year ago

Hi Matt, Have you fixed your issue? If not, could you share us a picture of your setup and describe wires connecttion between MCU and ICM42670P ? If you have logic analyzer, could you share I2C traces? Regards, Sebastien Riccardi

Lapporatory992 commented 1 year ago

Hi Sebastian,

thanks a lot for your help / support. Good news, we were able to get the ICM to work on a stand alone basis. Now I am having issues reading from another i2c sensor (running at 400khz) on the same bus. I have changed the ICM clock to 400khz as well but you can see in extract log that the ICM data is scrambled Any clue by chance? Thanks again! logICM

sriccardi-invn commented 1 year ago

Hi Matt, Happy to ear that you were able to get ICM data. If you can explain us how you fix the issue, it can help us to improve driver or documentation. Regarding your issue when you read two sensors, are you in I2C polling mode or you are on IMU interrupt ? Have you verify that both sensors don't use same I2C address? Do you have the capability to collect I2C trace with a logic analyzer? Regards, Sebastien