College Project
Dependencies: mbed MPU9250_SPI_Test MPU9250-XCLIN
main.cpp@3:ad2ef67e7f72, 2014-06-29 (annotated)
- Committer:
- kylongmu
- Date:
- Sun Jun 29 07:17:32 2014 +0000
- Revision:
- 3:ad2ef67e7f72
- Parent:
- 2:6de3660a1f92
- Child:
- 4:6bfddd447c27
Info added
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:58f9d4556df7 | 27 | imu.read_temp(); |
kylongmu | 0:58f9d4556df7 | 28 | imu.read_acc(); |
kylongmu | 0:58f9d4556df7 | 29 | imu.read_rot(); |
kylongmu | 1:7497c7952470 | 30 | imu.AK8963_read_Magnetometer(); |
kylongmu | 2:6de3660a1f92 | 31 | 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 | 32 | imu.Temperature, |
kylongmu | 0:58f9d4556df7 | 33 | imu.gyroscope_data[0], |
kylongmu | 0:58f9d4556df7 | 34 | imu.gyroscope_data[1], |
kylongmu | 0:58f9d4556df7 | 35 | imu.gyroscope_data[2], |
kylongmu | 0:58f9d4556df7 | 36 | imu.accelerometer_data[0], |
kylongmu | 0:58f9d4556df7 | 37 | imu.accelerometer_data[1], |
kylongmu | 1:7497c7952470 | 38 | imu.accelerometer_data[2], |
kylongmu | 1:7497c7952470 | 39 | imu.Magnetometer[0], |
kylongmu | 1:7497c7952470 | 40 | imu.Magnetometer[1], |
kylongmu | 1:7497c7952470 | 41 | imu.Magnetometer[2] |
kylongmu | 1:7497c7952470 | 42 | ); |
kylongmu | 0:58f9d4556df7 | 43 | //myled = 0; |
kylongmu | 0:58f9d4556df7 | 44 | //wait(0.5); |
kylongmu | 0:58f9d4556df7 | 45 | |
kylongmu | 0:58f9d4556df7 | 46 | } |
kylongmu | 0:58f9d4556df7 | 47 | } |
kylongmu | 0:58f9d4556df7 | 48 |