新手上路
- 积分
- 38
- 金钱
- 38
- 注册时间
- 2016-7-30
- 在线时间
- 5 小时
|
1金钱
移植MPU6050,发现在初始化时自检始终失败
[mw_shl_code=applescript,true]res=run_self_test(); //自检
printf("自检--res---%d\r\n",res);
if(res)return 8;
res=mpu_set_dmp_state(1); //使能DMP
printf("使能DMP--res---%d\r\n",res);[/mw_shl_code]
发现在函数 run_self_test检测,需要result=0x03;
[mw_shl_code=applescript,true]uint8_t run_self_test(void)
{
int result;
//char test_packet[4] = {0};
long gyro[3], accel[3];
result = mpu_run_self_test(gyro, accel);
printf("result %d\r\n",result);
if (result == 0x3)
{
/* Test passed. We can trust the gyro data here, so let's push it down
* to the DMP.
*/
float sens;
unsigned short accel_sens;
mpu_get_gyro_sens(&sens);
gyro[0] = (long)(gyro[0] * sens);
gyro[1] = (long)(gyro[1] * sens);
gyro[2] = (long)(gyro[2] * sens);
dmp_set_gyro_bias(gyro);
mpu_get_accel_sens(&accel_sens);
accel[0] *= accel_sens;
accel[1] *= accel_sens;
accel[2] *= accel_sens;
dmp_set_accel_bias(accel);
return 0;
}else return 1;
}[/mw_shl_code]
但是在mpu_run_self_test函数中,根本没有等于result=0x03的值
int mpu_run_self_test(long *gyro, long *accel)
{
#ifdef MPU6050
const unsigned char tries = 2;
long gyro_st[3], accel_st[3];
unsigned char accel_result, gyro_result;
#ifdef AK89xx_SECONDARY
unsigned char compass_result;
#endif
int ii;
#endif
int result;
unsigned char accel_fsr, fifo_sensors, sensors_on;
unsigned short gyro_fsr, sample_rate, lpf;
unsigned char dmp_was_on;
if (st.chip_cfg.dmp_on) {
mpu_set_dmp_state(0);
dmp_was_on = 1;
} else
dmp_was_on = 0;
printf("dmp_was_on =%d \r\n",dmp_was_on);
/* Get initial settings. */
mpu_get_gyro_fsr(&gyro_fsr);
printf("gyro_fsr = %X \r\n",gyro_fsr);
mpu_get_accel_fsr(&accel_fsr);
printf("accel_fsr = %X \r\n",accel_fsr);
mpu_get_lpf(&lpf);
printf("lpf = %X \r\n",lpf);
mpu_get_sample_rate(&sample_rate);
printf("sample_rate = %X \r\n",sample_rate);
sensors_on = st.chip_cfg.sensors;
printf("sensors_on = %X \r\n",sensors_on);
mpu_get_fifo_config(&fifo_sensors);
printf("fifo_sensors = %X \r\n",fifo_sensors);
/* For older chips, the self-test will be different. */
#if defined MPU6050
for (ii = 0; ii < tries; ii++)
if (!get_st_biases(gyro, accel, 0))
break;
if (ii == tries) {
/* If we reach this point, we most likely encountered an I2C error.
* We'll just report an error for all three sensors.
*/
result = 0;
goto restore;
}
for (ii = 0; ii < tries; ii++)
if (!get_st_biases(gyro_st, accel_st, 1))
break;
if (ii == tries) {
/* Again, probably an I2C error. */
result = 0;
goto restore;
}
accel_result = accel_self_test(accel, accel_st);
gyro_result = gyro_self_test(gyro, gyro_st);
result = 0;
if (!gyro_result)
result |= 0x01;
if (!accel_result)
result |= 0x02;
#ifdef AK89xx_SECONDARY
compass_result = compass_self_test();
if (!compass_result)
result |= 0x04;
#endif
restore:
#elif defined MPU6500
/* For now, this function will return a "pass" result for all three sensors
* for compatibility with current test applications.
*/
get_st_biases(gyro, accel, 0);
result = 0x7;
#endif
/* Set to invalid values to ensure no I2C writes are skipped. */
st.chip_cfg.gyro_fsr = 0xFF;
st.chip_cfg.accel_fsr = 0xFF;
st.chip_cfg.lpf = 0xFF;
st.chip_cfg.sample_rate = 0xFFFF;
st.chip_cfg.sensors = 0xFF;
st.chip_cfg.fifo_enable = 0xFF;
st.chip_cfg.clk_src = INV_CLK_PLL;
mpu_set_gyro_fsr(gyro_fsr);
mpu_set_accel_fsr(accel_fsr);
mpu_set_lpf(lpf);
mpu_set_sample_rate(sample_rate);
mpu_set_sensors(sensors_on);
mpu_configure_fifo(fifo_sensors);
if (dmp_was_on)
mpu_set_dmp_state(1);
return result;
}
原子哥,帮忙看下是否我移植的有问题
|
-
|