College Project

Dependencies:   mbed MPU9250_SPI_Test MPU9250-XCLIN

Committer:
kylongmu
Date:
Mon Jun 30 13:16:13 2014 +0000
Revision:
4:6bfddd447c27
Parent:
3:ad2ef67e7f72
Child:
5:5839d1b118bc
Add read all function.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kylongmu 3:ad2ef67e7f72 1 /*CODED by Qiyong Mu on 21/06/2014
kylongmu 3:ad2ef67e7f72 2 kylongmu@msn.com
kylongmu 3:ad2ef67e7f72 3 */
kylongmu 0:58f9d4556df7 4 #include "mbed.h"
kylongmu 0:58f9d4556df7 5 #include "MPU9250.h" //Include library
kylongmu 0:58f9d4556df7 6
kylongmu 0:58f9d4556df7 7 DigitalOut myled(LED1);
kylongmu 0:58f9d4556df7 8 Serial pc(SERIAL_TX, SERIAL_RX);
kylongmu 0:58f9d4556df7 9 SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK);
kylongmu 0:58f9d4556df7 10 mpu9250_spi imu(spi,SPI_CS); //define the mpu9250 object
kylongmu 0:58f9d4556df7 11 int main(){
kylongmu 0:58f9d4556df7 12 pc.baud(115200);
kylongmu 0:58f9d4556df7 13 if(imu.init(1,BITS_DLPF_CFG_5HZ)){ //INIT the mpu9250
kylongmu 1:7497c7952470 14 printf("\nCouldn't initialize MPU9250 via SPI!");
kylongmu 0:58f9d4556df7 15 }
kylongmu 2:6de3660a1f92 16 printf("\nWHOAMI=0x%2x\n",imu.whoami()); //output the I2C address to know if SPI is working, it should be 104
kylongmu 1:7497c7952470 17 wait(1);
kylongmu 2:6de3660a1f92 18 printf("Gyro_scale=%u\n",imu.set_gyro_scale(BITS_FS_2000DPS)); //Set full scale range for gyros
kylongmu 0:58f9d4556df7 19 wait(1);
kylongmu 2:6de3660a1f92 20 printf("Acc_scale=%u\n",imu.set_acc_scale(BITS_FS_16G)); //Set full scale range for accs
kylongmu 1:7497c7952470 21 wait(1);
kylongmu 2:6de3660a1f92 22 printf("AK8963 WHIAM=0x%2x\n",imu.AK8963_whoami());
kylongmu 1:7497c7952470 23 wait(0.1);
kylongmu 0:58f9d4556df7 24 while(1) {
kylongmu 0:58f9d4556df7 25 //myled = 1;
kylongmu 0:58f9d4556df7 26 wait(0.1);
kylongmu 4:6bfddd447c27 27 /*
kylongmu 0:58f9d4556df7 28 imu.read_temp();
kylongmu 0:58f9d4556df7 29 imu.read_acc();
kylongmu 0:58f9d4556df7 30 imu.read_rot();
kylongmu 1:7497c7952470 31 imu.AK8963_read_Magnetometer();
kylongmu 4:6bfddd447c27 32 */
kylongmu 4:6bfddd447c27 33 imu.read_all();
kylongmu 2:6de3660a1f92 34 printf("%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f\n",
kylongmu 0:58f9d4556df7 35 imu.Temperature,
kylongmu 0:58f9d4556df7 36 imu.gyroscope_data[0],
kylongmu 0:58f9d4556df7 37 imu.gyroscope_data[1],
kylongmu 0:58f9d4556df7 38 imu.gyroscope_data[2],
kylongmu 0:58f9d4556df7 39 imu.accelerometer_data[0],
kylongmu 0:58f9d4556df7 40 imu.accelerometer_data[1],
kylongmu 1:7497c7952470 41 imu.accelerometer_data[2],
kylongmu 1:7497c7952470 42 imu.Magnetometer[0],
kylongmu 1:7497c7952470 43 imu.Magnetometer[1],
kylongmu 1:7497c7952470 44 imu.Magnetometer[2]
kylongmu 1:7497c7952470 45 );
kylongmu 0:58f9d4556df7 46 //myled = 0;
kylongmu 0:58f9d4556df7 47 //wait(0.5);
kylongmu 0:58f9d4556df7 48
kylongmu 0:58f9d4556df7 49 }
kylongmu 0:58f9d4556df7 50 }
kylongmu 0:58f9d4556df7 51