本帖最后由 jungle1989 于 2017-6-16 11:03 编辑
使用ADXL345,得到的数据不正确,2个轴的数据不对:请各位大神帮忙 分析下,先谢谢啦!
流程:上电检测ID,配置,成功后,传感器水平放置,校准,主函数一直读取。
void ADXL345_Adjust(void)
{
short tx,ty,tz;
short offx = 0,offy = 0,offz = 0;
ADXL345_WriteReg(POWER_CTL,0x00);
delay_ms(100);
ADXL345_WriteReg(BW_RATE,0x0A);
ADXL345_WriteReg(POWER_CTL,0x28);
ADXL345_WriteReg(INT_ENABLE,0x00);//ADXL345_WriteReg(INT_ENABLE,0x10);
// ADXL345_WriteReg(INT_MAP,0x00);
//
// ADXL345_WriteReg(THRESH_ACK,0x0A);
// ADXL345_WriteReg(ACT_INACT_CTL,0xF0);
ADXL345_WriteReg(OFSX,0x00);
ADXL345_WriteReg(OFSY,0x00);
ADXL345_WriteReg(OFSZ,0x00);
delay_ms(12);
ADXL345_Read_Average(&tx,&ty,&tz,10);
offx = tx;
offy = ty;
offz = tz;
tx = -offx / 4;
ty = -offy / 4;
tx = -(offz - 256) / 4;
ADXL345_WriteReg(OFSX,tx);
ADXL345_WriteReg(OFSY,ty);
ADXL345_WriteReg(OFSZ,tz);
}
uint8_t ADXL345_Mode_Config(void)
{
// uint8_t temp;
if(ADXL345_ReadID())
{
ADXL345_WriteReg(DATA_FORMAT,0x2B);
ADXL345_WriteReg(BW_RATE,0x0A);
ADXL345_WriteReg(POWER_CTL,0x28);
ADXL345_WriteReg(INT_ENABLE,0x00);//ADXL345_WriteReg(INT_ENABLE,0x10);
// ADXL345_WriteReg(INT_MAP,0x00);
//
// ADXL345_WriteReg(THRESH_ACK,0x0A);
// ADXL345_WriteReg(ACT_INACT_CTL,0xF0);
ADXL345_WriteReg(OFSX,0x00);
ADXL345_WriteReg(OFSY,0x00);
ADXL345_WriteReg(OFSZ,0x00);
return 1;
}
else
{
return 0;
}
}
file:///C:UsersUSERAppDataRoamingTencentUsers963438617QQWinTempRichOleX{RHZP)9OC)PWS~9NO_364I.png
一周热门 更多>