Arduino Code to Read SPI Data:

#include <SPI.h>
// Connect Arduino pin 11 (Master Out, Slave In) to IMU SDI (Slave Data In) pin
// Connect Arduino pin 12 (Master In, Slave Out) to IMU SDO (Slave Data Out) pin
// Connect Arduino clock pin 13 to IMU SCK pin
#define CS_IMU 8 // Chip select for IMU can be any open digital pin
#define ImuToDeg(x) (((float)x)/100.0) // IMU angle info is in deg*100
#define ImuToVel(x) (((float)x)/10.0) // IMU angular vel is in deg/s*10

int roll, pitch, yaw, rolldot, pitchdot, yawdot;
int accel_x, accel_y, accel_z;

void setup() {
Serial.begin(57600);
pinMode(CS_IMU, OUTPUT);
SPI.begin();
delay(100);
}

void loop() {
static unsigned long t1=0;
if ( (millis()-t1) > 100){ // do update every 100 ms (10 Hz)
t1 = millis();
ReadIMU(0);
Serial.print(ImuToDeg(roll));
Serial.print(" ");
Serial.print(ImuToDeg(pitch));
Serial.print(" ");
Serial.print(ImuToDeg(yaw));
Serial.print(" ");
Serial.print(ImuToVel(rolldot));
Serial.print(" ");
Serial.print(ImuToVel(pitchdot));
Serial.print(" ");
Serial.print(ImuToVel(yawdot));
Serial.print(" ");
Serial.print(accel_x);
Serial.print(" ");
Serial.print(accel_y);
Serial.print(" ");
Serial.println(accel_z);
}
}

void ReadIMU(byte cmd) {
digitalWrite(CS_IMU, LOW); // select device
byte byte0 = SPI.transfer(cmd); // start it
roll = getSPIint(cmd);
pitch = getSPIint(cmd);
yaw = getSPIint(cmd);
rolldot = getSPIint(cmd);
pitchdot = getSPIint(cmd);
yawdot = getSPIint(cmd);
accel_x = getSPIint(cmd);
accel_y = getSPIint(cmd);
accel_z = getSPIint(cmd);
digitalWrite(CS_IMU, HIGH); // deselct device
}

int getSPIint(int command){
byte byte0 = SPI.transfer(command);
byte byte1 = SPI.transfer(command);
int result = ( ((int)byte1 << 8) | (int)byte0 );
return(result);
}
www.000webhost.com