你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

【经验分享】STM32开源代码——MPU6050程序

[复制链接]
STMCU小助手 发布时间:2022-2-5 23:00
  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. }
复制代码


收藏 评论0 发布时间:2022-2-5 23:00

举报

0个回答

所属标签

相似技术帖

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版