搜索
bottom↓
回复: 8

STM32读MPU6050的DMP数据,自检不过

[复制链接]

出0入0汤圆

发表于 2014-9-17 11:52:40 | 显示全部楼层 |阅读模式
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;

    /* Get initial settings. */
    mpu_get_gyro_fsr(&gyro_fsr);
    mpu_get_accel_fsr(&accel_fsr);
    mpu_get_lpf(&lpf);
    mpu_get_sample_rate(&sample_rate);
    sensors_on = st.chip_cfg.sensors;
    mpu_get_fifo_config(&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;
}

上面这个函数是自检函数在    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;这里accel_result 和gyro_result 都是0x07所以自检不过,有遇到过类似情况的吗,怎么解决?

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

发表于 2014-9-17 20:38:38 | 显示全部楼层
搞个沙发坐一下先

出0入0汤圆

发表于 2014-9-17 20:39:57 | 显示全部楼层
我也在弄这个!是不是RESET后MPU6050延时不够

出0入0汤圆

 楼主| 发表于 2014-9-18 09:25:50 | 显示全部楼层
and001 发表于 2014-9-17 20:39
我也在弄这个!是不是RESET后MPU6050延时不够

这样啊,可以试试,你的现在什么情况了

出0入0汤圆

发表于 2014-9-18 10:05:01 | 显示全部楼层
我也在调试,但苦于没上位机的波形显示(三轴的)

出0入0汤圆

发表于 2014-11-12 23:18:39 | 显示全部楼层
遇到和楼主一样的问题,返回值是ox03 和0x7  ,读不了数据,不知道哪里出问题了,不知道楼主的问题解决了没有。

出0入0汤圆

发表于 2015-1-27 21:39:47 | 显示全部楼层
v灰尘 发表于 2014-11-12 23:18
遇到和楼主一样的问题,返回值是ox03 和0x7  ,读不了数据,不知道哪里出问题了,不知道楼主的问题解决了没 ...

各位好,我在移植mpu6050 dmp到nrf51822遇到同样的问题,请问解决了吗,能否分享下经验!是IIC有问题吗。读原始数据都可以啊!

出0入0汤圆

发表于 2015-1-28 11:31:35 | 显示全部楼层
ZENO_Embed 发表于 2015-1-27 21:39
各位好,我在移植mpu6050 dmp到nrf51822遇到同样的问题,请问解决了吗,能否分享下经验!是IIC有问题吗。 ...

我是这样做的,初始化的时候给一个无限循环,一直读数据,等到读到正确的数据后,跳出。

出0入0汤圆

发表于 2015-1-28 11:50:57 | 显示全部楼层
v灰尘 发表于 2015-1-28 11:31
我是这样做的,初始化的时候给一个无限循环,一直读数据,等到读到正确的数据后,跳出。 ...

好的,谢谢您的回复!
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-15 23:23

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表