1 #include "led.h" 2 #include "delay.h" 3 #include "key.h" 4 #include "sys.h" 5 #include "usart.h" 6 #include "mpu6050.h" 7 #include "inv_mpu.h" 8 #include "inv_mpu_dmp_motion_driver.h" 9 /************************************************ 10 ALIENTEK精英STM32開發板 11 作者:唯戀殊雨 12 CSDN博客:https://blog.csdn.net/tichimi3375 13 SCL-PB6 14 SDA-PB7 15 ************************************************/ 16 int main(void) 17 { 18 u8 t=0,report=1; //默認開啟上報 19 u8 key; 20 float pitch,roll,yaw; //歐拉角 21 short aacx,aacy,aacz; //加速度傳感器原始數據 22 short gyrox,gyroy,gyroz; //陀螺儀原始數據 23 short temp; //溫度 24 SystemInit(); 25 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //設置NVIC中斷分組2:2位搶占優先級,2位響應優先級 26 uart_init(115200); //串口初始化為500000 27 delay_init(); //延時初始化 28 LED_Init(); //初始化與LED連接的硬件接口 29 KEY_Init(); //初始化按鍵 30 MPU_Init(); //初始化MPU6050 31 while(mpu_dmp_init()) 32 { 33 printf("\n\rMPU6050 Error\n\r"); 34 delay_ms(200); 35 } 36 while(1) 37 { 38 key=KEY_Scan(0); 39 if(key==KEY0_PRES) 40 { 41 report=!report; 42 if(report)printf("\n\rUPLOAD ON \n\r"); 43 else printf("\n\rUPLOAD OFF\n\r"); 44 } 45 if(mpu_dmp_get_data(&pitch,&roll,&yaw)==0) 46 { 47 temp=MPU_Get_Temperature(); //得到溫度值 48 MPU_Get_Accelerometer(&aacx,&aacy,&aacz); //得到加速度傳感器數據 49 MPU_Get_Gyroscope(&gyrox,&gyroy,&gyroz); //得到陀螺儀數據 50 if(report)mpu6050_send_data(aacx,aacy,aacz,gyrox,gyroy,gyroz);//用自定義幀發送加速度和陀螺儀原始數據 51 if(report)usart1_report_imu(aacx,aacy,aacz,gyrox,gyroy,gyroz,(int)(roll*100),(int)(pitch*100),(int)(yaw*10)); 52 if((t%10)==0) 53 { 54 printf("\n\rtemp:%f\n\r",temp/100.0); 55 printf("\n\rpitch:%f\n\r",pitch*10); 56 printf("\n\rroll:%f\n\r",roll*10); 57 printf("\n\ryaw:%f\n\r",yaw*10); 58 t=0; 59 } 60 } 61 t++; 62 } 63 }