OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 4165|回复: 4

【急急急】一个关于6050的历史遗留问题

[复制链接]

1

主题

3

帖子

0

精华

新手入门

积分
6
金钱
6
注册时间
2017-7-31
在线时间
1 小时
发表于 2017-7-31 12:02:36 | 显示全部楼层 |阅读模式
3金钱
这个历史遗留问题曾经在15年的一篇帖子出现过,但是并没有给出明确的答案http://www.openedv.com/thread-60568-1-1.html
我希望原子哥还有广大坛友帮忙解答。

下面是6050自检的函数
1.png

但是当我进入给result赋值的函数时,找到所有给返回值赋值的地方时候发现,并没有一处出现过0x3,也就是说这块自检过不去

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;
}




PS:本人测试过将

图中0x3改为0x1,可以通过初始化,但是未来的准确度不能保证,所以在此提问。


最佳答案

查看完整内容[请看2#楼]

好好看代码好不。你是有多懒得看代码? [mw_shl_code=c,true]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;[/mw_shl_code] 一个是accel_self_test,一个是gyro_self_test 当这两个条件同时满足时,会同时执行 result |= 0x01; result |= 0x02; ...
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

42

主题

358

帖子

0

精华

高级会员

Rank: 4

积分
890
金钱
890
注册时间
2014-8-16
在线时间
193 小时
发表于 2017-7-31 12:02:37 | 显示全部楼层
本帖最后由 Theone 于 2017-7-31 14:57 编辑

好好看代码好不。你是有多懒得看代码?
[mw_shl_code=c,true]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;[/mw_shl_code]

一个是accel_self_test,一个是gyro_self_test

当这两个条件同时满足时,会同时执行 result |= 0x01; result |= 0x02;

那result不就是3了!!!!!原子之前也告诉你让你单步调试,你就是懒得搞。

都告诉你该怎么吃饭了。还非要把饭喂到你嘴边才知道把嘴张开?
回复

使用道具 举报

1

主题

3

帖子

0

精华

新手入门

积分
6
金钱
6
注册时间
2017-7-31
在线时间
1 小时
 楼主| 发表于 2017-7-31 12:07:29 | 显示全部楼层
回复

使用道具 举报

1

主题

3

帖子

0

精华

新手入门

积分
6
金钱
6
注册时间
2017-7-31
在线时间
1 小时
 楼主| 发表于 2017-7-31 12:07:48 | 显示全部楼层
@正点原子 原子哥,求帮忙
回复

使用道具 举报

62

主题

902

帖子

0

精华

论坛元老

Rank: 8Rank: 8

积分
3559
金钱
3559
注册时间
2016-1-8
在线时间
543 小时
发表于 2017-7-31 16:10:28 | 显示全部楼层
Theone 发表于 2017-7-31 14:55
好好看代码好不。你是有多懒得看代码?
[mw_shl_code=c,true]accel_result = accel_self_test(accel, acce ...

可以
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-4-19 22:32

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

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