[原创] LM3S811读取ADXL345

eedesign   2012-1-6 14:13 楼主

终于用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");

                           }

}       

 

晃动小板子,就会发现数据有变化了,

静止情况下,读取的数据和下图对应,那么板子基本上就调好了。

 

回复评论 (2)

这个adxl345不是通过AD采样来获得相应数据。
最关键的一个函数read_adxl345_reg没给出来。开源要开到底啊!
点赞  2012-1-6 19:05

回复 沙发 鸵鸟蝈蝈 的帖子

非常赞同楼上的观点,开源不够彻底。但还是非常感谢楼主的分享。
点赞  2012-5-3 14:23
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复