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 }

 

版权声明:本文为zhb123456原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/zhb123456/p/10627867.html