0

我正在尝试使用 InvenSense 的运动驱动程序 6.12 从 MPU-6050 的 DMP 读取数据。

// ...

#define DEFAULT_MPU_HZ  100

void die(const char* message) {
    fprintf(stderr, message);
    exit(1);
}

int main(void) {
    if(mpu_init(NULL)) {
        die("could not initialize MPU!\n");
    }

    if(mpu_set_sensors(INV_XYZ_GYRO | INV_XYZ_ACCEL)) {
        die("could not turn on sensors!\n");
    }

    if(mpu_configure_fifo(INV_XYZ_GYRO | INV_XYZ_ACCEL)) {
        die("could not configure FIFO buffer\n");
    }

    if(mpu_set_sample_rate(DEFAULT_MPU_HZ)) {
        die("could not set sample rate\n");
    }

    if(mpu_set_gyro_fsr(2000)) {
        die("could not set gyro full scale range!\n");
    }

    if(mpu_set_accel_fsr(2)) {
        die("could not set accel full scale range!\n");
    }

    if(dmp_load_motion_driver_firmware()) {
        die("[ERROR] dmp_load_motion_driver_firmware\n");
    }

    // ....

}

此代码也来自运动驱动程序源代码。

在初始化我正在调用的 mpu 之后,dmp_load_motion_driver_firmware();它看起来像这样。

/**
 *  @brief      Load and verify DMP image.
 *  @param[in]  length      Length of DMP image.
 *  @param[in]  firmware    DMP code.
 *  @param[in]  start_addr  Starting address of DMP code memory.
 *  @param[in]  sample_rate Fixed sampling rate used when DMP is enabled.
 *  @return     0 if successful.
 */
int mpu_load_firmware(unsigned short length, const unsigned char *firmware,
    unsigned short start_addr, unsigned short sample_rate)
{
    unsigned short ii;
    unsigned short this_write;
    /* Must divide evenly into st.hw->bank_size to avoid bank crossings. */
#define LOAD_CHUNK  (16)
    unsigned char cur[LOAD_CHUNK], tmp[2];

    if (st.chip_cfg.dmp_loaded)
        /* DMP should only be loaded once. */
        return -1;

    if (!firmware)
        return -1;
    for (ii = 0; ii < length; ii += this_write) {
        this_write = min(LOAD_CHUNK, length - ii);
        if (mpu_write_mem(ii, this_write, (unsigned char*)&firmware[ii]))
            return -1;
        if (mpu_read_mem(ii, this_write, cur))
            return -1;
        if (memcmp(firmware+ii, cur, this_write))
            return -2;
    }

    /* Set program start address. */
    tmp[0] = start_addr >> 8;
    tmp[1] = start_addr & 0xFF;
    if (i2c_write(st.hw->addr, st.reg->prgm_start_h, 2, tmp))
        return -1;

    st.chip_cfg.dmp_loaded = 1;
    st.chip_cfg.dmp_sample_rate = sample_rate;
    return 0;
}

如您所见,这会将固件写入 MPU,读回数据并检查它们是否匹配。不幸的是,它们不匹配,我不知道为什么。读取的值mpu_read_mem如下所示

foo = {unsigned char [16]} 
 [0] = {unsigned char} 0 '\000'
 [1] = {unsigned char} 255 '�'
 [2] = {unsigned char} 255 '�'
 [3] = {unsigned char} 255 '�'
 [4] = {unsigned char} 255 '�'
 [5] = {unsigned char} 255 '�'
 [6] = {unsigned char} 255 '�'
 [7] = {unsigned char} 255 '�'
 [8] = {unsigned char} 255 '�'
 [9] = {unsigned char} 255 '�'
 [10] = {unsigned char} 255 '�'
 [11] = {unsigned char} 255 '�'
 [12] = {unsigned char} 255 '�'
 [13] = {unsigned char} 255 '�'
 [14] = {unsigned char} 255 '�'
 [15] = {unsigned char} 255 '�'

官方开发者论坛上有一些帖子存在完全相同的问题,但没有一个为这个问题提供解决方案。

也许你们中的一些人有同样的问题,可以帮助我。

4

0 回答 0