isouriadakis / Arduino_ICM20948_DMP_Full-Function

Arduino Library for ICM20948 using DMP for i2c and SPI
45 stars 6 forks source link

How to use the library with SPI? #7

Closed joshgalvan closed 10 months ago

joshgalvan commented 1 year ago

The library states that SPI is supported, yet I don't see a way to use it with SPI. I have an ICM-20948 sensor that I have successfully used with other SPI libraries, but can't tell how to get this one set up.

isouriadakis commented 1 year ago

Hi,

You should be able to use the SPI by modifying these settings.

is_SPI cs_pin spi_speed

In case this doesn’t work, check that you have connected the imu to the SPI0.

I don’t have an ICM20948 at the moment do help out in case it doesn’t work.

ArduinoICM20948Settings icmSettings =
{
  .i2c_speed = 400000,                // i2c clock speed
  .is_SPI = true,                    // Enable SPI, if disable use i2c
  .cs_pin = 10,                       // SPI chip select pin
  .spi_speed = 7000000,               // SPI clock speed in Hz, max speed is 7MHz
  .mode = 1,                          // 0 = low power mode, 1 = high performance mode
  .enable_gyroscope = true,           // Enables gyroscope output
  .enable_accelerometer = true,       // Enables accelerometer output
  .enable_magnetometer = true,        // Enables magnetometer output // Enables quaternion output
  .enable_gravity = true,             // Enables gravity vector output
  .enable_linearAcceleration = true,  // Enables linear acceleration output
  .enable_quaternion6 = true,         // Enables quaternion 6DOF output
  .enable_quaternion9 = true,         // Enables quaternion 9DOF output
  .enable_har = true,                 // Enables activity recognition
  .enable_steps = true,               // Enables step counter
  .gyroscope_frequency = 1,           // Max frequency = 225, min frequency = 1
  .accelerometer_frequency = 1,       // Max frequency = 225, min frequency = 1
  .magnetometer_frequency = 1,        // Max frequency = 70, min frequency = 1 
  .gravity_frequency = 1,             // Max frequency = 225, min frequency = 1
  .linearAcceleration_frequency = 1,  // Max frequency = 225, min frequency = 1
  .quaternion6_frequency = 50,        // Max frequency = 225, min frequency = 50
  .quaternion9_frequency = 50,        // Max frequency = 225, min frequency = 50
  .har_frequency = 50,                // Max frequency = 225, min frequency = 50
  .steps_frequency = 50               // Max frequency = 225, min frequency = 50  
};
joshgalvan commented 1 year ago

Thank you!

Thet setup() function calls i2c_scan() which causes it to hang, so I commented that out and the if statement and just called icm20948.init(icmSettings) directly but it still hangs with a message stating "Initializing ICM-20948..." and doing nothing else

joshgalvan commented 1 year ago

Just setting ICM_found = true in setup() by hand causes values to be output. Seems like it's working currently.