College Project
Dependencies: mbed MPU9250_SPI_Test MPU9250-XCLIN
main.cpp@2:6de3660a1f92, 2014-06-29 (annotated)
- Committer:
- kylongmu
- Date:
- Sun Jun 29 07:06:53 2014 +0000
- Revision:
- 2:6de3660a1f92
- Parent:
- 1:7497c7952470
- Child:
- 3:ad2ef67e7f72
All function is working now.
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:7497c7952470 | 11 | printf("\nCouldn't initialize MPU9250 via SPI!"); |
kylongmu | 0:58f9d4556df7 | 12 | } |
kylongmu | 2:6de3660a1f92 | 13 | printf("\nWHOAMI=0x%2x\n",imu.whoami()); //output the I2C address to know if SPI is working, it should be 104 |
kylongmu | 1:7497c7952470 | 14 | wait(1); |
kylongmu | 2:6de3660a1f92 | 15 | printf("Gyro_scale=%u\n",imu.set_gyro_scale(BITS_FS_2000DPS)); //Set full scale range for gyros |
kylongmu | 0:58f9d4556df7 | 16 | wait(1); |
kylongmu | 2:6de3660a1f92 | 17 | printf("Acc_scale=%u\n",imu.set_acc_scale(BITS_FS_16G)); //Set full scale range for accs |
kylongmu | 1:7497c7952470 | 18 | wait(1); |
kylongmu | 2:6de3660a1f92 | 19 | printf("AK8963 WHIAM=0x%2x\n",imu.AK8963_whoami()); |
kylongmu | 1:7497c7952470 | 20 | wait(0.1); |
kylongmu | 0:58f9d4556df7 | 21 | while(1) { |
kylongmu | 0:58f9d4556df7 | 22 | //myled = 1; |
kylongmu | 0:58f9d4556df7 | 23 | wait(0.1); |
kylongmu | 0:58f9d4556df7 | 24 | imu.read_temp(); |
kylongmu | 0:58f9d4556df7 | 25 | imu.read_acc(); |
kylongmu | 0:58f9d4556df7 | 26 | imu.read_rot(); |
kylongmu | 1:7497c7952470 | 27 | imu.AK8963_read_Magnetometer(); |
kylongmu | 2:6de3660a1f92 | 28 | 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 | 29 | imu.Temperature, |
kylongmu | 0:58f9d4556df7 | 30 | imu.gyroscope_data[0], |
kylongmu | 0:58f9d4556df7 | 31 | imu.gyroscope_data[1], |
kylongmu | 0:58f9d4556df7 | 32 | imu.gyroscope_data[2], |
kylongmu | 0:58f9d4556df7 | 33 | imu.accelerometer_data[0], |
kylongmu | 0:58f9d4556df7 | 34 | imu.accelerometer_data[1], |
kylongmu | 1:7497c7952470 | 35 | imu.accelerometer_data[2], |
kylongmu | 1:7497c7952470 | 36 | imu.Magnetometer[0], |
kylongmu | 1:7497c7952470 | 37 | imu.Magnetometer[1], |
kylongmu | 1:7497c7952470 | 38 | imu.Magnetometer[2] |
kylongmu | 1:7497c7952470 | 39 | ); |
kylongmu | 0:58f9d4556df7 | 40 | //myled = 0; |
kylongmu | 0:58f9d4556df7 | 41 | //wait(0.5); |
kylongmu | 0:58f9d4556df7 | 42 | |
kylongmu | 0:58f9d4556df7 | 43 | } |
kylongmu | 0:58f9d4556df7 | 44 | } |
kylongmu | 0:58f9d4556df7 | 45 |