|
发表于 2014-5-5 11:28:38
|
显示全部楼层
本帖最后由 SMC 于 2014-5-5 11:58 编辑
这几天我没弄9250了,去弄SPI读取MS5611,已经弄好了。主要参考你IIC写的那个,移植过程中发现一些小问题
一个是计算温度时的C[5]要换成C[6],还有一些数据的类型定义的问题,以及calculate中的计算必须强制将变量范围变大,不然计算溢出,这样会出错的。
这是我修改好的
static void MS5611_Calculate( MS5611_ST* COEFF )
{
float tem;
int64_t T2=0,OFF2,SENS2;
COEFF->dT = (COEFF->D[2] - (COEFF->C[5]*POW_2_8)); // dT = D2 - C5*2^8
COEFF->rTemp = (2000.f + ((int64_t)(COEFF->dT)*(COEFF->C[6]))/POW_2_23); // Temp = 2000 + dT*C6/2^23
COEFF->OFF = ((int64_t)COEFF->C[2]*POW_2_16 + ((int64_t)COEFF->C[4]*COEFF->dT)/POW_2_7); // OFF = C2*2^16 + (C4*dT)/2^7
COEFF->SENS = ((int64_t)COEFF->C[1]*POW_2_15 + ((int64_t)COEFF->C[3]*COEFF->dT)/POW_2_8); // SENS = C1*2^15 + (C3*dT)/2^8
COEFF->rPress = (((int64_t)COEFF->D[1]*COEFF->SENS)/POW_2_21 - (int64_t)COEFF->OFF)/POW_2_15; // Press = (D1*SENS/2^21 - OFF)/2^15
if(COEFF->rTemp<2000)
{
T2=(COEFF->dT)*(COEFF->dT)/POW_2_31;
OFF2=5.f*((float)COEFF->rTemp-2000)*((float)COEFF->rTemp-2000)/2;
SENS2=5.f*((float)COEFF->rTemp-2000)*((float)COEFF->rTemp-2000)/4;
if(COEFF->rTemp<-1500)
{
OFF2=OFF2+7.f*(COEFF->rTemp+1500)*(COEFF->rTemp+1500);
SENS2=SENS2+11.f*(COEFF->rTemp+1500)*(COEFF->rTemp+1500)/2;
}
COEFF->rTemp=COEFF->rTemp-T2;
COEFF->OFF=COEFF->OFF-OFF2;
COEFF->SENS=COEFF->SENS-SENS2;
}
COEFF->Temp = (float)(COEFF->rTemp-800.f)/100.f; //-800是为了修正结果
COEFF->Press = (float)(COEFF->rPress/100.0f);
tem=COEFF->rPress/101333.f;
tem=pow(tem,0.190295f);
COEFF->High=44330.f*(1-tem);
}
弄完这个之后,我就去弄9250了,接着移植你的代码,顺利的读出了加计,陀螺和温度计。
然后我又去弄Master Mode操作AK8963,我还没写读取测量数据的程序,只测了读取WHO AM I,但是一直有问题,不知为何,下面的配置仅仅是为了读取罗盘的ID。
大概思路是:将AK8963的IIC地址写到MPU6500_I2C_SLV0_ADDR中并且是读取模式,将AK8963_WIA写到MPU6500_I2C_SLV0_REG中,只读取一个byte,我去读取EXT_SENS_DATA_00中的数据,一直是0.
{0xCD, MPU6500_I2C_MST_CTRL}, // Enables multi-master IIC 400KHz
{0x30, MPU6500_USER_CTRL},
{AK8963_I2C_ADDR|0x80, MPU6500_I2C_SLV0_ADDR},
{AK8963_WIA, MPU6500_I2C_SLV0_REG},
{0x81, MPU6500_I2C_SLV0_CTRL},
{0x09, MPU6500_I2C_SLV4_CTRL},
{0x81, MPU6500_I2C_MST_DELAY_CTRL}, |
|