標(biāo)題:
STM32F0驅(qū)動(dòng)adxl345,串口打印數(shù)據(jù) 源程序
[打印本頁(yè)]
作者:
李花生51
時(shí)間:
2020-5-27 02:17
標(biāo)題:
STM32F0驅(qū)動(dòng)adxl345,串口打印數(shù)據(jù) 源程序
在這論壇學(xué)到很多知識(shí),為了回報(bào),貢獻(xiàn)出我調(diào)試好的代碼,STM32F0 iic協(xié)議驅(qū)動(dòng)adxl345,串口打印數(shù)據(jù)
單片機(jī)源程序如下:
#include "include.h"
#include "iic.h"
#include "adxl345.h"
#include "stm32f0xx.h"
#include "stm32f0_discovery.h"
#include "usart.h"
#include "oled.h"
int main(void)
{
short x,y,z;
int angx,angy,angz;
delay_init();
USART_Configuration();
I2C_INIT();
while(ADXL345_Init())
{
USART1_SendString("傳感器初始失敗\r\n");
}
USART1_SendString("傳感器初始化成功\r\n");
USART1_SendString("正在校準(zhǔn)……\r\n");
ADXL345_AUTO_Adjust(&x, &y, &z);//自動(dòng)校準(zhǔn)
while (1)
{
ADXL345_RD_XYZ(&x, &y,&z);
angx=ADXL345_Get_Angle(x,y,z,1);
angy=ADXL345_Get_Angle(x,y,z,2);
angz=ADXL345_Get_Angle(x,y,z,0);
USART1_SendString("\r\nAngx=");
USART1_SendNum(angx);
USART1_SendString("\tAngy=");
USART1_SendNum(angy);
USART1_SendString("\tAngz=");
USART1_SendNum(angz);
ADXL345_RD_XYZ(&x, &y,&z);
USART1_SendString("\tGx=");
USART1_SendNum2(-x*3.9);
USART1_SendString("\tGy=");
USART1_SendNum2(-y*3.9);
USART1_SendString("\tGz=");
USART1_SendNum2(z*3.9);
delay_ms(100);
}
}
復(fù)制代碼
所有資料51hei提供下載:
stm32f0 adxl345.7z
(192.71 KB, 下載次數(shù): 70)
2020-5-27 14:27 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1