bpp15802963098 发表于 2014-6-11 17:21
急需楼主帮忙,楼主我现在遇到一个问题读出来AKM_REG_ST1这个寄存器的tmp[0]=0,导致后面的直接返回,所以磁 ...
tmp[6]=0x00;
data_write[6]=0x01;
i2cread(Compass_Addr, Compass_ST1, 1, tmp+6);
if(tmp[6] == 1)
{
i2cread(Compass_Addr, Compass_HXL, 6, tmp);//读取compass
mag[0] = (((signed short int)tmp[1]) << 8) | tmp[0];
mag[1] = (((signed short int)tmp[3]) << 8) | tmp[2];
mag[2] = (((signed short int)tmp[5]) << 8) | tmp[4];
mag[0] = ((long)mag[0] * mag_sens_adj_val[0]) >> 8; //灵敏度调整
mag[1] = ((long)mag[1] * mag_sens_adj_val[1]) >> 8;
mag[2] = ((long)mag[2] * mag_sens_adj_val[2]) >> 8;
//修正mag
init_mx =(float)mag[1] * MXgain + MXoffset; //转换坐标轴
init_my =(float)mag[0] * MYgain + MYoffset;
init_mz =(float)-mag[2] * MZgain + MZoffset;
i2cwrite(Compass_Addr, Compass_CNTL, 1, data_write+6); //开启compass:single measurement mode
参考一下吧 |