- #include "led.h"
- #include "delay.h"
- #include "key.h"
- #include "sys.h"
- #include "usart.h"
- #include "mpu6050.h"
- #include "inv_mpu.h"
- #include "inv_mpu_dmp_motion_driver.h"
- /************************************************
- ALIENTEK精英STM32开发板
- 作者:唯恋殊雨
- CSDN博客:https://blog.csdn.net/tichimi3375
- SCL-PB6
- SDA-PB7
- ************************************************/
- int main(void)
- {
- u8 t=0,report=1; //默认开启上报
- u8 key;
- float pitch,roll,yaw; //欧拉角
- short aacx,aacy,aacz; //加速度传感器原始数据
- short gyrox,gyroy,gyroz; //陀螺仪原始数据
- short temp; //温度
- SystemInit();
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
- uart_init(115200); //串口初始化为500000
- delay_init(); //延时初始化
- LED_Init(); //初始化与LED连接的硬件接口
- KEY_Init(); //初始化按键
- MPU_Init(); //初始化MPU6050
- while(mpu_dmp_init())
- {
- printf("\n\rMPU6050 Error\n\r");
- delay_ms(200);
- }
- while(1)
- {
- key=KEY_Scan(0);
- if(key==KEY0_PRES)
- {
- report=!report;
- if(report)printf("\n\rUPLOAD ON \n\r");
- else printf("\n\rUPLOAD OFF\n\r");
- }
- if(mpu_dmp_get_data(&pitch,&roll,&yaw)==0)
- {
- temp=MPU_Get_Temperature(); //得到温度值
- MPU_Get_Accelerometer(&aacx,&aacy,&aacz); //得到加速度传感器数据
- MPU_Get_Gyroscope(&gyrox,&gyroy,&gyroz); //得到陀螺仪数据
- if(report)mpu6050_send_data(aacx,aacy,aacz,gyrox,gyroy,gyroz);//用自定义帧发送加速度和陀螺仪原始数据
- if(report)usart1_report_imu(aacx,aacy,aacz,gyrox,gyroy,gyroz,(int)(roll*100),(int)(pitch*100),(int)(yaw*10));
- if((t%10)==0)
- {
- printf("\n\rtemp:%f\n\r",temp/100.0);
- printf("\n\rpitch:%f\n\r",pitch*10);
- printf("\n\rroll:%f\n\r",roll*10);
- printf("\n\ryaw:%f\n\r",yaw*10);
- t=0;
- }
- }
- t++;
- }
- }
复制代码
|