zoukankan      html  css  js  c++  java
  • STM32开源代码——MPU6050程序

     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("
    
    MPU6050 Error
    
    ");
    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("
    
    UPLOAD ON 
    
    ");
    43             else printf("
    
    UPLOAD OFF
    
    ");
    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("
    
    temp:%f
    
    ",temp/100.0);
    55                 printf("
    
    pitch:%f
    
    ",pitch*10);
    56                 printf("
    
    roll:%f
    
    ",roll*10);
    57                 printf("
    
    yaw:%f
    
    ",yaw*10);                
    58                 t=0;
    59             }
    60         }
    61         t++; 
    62     }     
    63 }
  • 相关阅读:
    参数是指针,传递指针变量,最后函数总分配的内存丢了
    GoDaddy域名注册/空间购买优惠码
    Godaddy主机新建网站说明
    Godaddy主机购买图解教程
    Godaddy 如何添加独立IP到主机账户
    GoDaddy域名注册图解
    Godaddy windows主机添加域名,删除域名,添加子域名 操作说明
    ASP.net与PHP两大网站开发架构优势对比
    Godaddy如何导入导出MSSQL数据库
    什么是DSN文件
  • 原文地址:https://www.cnblogs.com/zhb123456/p/10627867.html
Copyright © 2011-2022 走看看