|
本帖最后由 kallyshall 于 2016-3-24 21:08 编辑
- uint8_t mpu_dmp_init(void)
- {
- twi_master_init();
- mpu_init(0);
- //mpu_init();
- simple_uart_putstring("mpu initialization complete......\n ");
- //mpu_set_sensor
- if(!mpu_set_sensors(INV_XYZ_GYRO | INV_XYZ_ACCEL))
- {
- simple_uart_putstring("mpu_set_sensor complete ......\n");
- }
- else
- {
- simple_uart_putstring("mpu_set_sensor come across error ......\n");
- }
- //mpu_configure_fifo
- if(!mpu_configure_fifo(INV_XYZ_GYRO | INV_XYZ_ACCEL))
- {
- simple_uart_putstring("mpu_configure_fifo complete ......\n");
- }
- else
- {
- simple_uart_putstring("mpu_configure_fifo come across error ......\n");
- }
- //mpu_set_sample_rate
- if(!mpu_set_sample_rate(DEFAULT_MPU_HZ))
- {
- simple_uart_putstring("mpu_set_sample_rate complete ......\n");
- }
- else
- {
- simple_uart_putstring("mpu_set_sample_rate error ......\n");
- }
- //dmp_load_motion_driver_firmvare
- if(!dmp_load_motion_driver_firmware())
- {
- simple_uart_putstring("dmp_load_motion_driver_firmware complete ......\n");
- }
- else
- {
- simple_uart_putstring("dmp_load_motion_driver_firmware come across error ......\n");
- }
- //dmp_set_orientation
- if(!dmp_set_orientation(inv_orientation_matrix_to_scalar(gyro_orientation)))
- {
- simple_uart_putstring("dmp_set_orientation complete ......\n");
- }
- else
- {
- simple_uart_putstring("dmp_set_orientation come across error ......\n");
- }
- //dmp_enable_feature
- if(!dmp_enable_feature(DMP_FEATURE_6X_LP_QUAT | DMP_FEATURE_TAP |
- DMP_FEATURE_ANDROID_ORIENT | DMP_FEATURE_SEND_RAW_ACCEL | DMP_FEATURE_SEND_CAL_GYRO |
- DMP_FEATURE_GYRO_CAL))
- {
- simple_uart_putstring("dmp_enable_feature complete ......\n");
- }
- else
- {
- simple_uart_putstring("dmp_enable_feature come across error ......\n");
- }
- //dmp_set_fifo_rate
- if(!dmp_set_fifo_rate(DEFAULT_MPU_HZ))
- {
- simple_uart_putstring("dmp_set_fifo_rate complete ......\n");
- }
- else
- {
- simple_uart_putstring("dmp_set_fifo_rate come across error ......\n");
- }
- run_self_test();
- if(!mpu_set_dmp_state(1))
- {
- simple_uart_putstring("mpu_set_dmp_state complete ......\n");
- }
- else
- {
- simple_uart_putstring("mpu_set_dmp_state come across error ......\n");
- }
- }
复制代码 然后在这个函数出错- int dmp_load_motion_driver_firmware(void)
- {
- return mpu_load_firmware(DMP_CODE_SIZE, dmp_memory, sStartAddress,
- DMP_SAMPLE_RATE);
- }
复制代码- 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;
- nrf_delay_ms(2);
- if (mpu_read_mem(ii, this_write, cur))
- return -1;
- if (memcmp(firmware+ii, cur, this_write))
- return -2;
- nrf_delay_ms(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;
- }
复制代码 用的应该是官方库呀= = |
|