找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2338|回復: 0
收起左側

HT32F52352DMP單片機讀取MPU9250數(shù)據(jù)源程序

[復制鏈接]
ID:875316 發(fā)表于 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;        //加速度傳感器原始數(shù)據(jù)
  29.         short gyrox,gyroy,gyroz;//陀螺儀原始數(shù)據(jù)
  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);        //得到加速度傳感器數(shù)據(jù)
  90.                         MPU_Get_Gyroscope(&gyrox,&gyroy,&gyroz);        //得到陀螺儀數(shù)據(jù)
  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, 下載次數(shù): 12)


評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表