ADXL345读出的三轴加速度值得问题

我的目的很简单,就是通过ADXL345测量三轴加速度,然后计算俯仰角和横滚角。但是我发现,读出的DEVICE_ID是正确的,而三轴加速度值有问题。还有我测量范围调整为2g,ADXL345的XY轴保持水平,三轴寄存器的值在什么范围内是属于正常的,我还不太清楚。

我的ADXL345的初始化过程如下:
void
ADXL345_Init(void)
{
SPI0_Send(0x31,0x28);
//数据通信格式;设置为自检功能禁用,4线制SPI接口,低电平中断输出,13位全分辨率,输出数据右对齐,2g量程

SPI0_Send(0x1E,0x00);
//X轴误差补偿; (15.6mg/LSB)
SPI0_Send(0x1F,0x00); //Y轴误差补偿;
(15.6mg/LSB)
SPI0_Send(0x20,0x00); //Z轴误差补偿;
(15.6mg/LSB)

SPI0_Send(0x21,0x00); //敲击延时0:禁用;
(1.25ms/LSB)
SPI0_Send(0x22,0x00); //检测第一次敲击后的延时0:禁用;
(1.25ms/LSB)
SPI0_Send(0x23,0x00); //敲击窗口0:禁用;
(1.25ms/LSB)

SPI0_Send(0x24,0x01); //保存检测活动阀值;
(62.5mg/LSB)
SPI0_Send(0x25,0x01); //保存检测静止阀值;
(62.5mg/LSB)
SPI0_Send(0x26,0x2B); //检测活动时间阀值;
(1s/LSB)
SPI0_Send(0x27,0x00); //

SPI0_Send(0x28,0x09); //自由落体检测推荐阀值;
(62.5mg/LSB)
SPI0_Send(0x29,0xFF);
//自由落体检测时间阀值,设置为最大时间;(5ms/LSB)
SPI0_Send(0x2A,0x80);
//
SPI0_Send(0x2C,0x0A); //
SPI0_Send(0x2D,0x28);
//开启Link,测量功能;关闭自动休眠,休眠,唤醒功能
SPI0_Send(0x2E,0x00);
//所有均关闭
SPI0_Send(0x2F,0x00); //中断功能设定,不使用中断
SPI0_Send(0x38,0x9F);
//FIFO模式设定,Stream模式,触发连接INT1,31级样本缓冲

}
我没有使用中断。
读取三轴加速度值过程如下:
void
ADXL345_ReadXYZ(INT16S* gx, INT16S* gy, INT16S* gz)
{
INT16U i;
INT8U
gbuf[6];
INT16S tempH, tempL;

GPIO2DATA &= ~CS;

/*读取X轴加速度*/
SSP0DR = 0xB2;
while( (SSP0SR & 0x01) == 0 );
//等待TFE置位,即发送FIFO空
SSP0DR = 0x00;
while( (SSP0SR & 0x01) == 0
);
gbuf[0] = SSP0DR;

SSP0DR = 0xB3;
while( (SSP0SR & 0x01) == 0
);
SSP0DR = 0x00;
while( (SSP0SR & 0x01) == 0 );
gbuf[1] =
SSP0DR;

/*读取Y轴加速度*/
SSP0DR = 0xB4;
while( (SSP0SR & 0x01) == 0
); //等待TFE置位,即发送FIFO空
SSP0DR = 0x00;
while( (SSP0SR & 0x01) == 0
);
gbuf[2] = SSP0DR;

SSP0DR = 0xB5;
while( (SSP0SR & 0x01) == 0
);
SSP0DR = 0x00;
while( (SSP0SR & 0x01) == 0 );
gbuf[3] =
SSP0DR;

/*读取Z轴加速度*/
SSP0DR = 0xB6;
while( (SSP0SR & 0x01) == 0
); //等待TFE置位,即发送FIFO空
SSP0DR = 0x00;
while( (SSP0SR & 0x01) == 0
);
gbuf[4] = SSP0DR;

SSP0DR = 0xB7;
while( (SSP0SR & 0x01) == 0
);
SSP0DR = 0x00;
while( (SSP0SR & 0x01) == 0 );
gbuf[5] =
SSP0DR;

for(i=500;i>0;i--);
GPIO2DATA |= CS;

tempL =
(INT16S)gbuf[0];
tempH = (INT16S)(gbuf[1]&&0x1F);
*gx =
(((tempH<<8)&0xFF00)|(tempL&0x00FF));
tempL =
(INT16S)gbuf[2];
tempH = (INT16S)(gbuf[3]&&0x1F);
*gy =
(((tempH<<8)&0xFF00)|(tempL&0x00FF));
tempL =
(INT16S)gbuf[4];
tempH = (INT16S)(gbuf[5]&&0x1F);
*gz =
(((tempH<<8)&0xFF00)|(tempL&0x00FF));

}
然后通过串口输出gx gy gz
值如下:
gx gy gz
01 FF 01 E2 00 56
01 FF 01 E2 00 58
01 FF 01 E2 00
58
01 FF 01 E1 00 58
01 FF 01 E1 00 58
01 FF 01 E2 00 59
01 FF
01 E1 00 58
01 FF 01 DF 00 57
01 FF 01 E0 00 57
01 FF 01 E1 00
57
01 FF 01 E1 00 58
01 FF 01 E0 00 57
01 FF 01 E1 00 57
01 FF 01
DF 00 58
01 FF 01 E0 00 58
01 FF 01 E2 00
57
我发现X轴的加速度一直不变化,求为什么?
还有我不知道读出来的对不对?

Parents
No Data
Reply Children
No Data