终于用811读取出ADXL345的数据了,庆祝下,源码参考了网上的,呵呵
static unsigned char DataX1, DataX2, DataY1, DataY2, DataZ1, DataZ2; //xyz的高低字节
static unsigned int DataX, DataY, DataZ; //X Y Z的数据
static unsigned char Interrupt;
void display_adxl345_data(unsigned int x)
{
// unsigned int x;
unsigned long y;
if((x&0xf000)==0xf000) //是负数
{
uartPutc('-') ; //显示符号位
x = ~x; //按位取反
}
x &= 0xffff;
y=x*39;
uartPutdouble(y);
}
void ADXL345_Test(void)
{
Interrupt=(unsigned char)read_adxl345_reg(0x30); // get interrupt status
if((Interrupt&0x80)==0x80) // Data Rdy interrupt, get X Y Z data for shake and rotate function
{
DataX1=(unsigned char)read_adxl345_reg(0x32);
DataX2=(unsigned char)read_adxl345_reg(0x33);
DataY1=(unsigned char)read_adxl345_reg(0x34);
DataY2=(unsigned char)read_adxl345_reg(0x35);
DataZ1=(unsigned char)read_adxl345_reg(0x36);
DataZ2=(unsigned char)read_adxl345_reg(0x37);
DataX=DataX2;
DataX=(DataX<<8) | DataX1;
DataY=DataY2;
DataY=(DataY<<8) | DataY1;
DataZ=DataZ2;
DataZ=(DataZ<<8) | DataZ1;
uartPuts("X=:"); display_adxl345_data(DataX);
uartPuts(" mg Y=:"); display_adxl345_data(DataY);
uartPuts(" mg Z=:"); display_adxl345_data(DataZ);
uartPuts(" mg \r\n");
}
}
晃动小板子,就会发现数据有变化了,
静止情况下,读取的数据和下图对应,那么板子基本上就调好了。