找回密码
 注册

QQ登录

只需一步,快速开始

搜索

STM32F0驱动adxl345,串口打印数据 源程序

[复制链接]
路漫漫 发表于 2020-5-29 02:08:52 | 显示全部楼层 |阅读模式
STM32F0 iic协议驱动adxl345,串口打印数据 完整源码stm32f0 adxl345.7z (192.71 KB, 售价: 1 E币)

部分源码
  1. #include "include.h"
  2. #include "iic.h"
  3. #include "adxl345.h"
  4. #include "stm32f0xx.h"
  5. #include "stm32f0_discovery.h"
  6. #include "usart.h"
  7. #include "oled.h"

  8. int main(void)
  9. {
  10.         short x,y,z;              
  11.         int angx,angy,angz;              
  12.   delay_init();
  13.         USART_Configuration();
  14.         I2C_INIT();
  15.                 while(ADXL345_Init())
  16.         {
  17.                 USART1_SendString("传感器初始失败\r\n");
  18.         }
  19.       
  20.                 USART1_SendString("传感器初始化成功\r\n");
  21.                 USART1_SendString("正在校准……\r\n");
  22.                         ADXL345_AUTO_Adjust(&x, &y, &z);//自动校准
  23.   while (1)
  24.   {
  25.                         ADXL345_RD_XYZ(&x, &y,&z);
  26.                         angx=ADXL345_Get_Angle(x,y,z,1);   
  27.                         angy=ADXL345_Get_Angle(x,y,z,2);   
  28.                         angz=ADXL345_Get_Angle(x,y,z,0);
  29.                         USART1_SendString("\r\nAngx=");
  30.                         USART1_SendNum(angx);
  31.                         USART1_SendString("\tAngy=");
  32.                         USART1_SendNum(angy);
  33.                         USART1_SendString("\tAngz=");
  34.                         USART1_SendNum(angz);
  35.                         ADXL345_RD_XYZ(&x, &y,&z);
  36.                         USART1_SendString("\tGx=");
  37.                         USART1_SendNum2(-x*3.9);
  38.                         USART1_SendString("\tGy=");
  39.                         USART1_SendNum2(-y*3.9);
  40.                         USART1_SendString("\tGz=");
  41.                         USART1_SendNum2(z*3.9);               
  42.                
  43.                 delay_ms(100);
  44.                
  45.   }
  46. }
复制代码

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

本版积分规则

QQ|手机版|小黑屋|ELEOK |网站地图

GMT+8, 2024-4-18 17:08

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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