找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1810|回复: 0
收起左侧

STM32F103C8T6的姿态传感器源程序

[复制链接]
ID:618513 发表于 2019-10-13 17:58 | 显示全部楼层 |阅读模式
  1. #include "delay.h"
  2. #include "sys.h"
  3. #include "usart.h"

  4. #include "serial.h"
  5. #include "led.h"
  6. #include "motor.h"
  7. #include "cap.h"
  8. #include "timer.h"

  9. #include "mpu6050.h"
  10. #include "mpuiic.h"
  11. #include "inv_mpu.h"
  12. #include "inv_mpu_dmp_motion_driver.h"

  13. extern u16 ADV[128];
  14. extern u8 CCD_Zhongzhi;
  15. extern u8 CCD_Yuzhi;

  16. extern u16  TIM2CH1_CAPTURE_STA;                                                   
  17. extern u16        TIM2CH1_CAPTURE_VAL;


  18. extern u16  TIM1CH1_CAPTURE_STA;                                                   
  19. extern u16        TIM1CH1_CAPTURE_VAL;

  20. u8 count_flag=0;


  21. int main(void)
  22. {
  23.         u8 num;
  24.         float pitch,roll,yaw;                 //欧拉角
  25.         short aacx,aacy,aacz;                //加速度传感器原始数据
  26.         short gyrox,gyroy,gyroz;        //陀螺仪原始数据
  27.         short temp;                                        //温度       
  28.        
  29.         SystemInit();        //初始化RCC 设置系统主频为72MHZ
  30.         delay_init();             //延时初始化
  31.         uart_init(115200);
  32.         MPU_Init();                                        //初始化MPU6050  
  33.         mpu_dmp_init();
  34.         while(mpu_dmp_init())//初始化dmp,初始化不过报错
  35.         {
  36.                 printf("%d",mpu_dmp_init());
  37.         }  
  38.        
  39.         while(1)
  40.         {
  41.                         if(mpu_dmp_get_data(&pitch,&roll,&yaw)==0)
  42.                         {
  43.                                 temp=MPU_Get_Temperature();        //得到温度值
  44.                                 MPU_Get_Accelerometer(&aacx,&aacy,&aacz);        //得到加速度传感器数据
  45.                                 MPU_Get_Gyroscope(&gyrox,&gyroy,&gyroz);        //得到陀螺仪数据

  46.                         }
  47.                 num++;
  48.                 if(num == 50) //每500msLED0闪烁一次
  49.                 {
  50.                         num = 0;
  51. //                        printf("%d %d %d\r\n",gyrox,gyroy,gyroz);
  52. //                        printf("%d %d %d\r\n",aacx,aacy,aacz);
  53.                         printf("x:%3.3f y:%3.3f z:%3.3f\r\n",pitch,roll,yaw);
  54. //                        printf("temp:%d\r\n",temp);
  55.                         printf("\r\n");
  56.                 }
  57.                 delay_ms(10);
  58.         }
  59. }
复制代码


串口.7z

245.13 KB, 下载次数: 12, 下载积分: 黑币 -5

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表