wdyggh 发表于 2014-5-24 13:55:40

求助_mma8652 加速度计 数据读取问题

在树莓派上想读取mma8652数据 没成功,各轴数据都显示255,参数设置也变过还是没行。
代码如下:                       
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/i2c-dev.h>
#include "wiringPi.h"
#include "wiringPiI2C.h"

int fd;
unsigned int X_M,X_L,Y_M,Y_L,Z_M,Z_L = 0;
int st =0;
long int axis(){
    //int wiringPiI2CReadReg8 (int fd, int reg);

        /* do{
                st = wiringPiI2CReadReg8(fd,0x00);
        }while( st & 0x07 == 0x00);   //reg00crc check
          */
        X_M = wiringPiI2CReadReg8 (fd, 0x01);                //OUT_X_MSB
        printf("X_M = %d \n", X_M);
        X_L = wiringPiI2CReadReg8 (fd, 0x02);                //OUT_X_LSB
        printf("X_L = %d \n", X_L);
        Y_M = wiringPiI2CReadReg8 (fd, 0x03);                //OUT_Y_MSB
        printf("Y_M = %d \n", Y_M);
        Y_L = wiringPiI2CReadReg8 (fd, 0x04);                //OUT_Y_LSB
        printf("Y_L = %d \n", Y_L);
        Z_M = wiringPiI2CReadReg8 (fd, 0x05);                //OUT_Z_MSB
        printf("Z_M = %d \n", Z_M);
        Z_L = wiringPiI2CReadReg8 (fd, 0x06);                //OUT_Z_LSB
        printf("Z_L = %d \n", Z_L);

}
int main(){

        if (wiringPiSetup () == -1) return 1;
        fd = wiringPiI2CSetup(0x1d);
        if (fd <0 )
        {
                printf(" Unable to initialise I2C: \n");
                return -1;
          }
        //int wiringPiI2CWriteReg8 (int fd, int reg, int data) ;
        wiringPiI2CWriteReg8 (fd,0x2a, (wiringPiI2CReadReg8(fd,0x2a)|0x01));        //CTRL1 activemode
        usleep(1);

        while(1){
                //usleep(1000);
                axis();
                usleep(500000);
        }
        return 0;
}

wdyggh 发表于 2014-5-24 22:11:34

求大神帮忙看看
页: [1]
查看完整版本: 求助_mma8652 加速度计 数据读取问题