MPU- 9250 I2C SPI connection

Hello,

I have been using Arduino Yun with MPU 9250. I am supposed to perform only acceleration and temperature acquisition at 1khz. I could not manage to achieve it with I2C. All I could obtain was 0.4khz. So I decided to use SPI but at this point the connection fails and it returns an error. It is because I kept the connections for I2C.

Since I could not find enough article, I failed to make proper connections for SPI. How can I make the connections? Can I reach 1khz with I2C without dealing with SPI?

Thank you!

The error is the following;

IMU initialization unsuccessful
Check IMU wiring or try cycling power
Status: -1

and here is the code I am using;

#include “MPU9250.h”

// an MPU9250 object with the MPU-9250 sensor on SPI bus 0 and chip select pin 10
MPU9250 IMU(SPI,10);
int status;

void setup() {
// serial to display data
Serial.begin(115200);
while(!Serial) {}

// start communication with IMU
status = IMU.begin();
if (status < 0) {
Serial.println(“IMU initialization unsuccessful”);
Serial.println(“Check IMU wiring or try cycling power”);
Serial.print("Status: ");
Serial.println(status);
while(1) {}
}
}

void loop() {
// read the sensor
IMU.readSensor();
// display the data
Serial.print(IMU.getAccelX_mss(),6);
Serial.print("\t");
Serial.print(IMU.getAccelY_mss(),6);
Serial.print("\t");
Serial.print(IMU.getAccelZ_mss(),6);
Serial.print("\t");
Serial.print(IMU.getGyroX_rads(),6);
Serial.print("\t");
Serial.print(IMU.getGyroY_rads(),6);
Serial.print("\t");
Serial.print(IMU.getGyroZ_rads(),6);
Serial.print("\t");
Serial.print(IMU.getMagX_uT(),6);
Serial.print("\t");
Serial.print(IMU.getMagY_uT(),6);
Serial.print("\t");
Serial.print(IMU.getMagZ_uT(),6);
Serial.print("\t");
Serial.println(IMU.getTemperature_C(),6);
delay(100);
}

With that code you won't ever reach 400Hz, the maximum is below 10Hz:

delay(100);

Even if you remove the delay() call completely the limiting factor is the serial interface which allow only 11 characters per millisecond. Definitely not enough to send all values the MPU offers.

You might get it working with a limited set of values on 400kHz I2C but that's not easy to get with the current hardware.

To use SPI you definitely need a level converter (for I2C it's just strongly advised) otherwise you fry the sensor (I expect you to use the sensor directly without a breakout board as you didn't write about a breakout board!). SCKL, MOSI and CS are from Arduino to sensor, while MISO is from sensor to Arduino (for the level converter direction).
You must use the ICSP header to reach the SPI signals on the Yun.