1.首先初始化MPU6050 借鑒原子哥MPU6050例程
//mpu6050,dmp初始化
//傳回值:0,正常
// 其他,失敗
u8 mpu_dmp_init(void)
{
u8 res=0;
MPU_IIC_Init(); //初始化IIC總線
if(mpu_init()==0) //初始化MPU6050
{
res=mpu_set_sensors(INV_XYZ_GYRO|INV_XYZ_ACCEL);//設定所需要的傳感器
if(res)return 1;
res=mpu_configure_fifo(INV_XYZ_GYRO|INV_XYZ_ACCEL);//設定FIFO
if(res)return 2;
res=mpu_set_sample_rate(DEFAULT_MPU_HZ); //設定采樣率
if(res)return 3;
res=dmp_load_motion_driver_firmware(); //加載dmp固件
if(res)return 4;
res=dmp_set_orientation(inv_orientation_matrix_to_scalar(gyro_orientation));//設定陀螺儀方向
if(res)return 5;
res=dmp_enable_feature(DMP_FEATURE_6X_LP_QUAT|DMP_FEATURE_TAP| //設定dmp功能
DMP_FEATURE_ANDROID_ORIENT|DMP_FEATURE_SEND_RAW_ACCEL|DMP_FEATURE_SEND_CAL_GYRO|
DMP_FEATURE_GYRO_CAL|DMP_FEATURE_PEDOMETER); //DMP_FEATURE_PEDOMETER這個功能,宏業一定要初始化
if(res)return 6;
res=dmp_set_fifo_rate(DEFAULT_MPU_HZ); //設定DMP輸出速率(最大不超過200Hz)
if(res)return 7;
res=run_self_test(); //自檢 這裡陀螺儀自檢可能不會通過,看資料說放平才可以
// if(res)return 8;
res=mpu_set_dmp_state(1); //使能DMP 這裡一定要使能該函數,才能使用計步的函數
if(res)return 9;
}else return 10;
return 0;
}
2.調用這幾個函數即可
/* Pedometer functions. */
int dmp_get_pedometer_step_count(unsigned long *count);
int dmp_set_pedometer_step_count(unsigned long count);
int dmp_get_pedometer_walk_time(unsigned long *time);
int dmp_set_pedometer_walk_time(unsigned long time);