找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1597|回复: 0
打印 上一主题 下一主题
收起左侧

HT32F52352DMP单片机读取MPU9250数据源程序

[复制链接]
跳转到指定楼层
楼主
ID:875316 发表于 2021-4-2 12:17 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
单片机源程序如下:
  1. #include "ht32.h"
  2. #include "ht32_board.h"
  3. #include "usart_int.h"
  4. #include <string.h>
  5. #include "usart.h"
  6. #include "./IMU901/ringbuffer.h"
  7. #include "./IMU901/imu901.h"
  8. #include "delay.h"
  9. #include "motor.h"
  10. #include "NRF24L01.h"
  11. #include "usart1.h"
  12. #include "ANO_DT.h"
  13. #include "pid.h"
  14. #include "mpu9250.h"
  15. #include "inv_mpu.h"
  16. #include "inv_mpu_dmp_motion_driver.h"
  17. #include "stdio.h"

  18. /*
  19.   1号电机 30解锁 31-40  占空比        372-480
  20.         3号电机 30解锁 31-40  占空比        372-480
  21.         2号电机 18解锁 19-34  占空比        228-408
  22.         4号电机 18解锁 21-39  占空比        252-468
  23.         
  24. */
  25. u8 tmp_buf[33]= "hello";
  26. u8  k;
  27.                 float mpu_pitch,mpu_roll,mpu_yaw;         //欧拉角
  28.         short aacx,aacy,aacz;        //加速度传感器原始数据
  29.         short gyrox,gyroy,gyroz;//陀螺仪原始数据
  30.         short temp;                        //温度

  31. #define   Key1       1<<8       //Key1=PA8
  32. #define   Key2       1<<13       //Key2=PC13
  33. #define   Key1_DIR   {  HT_GPIOA->INER |= HT_GPIOA->PUR |= Key1;}  //Key1块の矗ど筿
  34. #define   Key2_DIR   { HT_GPIOC->INER |= HT_GPIOC->PUR |= Key2;}  //Key2块の矗ど筿

  35. #define   Key1_0    !(HT_GPIOA->DINR & Key1)  //浪琩琌龄Key1=0
  36. #define   Key1_1     HT_GPIOA->DINR & Key1    //浪琩琌龄Key1=1

  37. #define   Key2_0    !(HT_GPIOC->DINR & Key2)   //浪琩琌龄Key2=0
  38. #define   Key2_1     HT_GPIOC->DINR & Key2    //浪琩琌龄Key2=1

  39. void Key_Init(void)
  40. {
  41.         HT_CKCU->AHBCCR |= 1<<16;
  42.         HT_CKCU->AHBCCR |= 1<<18;
  43.   Key1_DIR
  44.         Key2_DIR
  45. }        

  46. int main(void)
  47. {
  48.   static u8  t =23;

  49. //  u8  buff[20];        
  50.         
  51.         //NRF24L01_Init();
  52.   USART0_Configuration(256000);            //USART0的初始化,波特率为460800
  53. //        printf("OK\n");
  54. ////        ringbuffer_init(&usart0RxFifo, (uint8_t*)buff, 256);   //FIFO结构体的初始化
  55.   UART0_Configuration(115200);
  56. //  PWM_Init();
  57. //  Key_Init();
  58. ////  unlocked();

  59. ////        delay_ms(500);
  60. ////        delay_ms(500);
  61. ////        delay_ms(500);
  62. ////        delay_ms(500);
  63.    MPU_Init();                     //初始化MPU9250
  64. //                if(NRF24L01_Check()==0)  
  65. //        {

  66. //        }

  67.         if(mpu_dmp_init())
  68.         {

  69.         }
  70.         


  71. //  NRF24L01_TX_Mode();
  72.   while (1)
  73.   {

  74. //    Data_Send_To_PC();
  75.                 delay_ms(5);               

  76. //                Angle_PWM(attitude.pitch,attitude.roll,attitude.yaw);
  77.                 Angle_PWM(mpu_pitch,mpu_roll,mpu_yaw);

  78.     t++;
  79.                 if(t == 100)
  80.                 {
  81. //                          HT32F_DVB_LEDToggle(HT_LED1);
  82. //        HT32F_DVB_LEDToggle(HT_LED2);
  83.                         
  84.                 }
  85.           if(mpu_mpl_get_data(&mpu_pitch,&mpu_roll,&mpu_yaw)==0)
  86.     {
  87.                         
  88.       temp=MPU_Get_Temperature();        //得到温度值
  89.                         MPU_Get_Accelerometer(&aacx,&aacy,&aacz);        //得到加速度传感器数据
  90.                         MPU_Get_Gyroscope(&gyrox,&gyroy,&gyroz);        //得到陀螺仪数据
  91.                         printf("x:%f,y:%f,z:%f\n",mpu_pitch,mpu_roll,mpu_yaw);
  92.                                                                                          HT32F_DVB_LEDInit(HT_LED2);
  93.           HT32F_DVB_LEDOn(HT_LED2);
  94.                 }
  95.   }
  96. }
复制代码

所有代码51hei提供下载:
MPU9250DMP.7z (611.51 KB, 下载次数: 11)


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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