- #include "led.h"# d' {" u3 c0 i$ d
- #include "delay.h"9 i! u ~ I! g0 o C3 b* Q# Q; x
- #include "key.h"
$ V! D. P1 ~) l) x& a' h n4 Z - #include "sys.h", m, n' |) F) _3 C: S
- #include "usart.h"9 M/ V! p3 a' G' S
- #include "mpu6050.h"3 a+ U: y, n- H& n4 g
- #include "inv_mpu.h"! h0 z s" h) [9 v
- #include "inv_mpu_dmp_motion_driver.h"7 F* |3 D0 k1 G; R" u* J% i7 I
- /************************************************
5 Q4 |; _1 q$ _" I/ d# L - ALIENTEK精英STM32开发板7 t6 ]9 l0 s' E
- 作者:唯恋殊雨
! I/ ~6 W2 I, `4 r8 Z6 A - CSDN博客:https://blog.csdn.net/tichimi3375& T& T& I8 ]& {) S# l
- SCL-PB6( M* Q6 E7 l/ w' P
- SDA-PB72 N6 C( e3 o, F, V% w, i1 L$ C1 s
- ************************************************/
- ]& {1 D9 b6 E8 G h - int main(void)
8 s8 a) {3 ]9 p S3 W& i. u9 } - {
2 i. ?" B: i& Q - u8 t=0,report=1; //默认开启上报7 f6 T$ ?/ b$ q* v! h) f; ^
- u8 key;% ?% E# A8 z8 S; h. z
- float pitch,roll,yaw; //欧拉角: W. T& V, @, ^: U% g) \- z1 y% q* j
- short aacx,aacy,aacz; //加速度传感器原始数据) Y) w' _; `5 F; n5 A+ g
- short gyrox,gyroy,gyroz; //陀螺仪原始数据
5 A; }7 f/ t7 K5 L - short temp; //温度
6 ^9 N/ H8 c; K' u3 `1 s. n { - SystemInit();
6 B( u9 @7 e; Z# v+ m - NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级, W q/ ]% [) `. _% @8 t2 b
- uart_init(115200); //串口初始化为500000% u/ ~! _7 a+ T7 @1 X* @
- delay_init(); //延时初始化5 y7 M$ q/ d. B3 V g
- LED_Init(); //初始化与LED连接的硬件接口. q/ c `7 a0 Z* Q* Z
- KEY_Init(); //初始化按键9 D: W; u- z! G% E/ e# W( W( _ b1 U
- MPU_Init(); //初始化MPU6050
) `" V8 C1 y, h N6 g0 C - while(mpu_dmp_init())& Y. t9 Q0 z6 c8 y
- {& b1 W7 j' T% F& _, y# Q) {* N7 }8 ]
- printf("\n\rMPU6050 Error\n\r");; g1 k `) c0 j, C! @5 Q. W n
- delay_ms(200);, t3 z; ~: z o0 m
- }
, w5 _3 {& D( g8 A! o- w. y - while(1)& c+ I% J5 W/ @/ p ?( H
- {
, k* K. S$ d* M! R/ Z - key=KEY_Scan(0);
0 o6 ?/ b1 U2 H8 L - if(key==KEY0_PRES)
- ?( ~6 }% J* |9 a# ~# g9 t5 P - {
# C# h/ H. E c- K - report=!report;
& p* ]# E- n/ F, p - if(report)printf("\n\rUPLOAD ON \n\r");
) K: }% [- |$ O/ n- V6 K7 e - else printf("\n\rUPLOAD OFF\n\r");9 ~2 j1 s3 e9 D0 U7 m2 Z0 f
- }9 j4 h) V6 x* b7 [/ `
- if(mpu_dmp_get_data(&pitch,&roll,&yaw)==0)& J# b" P+ O7 v6 H3 l
- {8 m0 x4 W* l, L7 b+ B; e# ]
- temp=MPU_Get_Temperature(); //得到温度值7 o3 c2 E+ S; D- |& @# I
- MPU_Get_Accelerometer(&aacx,&aacy,&aacz); //得到加速度传感器数据
# M% l9 y0 I9 y) e% M - MPU_Get_Gyroscope(&gyrox,&gyroy,&gyroz); //得到陀螺仪数据
! j0 `. `, J* C$ _& D, r - if(report)mpu6050_send_data(aacx,aacy,aacz,gyrox,gyroy,gyroz);//用自定义帧发送加速度和陀螺仪原始数据
( s4 `. i% J& g' ~* r9 q - if(report)usart1_report_imu(aacx,aacy,aacz,gyrox,gyroy,gyroz,(int)(roll*100),(int)(pitch*100),(int)(yaw*10));
8 Z' q8 i D/ M" k" I - if((t%10)==0)
+ z4 ], Q& I$ N: K. { - {
8 A5 _, R- {6 B" w - printf("\n\rtemp:%f\n\r",temp/100.0);8 J3 |7 t- C5 A1 n0 n" V) x
- printf("\n\rpitch:%f\n\r",pitch*10);
' a ~( l( I: @5 B/ y% L! c; e# L - printf("\n\rroll:%f\n\r",roll*10);: T+ E7 z$ @( B7 H9 r3 J
- printf("\n\ryaw:%f\n\r",yaw*10);
1 H) A! }3 ?% R _; d1 v* R - t=0;
0 _6 C% q* b. E. V% w- [1 j1 e' ? - }
# e/ Z! g, q1 h2 T" ]- B - }
. u; G: Z8 E# e# H x0 _ - t++;& e- F# l6 @# ~# R! e
- }" p5 r; E! v9 ~& B5 a" Q! ?
- }
复制代码 . U' g: q& ?. y
& q% `7 a, i2 D) ]9 J8 o9 i |