提供给MPU6050驱动的讲解注释(本人亲测),以及DMP库移植的说明,提供一切必须文件,直接移植即可使用输出欧拉角。(附件)
提供完整的附加函数,方便移植使用:
提供完整的驱动以及移植好的DMP库:
MPU6050模块:输出原始数据通过内置DMP进行数据处理,获取姿态信息:角度、角速度,多用于PID控制。
IIC接口引脚配置
3.3V供电
SDA:PB11
SCL:PB10
AD0:PB2
//INT:PB5 中断,暂时用不到
通信协议层:mpu_iic.c/mpu_iic.h
软件模拟IIC,是STM32与MPU6050通信的基本框架
驱动层:mpu6050.c/mpu6050.h
建立在IIC通信机制上的,向DMP库提供对MPU6050寄存器的读写操作,以及完成对MPU6050初始化的任务。
应用层:
移植的库:inv_mpu.c/inv_mpu_dmp_motion_driver.c(及所包含的头文件)
移植的DMP库,对原始数据进行处理,
调用时,在inv_mpu.c中添加如下代码即可(实际上是让DMP库和我们写的驱动层建立联系)
#define i2c_write MPU_Write_Continue
#define i2c_read MPU_Read_Continue
#define delay_ms delay_ms
#define get_ms mget_ms
附加的函数:延时、串口打印,这些到时候可以统一
具体使用例子如下:
#include "stm32f10x.h"
#include "usart.h"
#include "delay.h"
#include "mpu6050.h"
#include "inv_mpu.h"
#include "inv_mpu_dmp_motion_driver.h"
int main(void)
{
uint8_t x=0;
float pitch,roll,yaw; //欧拉角
short aacx,aacy,aacz; //加速度传感器原始数据
short gyrox,gyroy,gyroz; //陀螺仪原始数据
short temp; //温度
NVIC_PriorityGroupConfig( 2 );
delay_init();
USART1_Init(115200);
printf("程序开始\n");
if( MPU_Init()!=0 )
{
printf("MPU6050初始化错误!\n");
return 0;
}
if( mpu_dmp_init() )
{
printf("DMP初始化错误!\n");
return 0;
}
while(1)
{
if(mpu_dmp_get_data(&pitch,&roll,&yaw)==0) //获取DMP处理后的姿态信息(欧拉角)
{
temp=MPU_Get_Temperature(); //得到温度值
MPU_Get_Accelerometer(&aacx,&aacy,&aacz); //获取加速度传感器原始数据
MPU_Get_Gyroscope(&gyrox,&gyroy,&gyroz); //获取陀螺仪原始数据
}
delay_ms(100);
printf("pitch:%02f roll:%02f yaw:%02f\n",pitch,roll,yaw);
}
}
全部资料51hei下载地址:
MPU6050.rar
(47.44 KB, 下载次数: 310)
|