College Project

Dependencies:   mbed MPU9250_SPI_Test MPU9250-XCLIN

Committer:
kylongmu
Date:
Wed Jun 25 15:43:17 2014 +0000
Revision:
0:58f9d4556df7
Child:
1:7497c7952470
SPI read MPU9250

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kylongmu 0:58f9d4556df7 1 #include "mbed.h"
kylongmu 0:58f9d4556df7 2 #include "MPU9250.h" //Include library
kylongmu 0:58f9d4556df7 3
kylongmu 0:58f9d4556df7 4 DigitalOut myled(LED1);
kylongmu 0:58f9d4556df7 5 Serial pc(SERIAL_TX, SERIAL_RX);
kylongmu 0:58f9d4556df7 6 SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK);
kylongmu 0:58f9d4556df7 7 mpu9250_spi imu(spi,SPI_CS); //define the mpu9250 object
kylongmu 0:58f9d4556df7 8 int main(){
kylongmu 0:58f9d4556df7 9 pc.baud(115200);
kylongmu 0:58f9d4556df7 10 if(imu.init(1,BITS_DLPF_CFG_5HZ)){ //INIT the mpu9250
kylongmu 0:58f9d4556df7 11 printf("\nCouldn't initialize MPU6000 via SPI!");
kylongmu 0:58f9d4556df7 12 }
kylongmu 0:58f9d4556df7 13 wait(0.1);
kylongmu 0:58f9d4556df7 14 printf("\n\nWHOAMI=%u\n",imu.whoami()); //output the I2C address to know if SPI is working, it should be 104
kylongmu 0:58f9d4556df7 15 wait(0.1);
kylongmu 0:58f9d4556df7 16 printf("\nGyro_scale=%u\n",imu.set_gyro_scale(BITS_FS_2000DPS)); //Set full scale range for gyros
kylongmu 0:58f9d4556df7 17 wait(1);
kylongmu 0:58f9d4556df7 18 printf("\nAcc_scale=%u\n",imu.set_acc_scale(BITS_FS_16G)); //Set full scale range for accs
kylongmu 0:58f9d4556df7 19 wait(0.1);
kylongmu 0:58f9d4556df7 20 while(1) {
kylongmu 0:58f9d4556df7 21 //myled = 1;
kylongmu 0:58f9d4556df7 22 wait(0.1);
kylongmu 0:58f9d4556df7 23 imu.read_temp();
kylongmu 0:58f9d4556df7 24 imu.read_acc();
kylongmu 0:58f9d4556df7 25 imu.read_rot();
kylongmu 0:58f9d4556df7 26 printf("%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f\n",
kylongmu 0:58f9d4556df7 27 imu.Temperature,
kylongmu 0:58f9d4556df7 28 imu.gyroscope_data[0],
kylongmu 0:58f9d4556df7 29 imu.gyroscope_data[1],
kylongmu 0:58f9d4556df7 30 imu.gyroscope_data[2],
kylongmu 0:58f9d4556df7 31 imu.accelerometer_data[0],
kylongmu 0:58f9d4556df7 32 imu.accelerometer_data[1],
kylongmu 0:58f9d4556df7 33 imu.accelerometer_data[2]);
kylongmu 0:58f9d4556df7 34 //myled = 0;
kylongmu 0:58f9d4556df7 35 //wait(0.5);
kylongmu 0:58f9d4556df7 36
kylongmu 0:58f9d4556df7 37 }
kylongmu 0:58f9d4556df7 38 }
kylongmu 0:58f9d4556df7 39