- #include "led.h"
+ E) A( Q8 [0 v4 t - #include "delay.h"
% `% |, M% {, L: i; F - #include "key.h"1 d% ^* k( m! F1 Y5 o. a
- #include "sys.h" G, l( N$ s) v r
- #include "usart.h". c& o0 G- E; e, ?$ x9 l. n
- #include "mpu6050.h"& B$ ]( v8 L/ [' I# p/ ^$ g K
- #include "inv_mpu.h". M; F6 {2 V, N T* S: t
- #include "inv_mpu_dmp_motion_driver.h": z7 q7 U, H) N) o8 Z+ m+ V& D5 ?+ r1 _
- /************************************************
# v& k Q; [; C! U3 l - ALIENTEK精英STM32开发板9 t" z# L# n8 H- k5 T$ {
- 作者:唯恋殊雨) `/ X8 f8 y1 N! S; h% {
- CSDN博客:https://blog.csdn.net/tichimi3375* {: n% X9 e+ R, r8 M
- SCL-PB6. d$ S* U# E, e$ @% l' E/ P
- SDA-PB7
% L4 t" g; v/ D5 o4 {8 f - ************************************************/
+ R$ B+ Q# I* W" ]5 Y/ f" d - int main(void)
* w9 P0 V& {+ y; D4 G - {7 d" `4 V1 U; W7 n9 `9 c' _) ~0 h ^
- u8 t=0,report=1; //默认开启上报
- o3 v8 N2 D8 d0 a2 @0 R - u8 key;& Y. X& V* R; ?7 I u3 h
- float pitch,roll,yaw; //欧拉角
( f! ~* W+ T$ G3 b8 u( I - short aacx,aacy,aacz; //加速度传感器原始数据: L% C0 T. i R$ _. I5 x, o
- short gyrox,gyroy,gyroz; //陀螺仪原始数据
i. L3 {. y1 r1 o - short temp; //温度3 r8 ^( P2 U, b6 n; e
- SystemInit();
6 ]& E/ [; U) y) \; P4 @/ z# j - NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
8 J8 _/ |7 U, @5 h/ x - uart_init(115200); //串口初始化为500000
- |+ D0 G( E* J4 U4 q- V - delay_init(); //延时初始化
7 c# ]7 Y% `: D. [ - LED_Init(); //初始化与LED连接的硬件接口; @# C7 I+ C% M& n, O
- KEY_Init(); //初始化按键6 ~" }4 l# S& E1 E' g/ [: ?0 B, k
- MPU_Init(); //初始化MPU6050: p- U* c# x. h( l9 K. v1 u
- while(mpu_dmp_init()): B: ^8 v: K3 c; {3 ]) N! M; T
- {
4 s) i4 c! j( O# k( L4 M [ - printf("\n\rMPU6050 Error\n\r");, [6 M0 ~2 g* R) p7 n6 w
- delay_ms(200);
1 s8 @1 p& W, j5 @ - }4 @2 k4 S/ n2 M$ t3 M- e2 C# l
- while(1)& q, v6 n J. Q7 o& G# u6 |
- {
- I1 }3 t1 i, R5 t _% F7 D - key=KEY_Scan(0);- s% [% \7 j$ m& V( X% l: n, S
- if(key==KEY0_PRES)8 ?, i" ?1 D% ?
- {
- t0 q+ J N/ ]5 S - report=!report;/ q2 d& n/ C9 b( `: Y
- if(report)printf("\n\rUPLOAD ON \n\r");
6 ^+ }+ a. p F9 Q0 V8 W, K, F - else printf("\n\rUPLOAD OFF\n\r");
9 c$ B0 w# g7 r" D" o - }
# V) i( N7 N' i; Y - if(mpu_dmp_get_data(&pitch,&roll,&yaw)==0)6 J; C$ s0 ~5 y
- {
, S* \# S+ S3 s - temp=MPU_Get_Temperature(); //得到温度值
4 T& D2 H7 v! A. y4 k# v1 | - MPU_Get_Accelerometer(&aacx,&aacy,&aacz); //得到加速度传感器数据; @, R& _" n' b) A+ M$ A
- MPU_Get_Gyroscope(&gyrox,&gyroy,&gyroz); //得到陀螺仪数据5 X1 @0 N2 o" N( {: S4 z9 _" R
- if(report)mpu6050_send_data(aacx,aacy,aacz,gyrox,gyroy,gyroz);//用自定义帧发送加速度和陀螺仪原始数据
1 Q2 T; m1 p, g - if(report)usart1_report_imu(aacx,aacy,aacz,gyrox,gyroy,gyroz,(int)(roll*100),(int)(pitch*100),(int)(yaw*10));
- X( t' T- W; ~' @' T: n3 i - if((t%10)==0)
, ~2 q/ o* j8 m4 K, c - {
" j, Z3 w! H' X+ @- @3 `8 t - printf("\n\rtemp:%f\n\r",temp/100.0);$ _% j) h a+ y( t( \: i
- printf("\n\rpitch:%f\n\r",pitch*10);
4 w6 f! y% V6 N3 c" t# s2 I2 q - printf("\n\rroll:%f\n\r",roll*10);( P2 X$ d3 t, m& E
- printf("\n\ryaw:%f\n\r",yaw*10);- q5 N6 O. P' L
- t=0;
# u/ k1 V2 y$ j* Q9 k1 Y - }
$ i+ J: z& P& m6 N; L' t - }
* g: e+ M" Z C% g# Q: X# C - t++;
% Z5 a6 [ R5 G - }
% \- ]3 O1 c4 J( P; ~# [ - }
复制代码 6 u! Y5 M: I: U0 g+ K
, k2 F! A& E$ l, L' u+ C# e% c! [1 _ |