#define MPU_ADDR 0X68
typedef struct
{
unsigned char reg;
unsigned char val;
}mpu6050cfg_t;
mpu6050cfg_t mpu6050[]={
{MPU_PWR_MGMT1_REG,0X80},//复位MPU6050
{MPU_PWR_MGMT1_REG,0x08},//电源管理寄存器1
{MPU_PWR_MGMT2_REG,0xC8},//电源管理寄存器2
{MPU_SAMPLE_RATE_REG,0x07},//采样频率分频器
{MPU_CFG_REG,0x04},//配置寄存器
{MPU_ACCEL_CFG_REG,0xFC},//加速度计配置寄存器
{MPU_MOTION_DET_REG,0x03},//运动检测阀值设置寄存器
{MPU_CHECK_TIME_REG,0x01},//检测时间
{MPU_INT_EN_REG,0x40}//中断使能寄存器
};
void mpu6050_init(int fd_i2c)
{
int i,iRet;
unsigned char rdBuff;
iRet = aod_i2c_write(fd_i2c, MPU_ADDR, mpu6050[0].reg, &mpu6050[0].val, 1);//复位MPU6050
sleep(1);
for(i=1; i < sizeof(mpu6050 )/sizeof(mpu6050cfg_t); i++)
{
aod_i2c_write(fd_i2c, MPU_ADDR, mpu6050.reg, &mpu6050.val, 1);
usleep(200);
}
for(i=1; i < sizeof(mpu6050 )/sizeof(mpu6050cfg_t); i++)
{
iRet = aod_i2c_read(fd_i2c, MPU_ADDR, mpu6050.reg, &rdBuff, 1);
printf(&quot;read iRet:%d,(0x%x,0x%x)
&quot;, iRet, mpu6050.reg, rdBuff);
usleep(200);
}
} |