OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 5473|回复: 2

【正点原子】六轴传感器模块ATK-MPU6050资料这个源码好像不能用啊

[复制链接]

0

主题

1

帖子

0

精华

新手入门

积分
1
金钱
1
注册时间
2020-8-14
在线时间
0 小时
发表于 2020-8-14 21:27:56 | 显示全部楼层 |阅读模式
1金钱
本帖最后由 这是真的菜鸡 于 2020-8-14 21:29 编辑
  1. #include "led.h"
  2. #include "delay.h"
  3. #include "sys.h"
  4. #include "key.h"
  5. #include "usart.h"
  6. #include "mpu6050.h"
  7. #include "usmart.h"   
  8. #include "inv_mpu.h"
  9. #include "inv_mpu_dmp_motion_driver.h"

  10. /************************************************
  11. ALIENTEK NANO STM32¿ª·¢°å À©Õ¹ÊµÑé6
  12. ATK-MPU6050ÁùÖá´«¸ÐÆ÷ʵÑé1 ´®¿ÚÖúÊÖ´òÓ¡-HAL¿â°æ±¾
  13. ¼¼ÊõÖ§³Ö£ºwww.openedv.com
  14. ÌÔ±¦µêÆÌ£ºhttp://eboard.taobao.com
  15. ¹Ø×¢Î¢ÐŹ«ÖÚÆ½Ì¨Î¢Ðźţº"ÕýµãÔ­×Ó"£¬Ãâ·Ñ»ñÈ¡STM32×ÊÁÏ¡£
  16. ¹ãÖÝÊÐÐÇÒíµç×ӿƼ¼ÓÐÏÞ¹«Ë¾  
  17. ×÷ÕߣºÕýµãÔ­×Ó @ALIENTEK
  18. ************************************************/

  19. int main(void)
  20. {
  21.   
  22.     u8 t=0;
  23.         u8 key=0;
  24.         u8 GetData=1;
  25.         float pitch,roll,yaw;                 //Å·À­½Ç
  26.         short aacx,aacy,aacz;                //¼ÓËÙ¶È´«¸ÐÆ÷ԭʼÊý¾Ý
  27.         short gyrox,gyroy,gyroz;        //ÍÓÂÝÒÇԭʼÊý¾Ý
  28.         short temp;                                        //ζÈ
  29.        
  30.     HAL_Init();                            //³õʼ»¯HAL¿â   
  31.     Stm32_Clock_Init(RCC_PLL_MUL9); //ÉèÖÃʱÖÓ,72M
  32.     delay_init(72);                 //³õʼ»¯ÑÓʱº¯Êý
  33.         uart_init(115200);                                //³õʼ»¯´®¿Ú115200
  34.     LED_Init();                     //³õʼ»¯LED
  35.         KEY_Init();                                                //³õʼ»¯°´¼ü
  36.         usmart_init(72);                //USMART³õʼ»¯
  37.         printf("ALIENTEK NANO STM32\r\n");
  38.     printf("MPU6050 TEST\r\n");
  39.     while(mpu_dmp_init())//MPU DMP³õʼ»¯
  40.         {
  41.             printf("MPU6050 Error!!!\r\n");
  42.                 delay_ms(500);
  43.                 LED0=!LED0;//DS0ÉÁ˸
  44.                
  45.         }
  46.     printf("MPU6050 OK\r\n");
  47.         while(1)
  48.         {
  49.                
  50.                 key=KEY_Scan(0);
  51.                 if(key==WKUP_PRES)
  52.                 {
  53.                         GetData=!GetData;
  54.                         if(GetData)printf("GETDATA ON\r\n");
  55.                         else printf("GETDATA OFF\r\n");
  56.                 }
  57.                 if(mpu_dmp_get_data(&pitch,&roll,&yaw)==0)
  58.                 {
  59.                         temp=MPU_Get_Temperature();        //µÃµ½Î¶ÈÖµ
  60.                         MPU_Get_Accelerometer(&aacx,&aacy,&aacz);        //µÃµ½¼ÓËÙ¶È´«¸ÐÆ÷Êý¾Ý
  61.                         MPU_Get_Gyroscope(&gyrox,&gyroy,&gyroz);        //µÃµ½ÍÓÂÝÒÇÊý¾Ý
  62.                         if(GetData)//GetData=0ʱ ÓÃÓÚUSMARTµ÷ÊÔMPU6050¼Ä´æÆ÷
  63.                         {
  64.                                
  65.                                 if((t%10)==0)
  66.                                 {                
  67.                                         //tempÖµ
  68.                                         if(temp<0)
  69.                                         {
  70.                                                 temp=-temp;                //×&#170;&#206;&#170;&#213;&#253;&#202;&#253;
  71.                                                 printf(" Temp:  -%d.%dC\r\n",temp/100,temp%10);
  72.                                         }else
  73.                                                 printf(" Temp:  %d.%dC\r\n",temp/100,temp%10);
  74.                                                
  75.                                         //pitch&#214;&#181;
  76.                                         temp=pitch*10;                       
  77.                                         if(temp<0)
  78.                                         {
  79.                                                 temp=-temp;                //×&#170;&#206;&#170;&#213;&#253;&#202;&#253;
  80.                                                 printf(" Pitch: -%d.%dC\r\n",temp/10,temp%10);
  81.                                         }else
  82.                                                 printf(" Pitch:  %d.%dC\r\n",temp/10,temp%10);
  83.                                        
  84.                                         //roll&#214;&#181;
  85.                                         temp=roll*10;               
  86.                                         if(temp<0)
  87.                                         {
  88.                                                 temp=-temp;                //×&#170;&#206;&#170;&#213;&#253;&#202;&#253;
  89.                                                 printf(" Roll:  -%d.%dC\r\n",temp/10,temp%10);
  90.                                         }else
  91.                                                 printf(" Roll:  %d.%dC\r\n",temp/10,temp%10);
  92.                                        
  93.                                         //yaw&#214;&#181;
  94.                                         temp=yaw*10;
  95.                                         if(temp<0)
  96.                                         {
  97.                                                 temp=-temp;                //×&#170;&#206;&#170;&#213;&#253;&#202;&#253;
  98.                                                 printf(" Yaw:  -%d.%dC\r\n",temp/10,temp%10);
  99.                                         }else
  100.                                                 printf(" Yaw:   %d.%dC\r\n",temp/10,temp%10);
  101.                                
  102.                                         printf("\r\n");
  103.                                         t=0;
  104.                                         LED0=!LED0;//LED&#201;&#193;&#203;&#184;
  105.                                 }

  106.                         }
  107.                        
  108.                 }
  109.                 t++;                

  110.         }
  111. }

复制代码



正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

0

主题

1

帖子

0

精华

新手入门

积分
1
金钱
1
注册时间
2020-8-14
在线时间
0 小时
 楼主| 发表于 2020-8-14 21:29:24 | 显示全部楼层
回复

使用道具 举报

0

主题

6

帖子

0

精华

初级会员

Rank: 2

积分
70
金钱
70
注册时间
2020-9-25
在线时间
16 小时
发表于 2020-12-1 14:08:18 | 显示全部楼层
我开探索者的MPU6050例程还报错的
回复

使用道具 举报

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

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-23 11:57

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

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