mpu6050量程设置中的满量程16384lsb/g是什么意思

8829人阅读
1.六轴与九轴的区别
六轴包括:三轴加速度计、三轴陀螺仪
九轴包括:三轴加速度计、三轴陀螺仪、三轴磁强计
2.MPU6050简单介绍
MPU6050 是 InvenSense 公司推出的全球首款整合性 6 轴运动处理组件,相较于多组件方案,免除了组合陀螺仪与加速器时之轴间差的问题,减少了安装空间。MPU6050 内部整合了 3 轴陀螺仪和 3 轴加速度传感器,并且含有一个第二 IIC 接口,可用于连接外部磁力传感器即AUX_CL 和 AUX_DA,并利用自带的数字运动处理器(DMP: DigitalMotion
Processor)硬件加速引擎,通过主 IIC 接口,向应用端输出完整的 9 轴融合演算数据。有了 DMP,我们可以使用 InvenSense 公司提供的运动处理资料库,非常方便的实现姿态解算,降低了运动处理运算对操作系统的负荷,同时大大降低了开发难度。
3.模块原理图
其中,SCL 和 SDA 是连接 MCU 的 IIC 接口,MCU 通过这个 IIC 接口来控制 MPU6050,
另外还有一个 IIC 接口:AUX_CL 和 AUX_DA,这个接口可用来连接外部从设备,比如磁
传感器,这样就可以组成一个九轴传感器。VLOGIC 是 IO 口电压,该引脚最低可以到 1.8V,
我们一般直接接 VDD 即可。AD0 是从 IIC 接口(接 MCU)的地址控制引脚,该引脚控制
IIC 地址的最低位。如果接 GND,则 MPU6050 的 IIC 地址是:0X68,如果接 VDD,则是
0X69,注意:这里的地址是不包含数据传输的最低位的(最低位用来表示读写)!!
4.初始化步骤及寄存器详解
1 )初始化 IIC &接口
MPU6050 采用 IIC 与 STM32F1 通信,所以我们需要先初始化与 MPU6050 连接的 SDA
和 SCL 数据线。
2 )复位 MPU6050
这一步让 MPU6050 内部所有寄存器恢复默认值,通过对电源管理寄存器 1(0X6B)的
bit7 写 1 实现。 复位后,电源管理寄存器 1 恢复默认&#2),然后必须设置该寄存器为
0X00,以唤醒 MPU6050,进入正常工作状态。
3 )设置角速度传感器(陀螺仪)和加速度传感器的满量程范围
这一步,我们设置两个传感器的满量程范围(FSR),分别通过陀螺仪配置寄存器(0X1B)
和加速度传感器配置寄存器(0X1C)设置。我们一般设置陀螺仪的满量程范围为±2000dps,
加速度传感器的满量程范围为±2g。
4 )设置其他参数
这里,我们还需要配置的参数有:关闭中断、关闭 AUX IIC 接口、禁止 FIFO、设置陀
螺仪采样率和设置数字低通滤波器(DLPF)等。我们不用中断方式读取数据,所以关
闭中断,然后也没用到 AUX IIC 接口外接其他传感器,所以也关闭这个接口。分别通过中
断使能寄存器(0X38)和用户控制寄存器(0X6A)控制。MPU6050 可以使用 FIFO 存储传
感器数据,不过我们没有用到,所以关闭所有 FIFO 通道,这个通过 FIFO 使能寄存器
(0X23)控制,默认都是 0(即禁止 FIFO),所以用默认值就可以了。陀螺仪采样率通过采
样率分频寄存器(0X19)控制,这个采样率我们一般设置为 50 即可。数字低通滤波器(DLPF)
则通过配置寄存器(0X1A)设置,一般设置 DLPF 为带宽的 1/2 即可。
5 )配置系统时钟源并使能角速度传感器和加速度传感器
系统时钟源同样是通过电源管理寄存器 1(0X1B)来设置,该寄存器的最低三位用于
设置系统时钟源选择,默认值是 0(内部 8M RC 震荡),不过我们一般设置为 1,选择 x 轴
陀螺 PLL 作为时钟源,以获得更高精度的时钟。同时,使能角速度传感器和加速度传感器,
这两个操作通过电源管理寄存器 2(0X6C)来设置,设置对应位为 0 即可开启。
至此,MPU6050 的初始化就完成了,可以正常工作了(其他未设置的寄存器全部采用
默认值即可),接下来,我们就可以读取相关寄存器,得到加速度传感器、角速度传感器和
温度传感器的数据了。不过,我们先简单介绍几个重要的寄存器。
首先,我们介绍电源管理寄存器 1,该寄存器地址为 0X6B,各位描述如图
其中,DEVICE_RESET 位用来控制复位,设置为 1,复位 MPU6050,复位结束后,MPU
硬件自动清零该位。SLEEEP 位用于控制 MPU6050 的工作模式,复位后,该位为 1,即进
入了睡眠模式(低功耗),所以我们要清零该位,以进入正常工作模式。TEMP_DIS 用于设
置是否使能温度传感器,设置为 0,则使能。最后 CLKSEL[2:0]用于选择系统时钟源,选择
默认是使用内部 8M RC 晶振的,精度不高,所以我们一般选择 X/Y/Z 轴陀螺作为参考
的 PLL 作为时钟源,一般设置 CLKSEL=001 即可。
接着,我们看陀螺仪配置寄存器,该寄存器地址为:0X1B,各位描述如图
该寄存器我们只关心 FS_SEL[1:0]这两个位,用于设置陀螺仪的满量程范围:0,±250°
/S;1,±500°/S;2,±1000°/S;3,±2000°/S;我们一般设置为 3,即±2000°/S,因
为陀螺仪的 ADC 为 16 位分辨率,所以得到灵敏度为:=16.4LSB/(°/S)。
接下来,我们看加速度传感器配置寄存器,寄存器地址为:0X1C,各位描述如图
该寄存器我们只关心 AFS_SEL[1:0]这两个位,用于设置加速度传感器的满量程范围:0,
±2g;1,±4g;2,±8g;3,±16g;我们一般设置为 0,即±2g,因为加速度传感器的
ADC 也是 16 位,所以得到灵敏度为:84LSB/g。
接下来,我看看 FIFO 使能寄存器,寄存器地址为:0X1C,各位描述如图
该寄存器用于控制 FIFO 使能,在简单读取传感器数据的时候,可以不用 FIFO,设置
对应位为 0 即可禁止 FIFO,设置为 1,则使能 FIFO。注意加速度传感器的 3 个轴,全由 1
个位(ACCEL_FIFO_EN)控制,只要该位置 1,则加速度传感器的三个通道都开启 FIFO
接下来,我们看陀螺仪采样率分频寄存器,寄存器地址为:0X19,各位描述如图
该寄存器用于设置 MPU6050 的陀螺仪采样频率,计算公式为:
采样频率 = &陀螺仪输出频率 / (1+SMPLRT_DIV)
这里陀螺仪的输出频率,是 1Khz 或者 8Khz,与数字低通滤波器(DLPF)的设置有关,
当 DLPF_CFG=0/7 的时候,频率为 8Khz,其他情况是 1Khz。而且 DLPF 滤波频率一般设置
为采样率的一半。采样率,我们假定设置为 50Hz,那么 SMPLRT_DIV==19。
接下来,我们看配置寄存器,寄存器地址为:0X1A,各位描述如图
这里,我们主要关心数字低通滤波器(DLPF)的设置位,即:DLPF_CFG[2:0],加速
度计和陀螺仪,都是根据这三个位的配置进行过滤的。DLPF_CFG 不同配置对应的过滤情
这里的加速度传感器,输出速率(Fs)固定是 1Khz,而角速度传感器的输出速率(Fs),
则根据 DLPF_CFG 的配置有所不同。一般我们设置角速度传感器的带宽为其采样率的一半,
如前面所说的,如果设置采样率为 50Hz,那么带宽就应该设置为 25Hz,取近似值 20Hz,
就应该设置 DLPF_CFG=100。
接下来,我们看电源管理寄存器 2,寄存器地址为:0X6C,各位描述如图&
该寄存器的 LP_WAKE_CTRL 用于控制低功耗时的唤醒频率,本章用不到。剩下的 6
位,分别控制加速度和陀螺仪的 x/y/z 轴是否进入待机模式,这里我们全部都不进入待机模
式,所以全部设置为 0 即可。
接下来,我们看看陀螺仪数据输出寄存器,总共有 8 个寄存器组成,地址为:0X43~0X48,
通过读取这 8 个寄存器,就可以读到陀螺仪 x/y/z 轴的值,比如 x 轴的数据,可以通过读取
0X43(高 8 位)和 0X44(低 8 位)寄存器得到,其他轴以此类推。
同样,加速度传感器数据输出寄存器,也有 8 个,地址为:0X3B~0X40,通过读取这 8
个寄存器,就可以读到加速度传感器 x/y/z 轴的值,比如读 x 轴的数据,可以通过读取 0X3B
(高 8 位)和 0X3C(低 8 位)寄存器得到,其他轴以此类推。
最后,温度传感器的值,可以通过读取 0X41(高 8 位)和 0X42(低 8 位)寄存器得到,
温度换算公式为:
Temperature = 36.53 + regval/340
其中,Temperature 为计算得到的温度值,单位为℃,regval 为从 0X41 和 0X42 读到的
温度传感器值。
我们可以读出 MPU6050 的加速度传感器和角速度传感器的原始数
据。不过这些原始数据,对想搞四轴之类的初学者来说,用处不大,我们期望得到的是姿态
数据,也就是欧拉角:航向角(yaw)、横滚角(roll)和俯仰角(pitch)。有了这三个角,我
们就可以得到当前四轴的姿态,这才是我们想要的结果。
要得到欧拉角数据,就得利用我们的原始数据,进行姿态融合解算,这个比较复杂,知
识点比较多,初学者 不易掌握。而 MPU6050 自带了数字运动处理器,即 DMP,并且,
InvenSense 提供了一个 MPU6050 的嵌入式运动驱动库,结合 MPU6050 的 DMP,可以将我
们的原始数据,直接转换成四元数输出,而得到四元数之后,就可以很方便的计算出欧拉角,
从而得到 yaw、roll 和 pitch。
使用内置的 DMP,大大简化了四轴的代码设计,且 MCU 不用进行姿态解算过程,大
大降低了 MCU 的负担,从而有更多的时间去处理其他事件,提高系统实时性。
使用 MPU6050 的 DMP 输出的四元数是 q30 格式的,也就是浮点数放大了 2 的 30 次方
倍。在换算成欧拉角之前,必须先将其转换为浮点数,也就是除以 2 的 30 次方,然后再进
行计算,计算公式为:
q0=quat[0] / q30; //q30 格式转换为浮点数
q1=quat[1] / q30;
q2=quat[2] / q30;
q3=quat[3] / q30;
//计算得到俯仰角/横滚角/航向角
pitch=asin(-2 * q1 * q3 + 2 * q0* q2)* 57.3; //俯仰角
roll=atan2(2 * q2 * q3 + 2 * q0 * q1, -2 * q1 * q1 - 2 * q2* q2 + 1)* 57.3; //横滚角
yaw=atan2(2*(q1*q2 + q0*q3),q0*q0+q1*q1-q2*q2-q3*q3) * 57.3; //航向角
其中 quat[0]~ quat[3]是 MPU6050 的 DMP 解算后的四元数,q30 格式,所以要除以一个
2 的 30 次方,其中 q30 是一个常量:,即 2 的 30 次方,然后带入公式,计算出
欧拉角。上述计算公式的 57.3 是弧度转换为角度,即 180/π,这样得到的结果就是以度(°)
为单位的。
nvenSense 提供的 MPU6050 运动驱动库是基于 MSP430 ,官方DMP驱动库移植起来,还是比较简单的,主要是实现这4个函数:i2c_write,i2c_read,delay_ms 和 get_ms,主要移植六个文件:
该驱动库,重点就是两个 c 文件:inv_mpu.c 和 inv_mpu_dmp_motion_driver.c。其中我
们在 inv_mpu.c 添加了几个函数,方便我们使用,重点是两个函数:mpu_dmp_init 和
mpu_dmp_get_data 这两个函数,这里我们简单介绍下这两个函数。
mpu_dmp_init,是 MPU6050 DMP 初始化函数,该函数代码如下:
//mpu6050,dmp 初始化
//返回值:0,正常
// 其他,失败
u8 mpu_dmp_init(void)
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_FEATURE_ANDROID_ORIENT|DMP_FEATURE_SEND_RAW_ACCEL
|DMP_FEATURE_SEND_CAL_GYRO|DMP_FEATURE_GYRO_CAL);
//设置 dmp 功能
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;
此函数首先通过 IIC_Init(需外部提供)初始化与 MPU6050 连接的 IIC 接口,然后调用
mpu_init 函数,初始化 MPU6050,之后就是设置 DMP 所用传感器、FIFO、采样率和加载
固件等一系列操作,在所有操作都正常之后,最后通过 mpu_set_dmp_state(1)使能 DMP 功
能,在使能成功以后,我们便可以通过 mpu_dmp_get_data 来读取姿态解算后的数据了。
mpu_dmp_get_data 函数代码如下:
//得到 dmp 处理后的数据(注意,本函数需要比较多堆栈,局部变量有点多)
//pitch:俯仰角 精度:0.1° 范围:-90.0° &---& +90.0°
//roll:横滚角 精度:0.1° 范围:-180.0°&---& +180.0°
//yaw:航向角 精度:0.1° 范围:-180.0°&---& +180.0°
//返回值:0,正常
// 其他,失败
u8 mpu_dmp_get_data(float *pitch,float *roll,float *yaw)
float q0=1.0f,q1=0.0f,q2=0.0f,q3=0.0f;
unsigned long sensor_
short gyro[3], accel[3],
long quat[4];
if(dmp_read_fifo(gyro, accel, quat, &sensor_timestamp, &sensors,&more))return 1;
if(sensors&INV_WXYZ_QUAT)
q0 = quat[0] / q30; //q30 格式转换为浮点数
q1 = quat[1] / q30;
q2 = quat[2] / q30;
q3 = quat[3] / q30;
//计算得到俯仰角/横滚角/航向角
*pitch = asin(-2 * q1 * q3 + 2 * q0* q2)* 57.3; &// pitch
*roll = atan2(2 * q2 * q3 + 2 * q0 * q1, -2 * q1 * q1 - 2 * q2* q2 + 1)* 57.3;// roll
*yaw= atan2(2*(q1*q2 + q0*q3),q0*q0+q1*q1-q2*q2-q3*q3) * 57.3;//yaw
}else return 2;
此函数用于得到 DMP 姿态解算后的俯仰角、横滚角和航向角。这里就用到了我们前面
介绍的四元数转欧拉角公式,将 dmp_read_fifo 函数读到的 q30 格式四元数转换成欧拉角。
6.实现部分源代码
//初始化 MPU6050
//返回值:0,成功
// 其他,错误代码
u8 MPU_Init(void)
MPU_IIC_Init(); &//初始化 IIC 总线
MPU_Write_Byte(MPU_PWR_MGMT1_REG,0X80);//复位 MPU6050
delay_ms(100);
MPU_Write_Byte(MPU_PWR_MGMT1_REG,0X00);//唤醒 MPU6050
MPU_Set_Gyro_Fsr(3); //陀螺仪传感器,±2000dps
MPU_Set_Accel_Fsr(0); &//加速度传感器,±2g
MPU_Set_Rate(50); &//设置采样率 50Hz
MPU_Write_Byte(MPU_INT_EN_REG,0X00); //关闭所有中断
MPU_Write_Byte(MPU_USER_CTRL_REG,0X00); //I2C 主模式关闭
MPU_Write_Byte(MPU_FIFO_EN_REG,0X00); //关闭 FIFO
MPU_Write_Byte(MPU_INTBP_CFG_REG,0X80); //INT 引脚低电平有效
res=MPU_Read_Byte(MPU_DEVICE_ID_REG);
if(res==MPU_ADDR)//器件 ID 正确
MPU_Write_Byte(MPU_PWR_MGMT1_REG,0X01);&
//设置 CLKSEL,PLL X 轴为参考
MPU_Write_Byte(MPU_PWR_MGMT2_REG,0X00);//加速度与陀螺仪都工作
MPU_Set_Rate(50); &//设置采样率为 50Hz
}else return 1;
//得到温度值
//返回值:温度值(扩大了 100 倍)
short MPU_Get_Temperature(void)
u8 buf[2];
MPU_Read_Len(MPU_ADDR,MPU_TEMP_OUTH_REG,2,buf);
raw=((u16)buf[0]&&8)|buf[1];
temp=36.53+((double)raw)/340;
return temp*100;
//得到陀螺仪值(原始值)
//gx,gy,gz:陀螺仪 x,y,z 轴的原始读数(带符号)
//返回值:0,成功
// 其他,错误代码
u8 MPU_Get_Gyroscope(short *gx,short *gy,short *gz)
u8 buf[6],
res=MPU_Read_Len(MPU_ADDR,MPU_GYRO_XOUTH_REG,6,buf);
if(res==0)
*gx=((u16)buf[0]&&8)|buf[1];
*gy=((u16)buf[2]&&8)|buf[3];
*gz=((u16)buf[4]&&8)|buf[5];
//得到加速度值(原始值)
//gx,gy,gz:陀螺仪 x,y,z 轴的原始读数(带符号)
//返回值:0,成功
// 其他,错误代码
u8 MPU_Get_Accelerometer(short *ax,short *ay,short *az)
u8 buf[6],
res=MPU_Read_Len(MPU_ADDR,MPU_ACCEL_XOUTH_REG,6,buf);
if(res==0)
*ax=((u16)buf[0]&&8)|buf[1];
*ay=((u16)buf[2]&&8)|buf[3];
*az=((u16)buf[4]&&8)|buf[5];
/IIC 连续写
//addr:器件地址
//reg:寄存器地址
//len:写入长度
//buf:数据区
//返回值:0,正常
// 其他,错误代码
u8 MPU_Write_Len(u8 addr,u8 reg,u8 len,u8 *buf)
IIC_Start();
IIC_Send_Byte((addr&&1)|0);//发送器件地址+写命令&
if(IIC_Wait_Ack()){IIC_Stop();return 1;}//等待应答
IIC_Send_Byte(reg); &//写寄存器地址
IIC_Wait_Ack(); &//等待应答
for(i=0;i&i++)
IIC_Send_Byte(buf[i]); //发送数据
if(IIC_Wait_Ack()) {IIC_Stop();return 1;}//等待 ACK
IIC_Stop();&
//IIC 连续读
//addr:器件地址
//reg:要读取的寄存器地址
//len:要读取的长度
//buf:读取到的数据存储区
//返回值:0,正常
// 其他,错误代码
u8 MPU_Read_Len(u8 addr,u8 reg,u8 len,u8 *buf)
IIC_Start();
IIC_Send_Byte((addr&&1)|0); //发送器件地址+写命令&
if(IIC_Wait_Ack()){ IIC_Stop();return 1; } //等待应答
IIC_Send_Byte(reg); &//写寄存器地址
IIC_Wait_Ack(); &//等待应答
IIC_Start();
IIC_Send_Byte((addr&&1)|1);//发送器件地址+读命令&
IIC_Wait_Ack(); &//等待应答
while(len)
if(len==1)*buf=IIC_Read_Byte(0);//读数据,发送 nACK
else *buf=IIC_Read_Byte(1); //读数据,发送 ACK
len--; buf++;
IIC_Stop(); &//产生一个停止条件
//串口 1 发送 1 个字符
//c:要发送的字符
void usart1_send_char(u8 c)
while((USART1-&SR&0X40)==0);//等待上一次发送完毕
USART1-&DR=c;
//传送数据给匿名四轴上位机软件(V2.6 版本)
//fun:功能字. 0XA0~0XAF
//data:数据缓存区,最多 28 字节!!
//len:data 区有效数据个数
void usart1_niming_report(u8 fun,u8*data,u8 len)
u8 send_buf[32]; u8
if(len&28) &//最多 28 字节数据
send_buf[len+3]=0; //校验数置零
send_buf[0]=0X88; //帧头
send_buf[1]= //功能字
send_buf[2]= &//数据长度
for(i=0;i&i++)send_buf[3+i]=data[i]; &//复制数据
for(i=0;i&len+3;i++)send_buf[len+3]+=send_buf[i]; &//计算校验和
for(i=0;i&len+4;i++)usart1_send_char(send_buf[i]); &//发送数据到串口 1
//发送加速度传感器数据和陀螺仪数据
//aacx,aacy,aacz:x,y,z 三个方向上面的加速度值
//gyrox,gyroy,gyroz:x,y,z 三个方向上面的陀螺仪值
void mpu6050_send_data(short aacx,short aacy,short aacz,short gyrox,short gyroy,short
u8 tbuf[12];
tbuf[0]=(aacx&&8)&0XFF;
tbuf[1]=aacx&0XFF;
tbuf[2]=(aacy&&8)&0XFF;
tbuf[3]=aacy&0XFF;
tbuf[4]=(aacz&&8)&0XFF;
tbuf[5]=aacz&0XFF;
tbuf[6]=(gyrox&&8)&0XFF;
tbuf[7]=gyrox&0XFF;
tbuf[8]=(gyroy&&8)&0XFF;
tbuf[9]=gyroy&0XFF;
tbuf[10]=(gyroz&&8)&0XFF;
tbuf[11]=gyroz&0XFF;
usart1_niming_report(0XA1,tbuf,12);//自定义帧,0XA1
//通过串口 1 上报结算后的姿态数据给电脑
//aacx,aacy,aacz:x,y,z 三个方向上面的加速度值
//gyrox,gyroy,gyroz:x,y,z 三个方向上面的陀螺仪值
//roll:横滚角.单位 0.01 度。 -18000 -& 18000 对应 -180.00 -& 180.00 度
//pitch:俯仰角.单位 0.01 度。-9000 - 9000 对应 -90.00 -& 90.00 度
//yaw:航向角.单位为 0.1 度 0 -& 3600 对应 0 -& 360.0 度
void usart1_report_imu(short aacx,short aacy,short aacz,short gyrox,short gyroy,short
gyroz,short roll,short pitch,short yaw)
u8 tbuf[28]; u8
for(i=0;i&28;i++)tbuf[i]=0;//清 0
tbuf[0]=(aacx&&8)&0XFF;
tbuf[1]=aacx&0XFF;
tbuf[2]=(aacy&&8)&0XFF;
tbuf[3]=aacy&0XFF;
tbuf[4]=(aacz&&8)&0XFF;
tbuf[5]=aacz&0XFF;
tbuf[6]=(gyrox&&8)&0XFF;
tbuf[7]=gyrox&0XFF;
tbuf[8]=(gyroy&&8)&0XFF;
tbuf[9]=gyroy&0XFF;
tbuf[10]=(gyroz&&8)&0XFF;
tbuf[11]=gyroz&0XFF;
tbuf[18]=(roll&&8)&0XFF;
tbuf[19]=roll&0XFF;
tbuf[20]=(pitch&&8)&0XFF;
tbuf[21]=pitch&0XFF;
tbuf[22]=(yaw&&8)&0XFF;
tbuf[23]=yaw&0XFF;
usart1_niming_report(0XAF,tbuf,28);//飞控显示帧,0XAF
int main(void)
u8 t=0,report=1; &//默认开启上报
float pitch,roll, //欧拉角
short aacx,aacy, &//加速度传感器原始数据
short gyrox,gyroy, //陀螺仪原始数据
Stm32_Clock_Init(9); &//系统时钟设置
uart_init(72,500000); &//串口初始化为 500000
delay_init(72); //延时初始化
usmart_dev.init(72); &//初始化 USMART
LED_Init(); &//初始化与 LED 连接的硬件接口
KEY_Init(); &//初始化按键
LCD_Init(); &//初始化 LCD
MPU_Init(); //初始化 MPU6050
POINT_COLOR=RED; //设置字体为红色
LCD_ShowString(30,50,200,16,16,&Mini STM32&);
LCD_ShowString(30,70,200,16,16,&MPU6050 TEST&);&
LCD_ShowString(30,90,200,16,16,&ATOM@ALIENTEK&);
LCD_ShowString(30,110,200,16,16,&&);
while(mpu_dmp_init())
LCD_ShowString(30,130,200,16,16,&MPU6050 Error&); delay_ms(200);
LCD_Fill(30,130,239,130+16,WHITE); delay_ms(200);
LCD_ShowString(30,130,200,16,16,&MPU6050 OK&);
LCD_ShowString(30,150,200,16,16,&KEY0:UPLOAD ON/OFF&);
POINT_COLOR=BLUE;//设置字体为蓝色
LCD_ShowString(30,170,200,16,16,&UPLOAD ON &);&
LCD_ShowString(30,200,200,16,16,& Temp: . C&);&
LCD_ShowString(30,220,200,16,16,&Pitch: . C&);
LCD_ShowString(30,240,200,16,16,& Roll: . C&);
LCD_ShowString(30,260,200,16,16,& Yaw : . C&);
key=KEY_Scan(0);
if(key==KEY0_PRES)
if(report)LCD_ShowString(30,170,200,16,16,&UPLOAD ON &);
else LCD_ShowString(30,170,200,16,16,&UPLOAD OFF&);
if(mpu_dmp_get_data(&pitch,&roll,&yaw)==0)
temp=MPU_Get_Temperature(); //得到温度值
MPU_Get_Accelerometer(&aacx,&aacy,&aacz); //得到加速度传感器数据
MPU_Get_Gyroscope(&gyrox,&gyroy,&gyroz); //得到陀螺仪数据
if(report)mpu6050_send_data(aacx,aacy,aacz,gyrox,gyroy,gyroz);
//用自定义帧发送加速度和陀螺仪原始数据
if(report)usart1_report_imu(aacx,aacy,aacz,gyrox,gyroy,gyroz,(int)(roll*100),
(int)(pitch*100),(int)(yaw*10));
if((t%10)==0)
if(temp&0)
LCD_ShowChar(30+48,200,'-',16,0); &//显示负号
temp=- //转为正数
}else LCD_ShowChar(30+48,200,' ',16,0); //去掉负号
LCD_ShowNum(30+48+8,200,temp/100,3,16); //显示整数部分
LCD_ShowNum(30+48+40,200,temp%10,1,16); //显示小数部分
temp=pitch*10;
if(temp&0)
LCD_ShowChar(30+48,220,'-',16,0); &//显示负号
temp=- //转为正数
}else LCD_ShowChar(30+48,220,' ',16,0); //去掉负号
LCD_ShowNum(30+48+8,220,temp/10,3,16); &//显示整数部分&
LCD_ShowNum(30+48+40,220,temp%10,1,16); //显示小数部分
temp=roll*10;
if(temp&0)
LCD_ShowChar(30+48,240,'-',16,0); &//显示负号
temp=- //转为正数
}else LCD_ShowChar(30+48,240,' ',16,0); //去掉负号
LCD_ShowNum(30+48+8,240,temp/10,3,16); &//显示整数部分&
LCD_ShowNum(30+48+40,240,temp%10,1,16); //显示小数部分
temp=yaw*10;
if(temp&0)
LCD_ShowChar(30+48,260,'-',16,0); &//显示负号
temp=- //转为正数
}else LCD_ShowChar(30+48,260,' ',16,0); //去掉负号
LCD_ShowNum(30+48+8,260,temp/10,3,16); &//显示整数部分&
LCD_ShowNum(30+48+40,260,temp%10,1,16); //显示小数部分
LED0=!LED0;//LED 闪烁
t++;
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:78418次
积分:1687
积分:1687
排名:千里之外
原创:88篇
转载:24篇
评论:17条
(1)(2)(2)(7)(2)(12)(27)(2)(2)(1)(1)(6)(23)(7)(4)(13)当前位置: >>
MPU6050基础
MPU-6050MPU-6000 为全球首例整合性 6 轴运动处理组件,相较于多组件方案,免除了组合陀螺 仪与加速器时之轴间差的问题,减少了大量的包装空间。MPU-6000 整合了 3 轴陀螺仪、3 轴加速器,并含可藉由第二个 I2C 端口连接其他厂牌之加速器、磁力传感器、或其他传感器 的数位运 动处理(DMP: Digital Motion Processor)硬件
加速引擎,由主要 I2C 端口以单一数据 流的形式,向应用端输出完整的 9 轴融合演算技术 InvenSense 的运动处理资料库,可处理运动感测的复杂数据,降低了运动处理运算对操 作系统的负荷,并为应用开发提供架构化的 API。 MPU-6000 的角速度全格感测范围为±250、±500、±1000 与±2000°/sec (dps),可准确追 h快速与慢速动作,并且,用户可程式控制的加速器全格感测范围为±2g、±4g±8g 与±16g。 产品传输可透过最高至 400kHz 的 I2C 或最高达 20MHz 的 SPI。 MPU-6000 可在不同电压下工作,VDD 供电电压介为 2.5V±5%、3.0V±5%或 3.3V±5%,逻 辑接口 VVDIO 供电为 1.8V± 5%。MPU-6000 的包装尺寸 4x4x0.9mm(QFN),在业界是革命性 的尺寸。其他的特征包含内建的温度感测器、包含在运作环境中仅有±1%变 动的振荡器。 应用 运动感测游戏 现实增强 电子稳像 (EIS: Electronic Image Stabilization) 光学稳像(OIS: Optical Image Stabilization) 行人导航器 “零触控”手势用户接口 姿势快捷方式 认证市场 智能型手机 平板装置设备 手持型游戏产品 游戏机 3D 遥控器 可携式导航设备 特征 1、以数字输出 6 轴或 9 轴的旋转矩阵、四元数(quaternion)、欧拉角格式(Euler Angle forma) 的融合演算数据。 2、具有 131 LSBs/°/sec 敏感度与全格感测范围为±250、±500、±1000 与±2000°/sec 的 3 轴 角速度感测器(陀螺仪)。 3、可程式控制,且程式控制范围为±2g、±4g、±8g 和±16g 的 3 轴加速器。 4、移除加速器与陀螺仪轴间敏感度,降低设定给予的影响与感测器的飘移。 5、数字运动处理(DMP: Digital Motion Processing)引擎可减少复杂的融合演算数据、感测器同 步化、姿势感应等的负荷。 6、运动处理数据库支持 Android、Linux 与 Windows 7、内建之运作时间偏差与磁力感测器校正演算技术,免除了客户须另外进行校正的需求。 8、以数位输出的温度传感器 9、以数位输入的同步引脚(Sync pin)支援视频电子影相稳定技术与 GPS 10、可程式控制的中断(interrupt)支援姿势识别、摇摄、画面放大缩小、滚动、快速下降中 断、high-G 中断、零动作感应、触击感应、摇动感应功能。 11、VDD 供电电压为 2.5V±5%、3.0V±5%、3.3V±5%;VDDIO 为 1.8V± 5% 12、陀螺仪运作电流:5mA,陀螺仪待命电流:8A;加速器运作电流:8A,加速器省电模 式电流: 8A@10Hz 13、高达 400kHz 快速模式的 I2C,或最高至 20MHz 的 SPI 串行主机接口(serial host interface) 14、内建频率产生器在所有温度范围(full temperature range)仅有±1%频率变化。 15、使用者亲自测试 16、10,000 g 碰撞容忍度 17、为可携式产品量身订作的最小最薄包装 (4x4x0.9mm QFN) 18、符合 RoHS 及环境标准 MPU-6000 为全球首例整合性 6 轴运动处理组件,相较于多组件 方案,免除了组合陀螺仪与加速器时之轴间差的问题,减少了 大量的包装空间。MPU-6000 整合了 3 轴陀螺仪、3 轴加速器,并含可藉由第二个 I2C 端口连接其他厂牌之加速器、磁力 传感器、或其他传感器的数位运动 处理(DMP: Digital Motion Processor)硬件加速引擎,由主 要 I2C 端口以单一数据流的形式,向应用端输出完整的 9 轴融合演算技术 InvenSense 的运动处理资料库,可处理运动感测的复杂数据,降低了运动处理运算对操作系 统的负荷,并为应用开发提供架构化的 API。 MPU-6000 的角速度全格感测范围为±250、±500、±1000 与±2000°/sec (dps),可准确追 h快速与慢速动作,并且,用户可程式控制的加速器全格感测范围为±2g、±4g±8g 与±16g。 产品传输可透过最高至 400kHz 的 I2C 或最高达 20MHz 的 SPI。 MPU-6000 可在不同电压下工作,VDD 供电电压介为 2.5V±5%、3.0V±5%或 3.3V±5%,逻 辑接口 VVDIO 供电为 1.8V± 5%。MPU-6000 的包装尺寸 4x4x0.9mm(QFN),在业界是革命性 的尺寸。其他的特征包含内建的温度感测器、包含在运作环境中仅有±1%变 动的振荡器。 MEMS 模块功能: 三轴陀螺仪,三轴加速度计电源电压最小值: 2.5V 电源电压最大值: 3.6V 封装类: QFN 针脚数: 24 陀螺仪范围: ± 250°/s, ± 500°/s, ± 1000°/s, ± 2000°/sdps 是一种角速度单位,Degree Per Second 的缩写°/S。加速度范围: ± 2g, ± 4g, ± 8g, ± 16g 封装: 剪切带 MSL: 19.2MHz 或 32.768kHz 可选外部时钟输入频率变化。内部有自带晶振。 DMP 从陀螺仪、加速度计以及外接的传感器接收并处理数据,处理结果可以从 DMP 的寄存器读出,或通过 FIFO 缓冲. DMP 有权使用 MPU 的一个外部引脚产生中断。 6050 使用 I2C,并且总是作为从设备。 连接主设备的逻辑电平用 VLOGIC 引脚设置。 I2C 的 Slave 地址的最低有效位(LSB)用 PIN9(AD0)设置。 自检可用来测试传感器的机械和电气结构。 对每个测量轴的自检可通过设置控制寄存器 ACCEL_CONFIG 和 GYRO_CONFIG 的相关位来进行。自检启动后,电路会使传感器工作 并且产生输出信号。 MPU-6050 器件结合了 3 轴陀螺仪和在同一硅芯片的三轴加速度计, 结合机载数字运动处理 器?(DMP?) ,处理复杂的六轴 motionfusion 算法。该设备可以通过一个辅助主我?C 总线访 问外部传感器或其它传感器,允许设备收集全套传感器数据。轴方向的灵敏度和极性旋转1(CLKIN) Optional external reference clock input. Connect to GND if unused.可选的外部参考时钟输入,不用则连接到 GND 2,3, 4, 5, 14,15, 16, 17(NC) Not internally connected. May be used for PCB trace routing. 无内部连接。 可用于 PCB 布线。 6(AUX_DA) I 2C master serial data, for connecting to external sensors I~2C 主串行数据,用于连接外部传感器 7(AUX_CL) I 2C Master serial clock, for connecting to external sensors I~2C 串行主时钟,用于连接外部传感器 8(VLOGIC) Digital I/O supply voltage 数字 I / O 电源电压 9(AD0) I 2C Slave Address LSB (AD0) I2C 从地址的 LSB(ADO) 10(REGOUT) Regulator filter capacitor connection 调节器的滤波电容器的连接 11(FSYNC) Frame synchronization digital input. Connect to GND if unused. 帧同步数字输入。如果不用则连接到 GND。带数 字输入同步引脚(Sync pin)支持视频电子影相稳定技术与 GPS 12(INT) Interrupt digital output (totem pole or open-drain) 中断的数字输出(推挽或开漏)可程序控制的中断(interrupt), 支持姿势识别、摇摄、画面放大缩小、滚动、快速下降中断、high-G 中断、零动作感应、触击感应、摇动感应功能 13(VDD) Power supply voltage and Digital I/O supply voltage 电源电压和数字 I / O 电源电压 18(GND) Power supply ground 电源地 19, 21(RESV) Reserved. Do not connect. 保留。不连接。 20(CPOUT) Charge pump capacitor connection 电荷泵电容连接 22(CLKOUT) System clock output 系统时钟输出 23(SCL) I 2C serial clock (SCL) I2C 串行时钟(SCL) 24(SDA) I 2C serial data (SDA) I2C 串行数据(SDA) Typical Operating Circuit外部零件材料账单推荐上电过程: Power-Up Sequencing 先后顺序 1 . VLOGIC amplitude 振幅 must always be ≤VDD amplitude 2. TVDDR is VDD rise time: Time for VDD to rise from 1 0% to 90% of its final value 3. TVDDR is ≤1 00ms 4. TVLGR is VLOGIC rise time: Time for VLOGIC to rise from 1 0% to 90% of its final value 5. TVLGR is ≤3ms 6. TVLG-VDD is the delay from the start of VDD ramp 斜道 to the start of VLOGIC rise 7. TVLG-VDD is ≥0 8. VDD and VLOGIC must be monotonic 单调的 rampsBlock Diagram 框图 Note: Pin names in round brackets ( ) apply only to MPU-6000 Pin names in square brackets [ ] apply only to MPU-6050 Bypass 旁道,支路. multiplexer 多路调制器FSYNC 帧同步数字输入。如果未连接到 GND。偏压和 LDO 部分提供了 6050 需要的内部支持以及参考电压和参考电流。 他的 2 个输出为 VDD (2.1V-3.6V)和 VLOGIC 逻辑参考电压(1.71V~VDD)OverviewThe MPU-60X0 is comprised of the following key blocks and functions(关键模块和功能) 1. Three-axis MEMS rate gyroscope sensor with 16-bit ADCs and signal conditioning 2. Three-axis MEMS accelerometer sensor with 16-bit ADCs and signal conditioning 3. Digital Motion Processor (DMP) engine 4. Primary I 2C serial communications interfaces 5. Auxiliary I2C serial interface for 3rd party magnetometer & other sensors 第三方磁强计和其他传感器 6. Clocking 7. Sensor Data Registers 8. FIFO 9. Interrupts 10. Digital-Output Temperature Sensor 11. Gyroscope & Accelerometer Self-test 12. Bias and LDO 13. Charge Pump6 Electrical Characteristics 6.1 Gyroscope SpecificationsVDD = 2.375V-3.46V, VLOGIC (MPU-6050 only) = 1.8V±5% or VDD, TA = 25°C6.2 Accelerometer SpecificationsVDD = 2.375V-3.46V, VLOGIC (MPU-6050 only) = 1.8V±5% or VDD, TA = 25°C7.7 Three-Axis MEMS Gyroscope with 16-bit ADCs and Signal ConditioningThe MPU-60X0 consists of three independent vibratory 振动的 MEMS rate gyroscopes, which detect 侦察 rotation 转动 about the X-, Y-, and Z- Axes. When the gyros are rotated about any of the sense axes, the Coriolis科里奥利(法国数学家)Effect causes a vibration that is detected by a capacitive pickoff 这是由一个电容式传感器检测. The resulting signal is amplified, demodulated, and filtered 由此产生的信号经放大, 解调, 滤波 to produce a voltage that is proportional 比例的 to the angular rate 角速度. This voltage is digitized 数字化 using individual on-chip 单个芯片 16-bit Analog-to-Digital Converters (ADCs) to sample each axis. The full-scale range of the gyro sensors may be digitally programmed to ±250, ±500, ±1000, or ±2000 degrees per second (dps). The ADC sample rate is programmable from 8,000 samples per second, down to 3.9 samples per second ADC 的采样 率可从每秒 8000 个样本,到每秒 3.9 个样本, and user-selectable 用户可选择的 low-pass filters enable a wide range of cut-off frequencies 宽范围的截止频率。.7.8 Three-Axis MEMS Accelerometer with 16-bit ADCs and Signal ConditioningThe MPU-60X0’s 3-Axis accelerometer uses separate proof masses for each axis. Acceleration along(prep. 沿着;顺着)a particular axis induces 感应, 引起 displacement 替代 on the corresponding 对应的 proof mass, and capacitive 电容性的 sensors detect 侦查 the displacement differentially. The MPU-60X0’s architecture 体系结构 reduces 减少 the accelerometers’ susceptibility易受影响或损害的状态 to fabrication(n.制造)variations 变化 as well as to thermal 温热的 drift 漂移.When the device is placed on a flat surface, it will measure 0g on the X- and Y-axes and +1 g on the Z-axis. The accelerometers’ scale factor is calibrated at the factory 该加速度计标度因数是在工厂校 准 and is nominally independent of supply voltage 独立的电源电压. Each sensor has a dedicated sigma-delta ADC for providing 每个传感器都有一个专门的 ADC 提供 digital outputs. The full scale range of the digital output can be adjusted to ± 2 g, ± 4g, ± 8g, or ± 16g.7.9 Digital Motion ProcessorThe embedded Digital Motion Processor 嵌入式数字运动处理器(DMP) is located within the MPU-60X0 and offloads 卸货 computation 计算 of motion processing 运动处理 algorithms 运算法则 from the host processor 主处理机.The DMP acquires data from accelerometers, gyroscopes, and additional 3rd party sensors such as magnetometers (n. 磁力计), and processes the data 处理数据. The resulting data can be read from the DMP’s registers, or can be buffered in a FIFO. The DMP has access to one of the MPU’s external pins, which can be used for generating interrupts. The purpose of the DMP is to offload both timing requirements and processing power from the host processor. Typically, motion processing algorithms 运算法则 should be run at a high rate, often around 200Hz, in order to provide accurate 精确的 results with low latency 低延迟. This is required even if 即使 the application updates at a much lower for example, a low power user interface 低功率的用户界面 may update as slowly as 5Hz, but the motion processing should still run at 200Hz. The DMP can be used as a tool in order to minimize power, simplify timing, simplify the software architecture, and save valuable MIPS on the host processor for use in the application. DMP 可以作为一个工具,以降低功耗,简化时序,简化软件结构,节省了宝贵的 MIPS 为在应用程序中使用的主处理器。7.10 Primary I2C and SPI Serial Communications InterfacesThe MPU-60X0 communicates to a system processor using either a SPI (MPU-6000 only) or an I2C serial interface. The MPU-60X0 always acts as a slave when communicating to the system processor. The LSB of the of the I2C slave address is set by pin 9 (AD0).The logic levels for communications between the MPU-60X0 and its master are as follows: MPU-6050: The logic level for communications with the master is set by the voltage on VLOGIC For further information regarding the logic levels of the MPU-6050, please refer to Section 10.7.11 Auxiliary I2C Serial InterfaceThe MPU-60X0 has an auxiliary I2C bus for communicating to an off-chip 3-Axis digital output magnetometer 片外 三轴数字输出磁强计 or other sensors. This bus has two operating modes: ??I2C Master Mode: The MPU-60X0 acts as a master to any external sensors connected to the auxiliary I2C bus 2. Pass-Through Mode 通过模式: The MPU-60X0 directly connects the primary and auxiliary I2C buses together, allowing the system processor to directly communicate with any external sensors. Auxiliary I2C Bus Modes of Operation: 1. I2C Master Mode: Allows the MPU-60X0 to directly access the data registers of external digital sensors, such as a magnetometer. In this mode, the MPU-60X0 directly obtains data from auxiliary sensors, allowing the on-chip DMP to generate 形成 sensor fusion 融合 data without intervention 介入,干涉 from the system applications processor. For example, In I 2C Master mode, the MPU-60X0 can be configured to perform burst reads, returning the following data from a magnetometer: 在 I2C 主模式,该 mpu-60x0 可以配置成执行突发读取,从磁强计 返回以下数据: X magnetometer data (2 bytes);Y magnetometer data (2 bytes);Z magnetometer data (2 bytes) The I2C Master can be configured to read up to 24 bytes from up to 4 auxiliary sensors. A fifth sensor can be configured to work single byte read/write mode. I2C 主可以配置为从 4 辅助传感器读取 24 个字节。五 分之一传感器可以单字节读/写模式。 2. Pass-Through Mode: Allows an external system processor to act as master and directly communicate to the external sensors connected to the auxiliary I2C bus pins (AUX_DA and AUX_CL). In this mode, the auxiliary I 2C bus control logic (3rd party sensor interface block) of the MPU-60X0 is disabled, and the auxiliary I 2C pins AUX_DA and AUX_CL (Pins 6 and 7) are connected to the main I 2C bus (Pins 23 and 24) through analog switches. Pass-Through Mode is useful for configuring the external sensors, or for keeping the MPU-60X0 in a low-power mode when only the external sensors are used. In Pass-Through Mode the system processor can still access MPU-60X0 data through the I 2C interface. Auxiliary I2C Bus IO Logic Levels MPU-6050: The logic level of the auxiliary I2C bus can be programmed to be either VDD or VLOGIC 该辅助 I2C 总 线的逻辑电平可编程为 VDD 或 Vlogic For further information regarding the MPU-6050’s logic levels, please refer to Section 10.2.7.12 Self-TestPlease refer to the MPU-6000/MPU-6050 Register Map and Register Descriptions document for more details on self test. Self-test allows for the testing of the mechanical and electrical portions of the sensors. The self-test for each measurement axis can be activated by means of 通过 the gyroscope and accelerometer self-test registers(registers 13 to 16). When self-test is activated, the electronics cause the sensors to be actuated and produce an output signal. 当 自检被激活,电子使传感器被驱动并产生一个输出信号。The output signal is used to observe the self-test response. The self-test response is defined as follows: Self-test response = Sensor output with self-test enabled C Sensor output without self-test enabled The self-test response for each accelerometer axis is defined in the accelerometer specification table 加速度计规 格表(Section 6.2), while that for each gyroscope axis is defined in the gyroscope specification table (Section 6.1). When the value of the self-test response is within the min/max limits of the product specification, the part has passed self test. When the self-test response exceeds the min/max values, the part is deemed to have failed self-test. Code for operating self test code is included within the MotionApps software provided by InvenSense.7.13 MPU-60X0 Solution for 9-axis Sensor Fusion 融合 Using I2C InterfaceIn the figure below 在下面的图中, the system processor is an I 2C master to the MPU-60X0. In addition, the MPU-60X0 is an I2C master to the optional external compass sensor. The MPU-60X0 has limited capabilities 能力 as an I 2C Master, and depends on the system processor to manage the initial 最初的 configuration of any auxiliary sensors. The MPU-60X0 has an interface 接口 bypass 旁道,支路 multiplexer 多路 (复用) 器, which connects the system processor I 2C bus pins 23 and 24 (SDA and SCL) directly to the auxiliary sensor I 2C bus pins 6 and 7 (AUX_DA and AUX_CL). Once the auxiliary sensors have been configured by the system processor 一旦辅助传感器已由系统的处理器配 置配置,the interface bypass multiplexer should be disabled so that the MPU-60X0 auxiliary I 2C master can take control of the sensor I2C bus and gather data from the auxiliary sensors. For further information regarding I2C master control, please refer to Section 10. 7.15 Internal Clock Generation 内部时钟产生The MPU-60X0 has a flexible 灵活的 clocking scheme 体系, allowing a variety of internal or external clock sources to be used for the internal synchronous 同步 circuitry 电路. This synchronous circuitry includes the signal conditioning 信号调理 and ADCs, the DMP, and various control circuits and registers. 该同步电路包括信 号调理和模数转换器,DMP,和各种控制电路和寄存器。 An on-chip PLL provides flexibility in the allowable inputs for generating this clock.其时钟可由一个片上的 PLL 产生。 Allowable internal sources for generating the internal clock are: 1. An internal relaxation oscillator 张弛振荡器 2. Any of the X, Y, or Z gyros (MEMS oscillators with a variation of ±1 % over temperature) Allowable external clocking sources are: 1.32.768kHz square wave 2. 19.2MHz square wave Selection of the source for generating the internal synchronous clock depends on the availability of external sources and the requirements for power consumption 消费 and clock accuracy 精度. These requirements will most likely 最有可能 vary by mode of operation. For example, in one mode, where the biggest concern is power consumption, the user may wish to operate the Digital Motion Processor of the MPU-60X0 to process accelerometer data, while keeping the gyros off. In this case, the internal relaxation oscillator is a good clock choice. However, in another mode, where the gyros are active, selecting the gyros as the clock source provides for a more accurate clock source. Clock accuracy is important, since timing errors directly affect the distance and angle calculations performed by the Digital Motion Processor (and by extension, by any processor). There are also start-up conditions to consider. When the MPU-60X0 first starts up, the device uses its internal clock until programmed to operate from another source. This allows the user, for example, to wait for the MEMS oscillators to stabilize before they are selected as the clock source.7.16 Sensor Data RegistersThe sensor data registers contain the latest gyro, accelerometer, auxiliary sensor, and temperature measurement 量度 data. They are read-only registers, and are accessed via the serial interface. 传感器数据寄存器包含最新的 陀螺仪, 加速度计, 辅助传感器, 和温度测量数据。 他们是只读寄存器, 并通过串行接口访问。 Data from these registers may be read anytime. However, the interrupt function may be used to determine when new data is available. 然而,当新数据可用中断函数可以用于确定。For a table of interrupt sources please refer to Section 8.7.17 FIFOThe MPU-60X0 contains a 1024-byte FIFO register that is accessible via 经过 the Serial Interface. The FIFO(firstin, first out)configuration register determines which data is written into the FIFO. mpu-60x0 包含一个 1024 字节的 FIFO 寄存器,可通过串行接口。先进先出配置寄存器确定哪些数据写入 FIFO。 Possible choices include gyro data, accelerometer data, temperature readings, auxiliary sensor readings, and FSYNC input. 可能的选择包 括陀螺加速度计数据,数据,温度读数,辅助传感器的读数,和 FSYNC 输入。 A FIFO counter keeps track of how many bytes of valid data are contained in the FIFO FIFO 计数器跟踪有效数据有多少字节都包含在 FIFO。 . The FIFO register supports burst reads. The interrupt function may be used to determine when new data is available. FIFO 寄存器支持突发读。当新数据可用中断函数可以用于确定 For further information regarding the FIFO, please refer to the MPU-6000/MPU-6050 Register Map and Register Descriptions document.7.18 InterruptsInterrupt functionality is configured via the Interrupt Configuration register. 中断功能是通过中断配置寄存器进 行配置 Items that are configurable include the INT pin configuration, the interrupt latching and clearing method, and triggers for the interrupt. 这是可配置的项目包括 INT 引脚配置,中断锁存和清除方法,以及中断触发。 Items 项目 that can trigger an interrupt are (1) Clock generator locked to new reference oscillator (used when switching clock sources); 时钟发生器锁定新的参考振荡器(时钟源切换时使用) ; (2) new data is available to be read (from the FIFO and Data registers); 新的数据可以被读取(从 FIFO 数据寄存器) ; (3) accelerometer event interrupts 加速度传感器事件中断; (4) the MPU-60X0 did not receive an acknowledge from an auxiliary sensor on the secondary 第二的 I2C bus. The interrupt status can be read from the Interrupt Status register. 6050 没有收到外接传感器的应答信号(辅助 I2C 总线) 。中断状态可以从中断状态寄存器读。For further information regarding interrupts, please refer to the MPU-60X0 Register Map and Register Descriptions document. For information regarding the MPU-60X0’s accelerometer event interrupts, please refer to Section 8.7.19 Digital-Output Temperature SensorAn on-chip temperature sensor and ADC are used to measure the MPU-60X0 die temperature. 一个片上温度传 感器和 ADC 用于测量 mpu-60x0 模具温度 The readings from the ADC can be read from the FIFO or the Sensor Data registers. 来自 ADC 的读数可以从 FIFO 或传感器数据寄存器读取。8.1 自由落体中断通过检测 3 个轴上的加速度测量值是否在规定的阈值内来判断自由落体运动。对每一次的采样值,如 果没达到阈值将会被忽略。一旦达到阈值,即触发自由落体中断。并产生标志位。直到计数器降到 0,标 志才会被清除。计数器的取值范围在 0 和规定的阈值之间。 可用 FF_THR 寄存器设置阈值,精确到 1mg 。用 FF_DUR 寄存器设置持续时间,精确到 1ms 。 使用 MOT_DETECT_CTRL 寄存器可以设施是否用一个无效的采样值使计数器清零,或者以 1,2,4 的量衰减。8.2 Motion Interrupt(运动中断)The MPU-60X0 provides Motion detection 侦查 ; 察觉 capability. Accelerometer measurements are passed through a configurable digital high pass filter (DHPF) in order to eliminate bias due to gravity. mpu-60x0 提供运动检测能力。为了消除由于重力偏差,加速度计的测量是通过一个可配置的数字高通滤波 器(DHPF) 。 A qualifying motion sample is one where the high passed sample from any axis has an absolute value exceeding a user programmable threshold. A counter increments for each qualifying sample 通过高通滤波器的 绝对值超过一个用户可编程的阈值。则被认定是有效的对于每个有效的采样值,计数器加 1 而对于无效的 值,则计数器减 1., and decrements for each non qualifying sample. Once the counter reaches a user-programmable counter threshold, a motion interrupt is triggered. The axis and polarity which caused the interrupt to be triggered is flagged in the MOT_DETECT_STATUS register. 一旦计数器达到用户可编程计数器阈 值,运动中断触发。产生运动中断的轴及其方向在 MOT_DETECT_STATUS register 读出。Motion detection has a configurable acceleration threshold MOT_THR specified in 1 mg increments. 运动检测有一个可配置的阈值加 速度 MOT_THR 精确到 1ms。 The counter threshold MOT_DUR is specified in 1 ms increments. 计数器的 MOT_DUR 阈值在 1 毫秒的增量指定 。The decrement rate for non-qualifying samples is also configurable. The MOT_DETECT_CTRL register allows the user to specify whether a non-qualifying sample makes the counter reset to zero, or decrement in steps of 1, 2, or 4. 不合格样品的减量率也可配置。MOT_DETECT_CTRL 的寄存器允许 用户指定是否不合格样品使计数器复位到零,或递减 1,2,或 4。 The flow chart below explains how the motion interrupt should be used. Please refer to the MPU-6000/MPU 6050 Register Map and Register Descriptions document for descriptions of the registers referenced in the flow chart.9.2 I2C InterfaceI2C is a two-wire interface comprised of the signals serial data (SDA) and serial clock (SCL). In general, the lines are open-drain and bi-directional I2C 是一个双线接口组成的信号的串行数据 (SDA) 和串行时钟 (SCL) 。 一般来说,这线是开漏双向。. In a generalized I 2C interface implementation, attached devices can be a master or a slave. The master device puts the slave address on the bus, and the slave device with the matching address acknowledges the master.10.2The power-on-reset value for AUX_VDDIO is 0. VLOGIC may be set to be equal to VDD or to another voltage. However, VLOGIC must be ≤ VDD at all times. When AUX_VDDIO is set to 0 (its power-on-reset value), VLOGIC is the power supply voltage for both the microprocessor system bus and the auxiliary I2C bus, as shown in the figure of Section 10.3. When AUX_VDDIO is set to 1, VLOGIC is the power supply voltage for the microprocessor system bus and VDD is the supply for the auxiliary I2C bus, as shown in the figure of Section 10.4. Note 2.3rd-party auxiliary device logic levels are referenced to VDD. Setting INT1 and INT2 to open drain configuration provides voltage compatibility when VDD ≠ VLOGIC. When VDD = VLOGIC, INT1 and INT2 may be set to push-pull outputs, and external pull-up resistors are not needed. 第三方辅助设备的逻辑水 平参照 VDD。当 VDD≠Vlogic,设置 INT1 和 INT2 到漏极开路配置提供电压兼容。 当 VDD = Vlogic,INT1 和 INT2 可以设置为推挽输出,而不需要外部上拉电阻。找出几个重要的寄存器: 1) Register 25 C Sample Rate Divider (SMPRT_DIV)SMPLRT_DIV 8 位无符号值,通过该值将陀螺仪输出分频, 得到采样频率。 该寄存器指定陀螺仪输出率的分频, 用来产生 MPU-60X0 的采样率。传感器寄存器的输出、FIFO 输出、DMP 采样和运动检测的都是基于该采样 率。采样率的计算公式 采样率 = 陀螺仪的输出率 / (1 + SMPLRT_DIV) 当数字低通滤波器没有使能的时候,陀螺仪的输出频率等于 8KHZ,反之等于 1KHZ。 2)Register 26 C Configuration(CONFIG)1)EXT_SYNC_SET 3 位无符号值,配置帧同步引脚的采样 2)DLPF_CFG 3 位无符号值,配置数字低通滤波器 该寄存器为陀螺仪和加速度计配置外部帧同步(FSYNC)引脚采样和数字低通滤波器(DLPF) 。通过配置 EXT_SYNC_SET,可以对连接到 FSYNC 引脚的一个外部信号进行采样。 FSYNC 引脚上的信号变化会被锁存, 这样就能捕获到很短的频闪信号。 采样结束后,锁存器将复位到当前的 FSYNC 信号状态。 根据下面的表格 定义的值,采集到的数据会替换掉数据寄存器中上次接收到的有效数据。数字低通滤波器是由 DLPF_CFG 来配置,根据下表中 DLPF_CFG 的值对加速度传感器和陀螺仪滤波3)Register 27 C Gyroscope Configuration(GYRO_CONFIG) 1)XG_ST 设置此位,X 轴陀螺仪进行自我测试。 2)YG_ST 设置此位,Y 轴陀螺仪进行自我测试。 3)ZG_ST 设置此位,Z 轴陀螺仪进行自我测试。 4)FS_SEL 2 位无符号值。选择陀螺仪的量程。 这个寄存器是用来触发陀螺仪自检和配置陀螺仪的满量程范围。陀螺仪自检允许用户测试陀螺仪的机械和 电气部分,通过设置该寄存器的 XG_ST、YG_ST 和 ZG_ST bits 可以激活陀螺仪对应轴的自检。每个轴的检 测可以独立进行或同时进行。 自检的响应 = 打开自检功能时的传感器输出 - 未启用自检功能时传感器的输出 在 MPU-6000/MPU-6050 数据手册的电气特性表中已经给出了每个轴的限制范围。当自检的响应值在规定的 范围内,就能够通过自检;反之,就不能通过自检。 根据下表,FS_SEL 选择陀螺仪输出的量程:4)Register 28 C Accelerometer Configuration(ACCEL_CONFIG)1)XA_ST 2)YA_ST 3)ZA_ST 4)AFS_SEL设置为 1 时,X 轴加速度感应器进行自检。 设置为 1 时,Y 轴加速度感应器进行自检。 设置为 1 时,Z 轴加速度感应器进行自检。 2 位无符号值。选择加速度计的量程。具体细节和上面陀螺仪的相似。 根据下表,AFS_SEL 选择加速度传感器输出的量程。5)Registers 59 to 64 C Accelerometer Measurements (ACCEL_XOUT_H, ACCEL_XOUT_L, ACCEL_YOUT_H, ACCEL_YOUT_L, ACCEL_ZOUT_H, and ACCEL_ZOUT_L )1)ACCEL_XOUT 16 位 2’s 补码值。 存储最近的 X 轴加速度感应器的测量值。 2)ACCEL_YOUT 16 位 2’s 补码值。 存储最近的 Y 轴加速度感应器的测量值。 3)ACCEL_ZOUT 16 位 2’s 补码值。 存储最近的 Z 轴加速度感应器的测量值。 这些寄存器存储加速感应器最近的测量值。加速度传感器寄存器,连同温度传感器寄存器、陀螺仪传感器 寄存器和外部感应数据寄存器,都由两部分寄存器组成(类似于 STM32F10X 系列中的影子寄存器):一个 内部寄存器,用户不可见。另一个用户可读的寄存器。内部寄存器中数据在采样的时候及时的到更新,仅 在串行通信接口不忙碌时,才将内部寄存器中的值复制到用户可读的寄存器中去,避免了直接对感应测量 值的突发访问。 在寄存器 28 中定义了每个 16 位的加速度测量值的最大范围,对于设置的每个最大范围,都对应一个加速 度的灵敏度 ACCEL_xOUT,如下面的表中所示: 6)Registers 65 and 66 C Temperature Measurement(TEMP_OUT_H and TEMP_OUT_L)1)TEMP_OUT 16 位有符号值。 储的最近温度传感器的测量值。 7)Registers 67 to 72 C Gyroscope Measurements GYRO_YOUT_L, GYRO_ZOUT_H, and GYRO_ZOUT_L) (GYRO_XOUT_H, GYRO_XOUT_L, GYRO_YOUT_H,这个和加速度感应器的寄存器相似 对应的灵敏度:8)Register 107 C Power Management 1(PWR_MGMT_1)该寄存器允许用户配置电源模式和时钟源。它还提供了一个复位整个器件的位,和一个关闭温度传感器的 位 1)DEVICE_RESET 2)SLEEP 3)CYCLE置 1 后所有的寄存器复位,随后 DEVICE_RESET 自动置 0. 置 1 后进入睡眠模式 当 CYCLE 被设置为 1,且 SLEEP 没有设置,MPU-60X0 进入循环模式,为了从速度传感器中获得采样值, 在睡眠模式和正常数据采集模式之间切换, 每次获得一个采样数据。 在 LP_WAKE_CTRL (108) 寄存器中,可以设置唤醒后的采样率和被唤醒的频率。 4)TEMP_DIS 5)CLKSEL 时钟源的选择: 置 1 后关闭温度传感器 指定设备的时钟源9)Register 117 C Who Am I(WHO_AM_I)WHO_AM_I 中的内容是 MPU-60X0 的 6 位 I2C 地址。上电复位的第 6 位到第 1 位值为:110100。为了让两个 MPU-6050 能够连接在一个 I2C 总线上,当 AD0 引脚逻辑低电平时,设备的地址是 b1101000 ,当 AD0 引脚 逻辑高电平时, 设备的地址是 b1101001。 MPU-6000 可以使用 SPI 和 I2C 接口, 而 MPU-6050 只能使用 I2C, 其中 I2C 的地址由 AD0 引脚决定。寄存器共 117 个,挺多的,下面的是精简常用的,根据具体的要求,适 当的添加。 #define SMPLRT_DIV #define CONFIG #define GYRO_CONFIG 0x19 0x1B //采样率分频,典型值:0x07(125Hz) */ // 低通滤波频率,典型值:0x06(5Hz) */ // 陀螺仪自检及测量范围,典型值:0x18(不自检,2000deg/s) */0x1A #define ACCEL_CONFIG 0x1C // 加速计自检、 测量范围及高通滤波频率, 典型值: 0x01(不自检, 2G, 5Hz) */ #define ACCEL_XOUT_H 0x3B // 存储最近的 X 轴、Y 轴、Z 轴加速度感应器的测量值 */ #define ACCEL_XOUT_L 0x3C #define ACCEL_YOUT_H 0x3D #define ACCEL_YOUT_L 0x3E #define ACCEL_ZOUT_H 0x3F #define ACCEL_ZOUT_L 0x40 #define TEMP_OUT_H #define TEMP_OUT_L #define GYRO_XOUT_H #define GYRO_XOUT_L #define GYRO_YOUT_H #define GYRO_YOUT_L #define GYRO_ZOUT_H #define GYRO_ZOUT_L #define PWR_MGMT_1 #define WHO_AM_I 0x41 0x42 0x43 // 存储最近的 X 轴、Y 轴、Z 轴陀螺仪感应器的测量值 */ 0x44 0x45 0x46 0x47 0x48 0x6B // 电源管理,典型值:0x00(正常启用) */ 0x75 //IIC 地址寄存器(默认数值 0x68,只读) */ // 存储的最近温度传感器的测量值 */1.2. 本模块采用的是 IIC 通信方式,所以我们只需要连接四跟线就可以完成电路的连接 A4 接 SDA,A5 接 SCL, VCC 接 3v3,GND 接 GND MPU6050_raw 这个代码是没有添加算法的,所以显示的是只是原始数据!我们可以通过串 口监视串口可以看到这样的结果! 仔细观察了一下, 这些误差都分布在某个常数的周围, 下面就可以通过一个简单的方法对其 进行校准。从数据手册中找到刻度系数表,用输出值除以这些刻度系数即可得到以°/s 为单 位的角速度和以 g 为单位的加速度输出#include &Wire.h& #include &I2Cdev.h& #include &MPU6050.h& MPU6050int16_t ax, ay, int16_t gx, gy,bool blinkState =void setup() {Wire.begin(); Serial.begin(38400); accelgyro.initialize(); } void loop() { accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); Serial.print(&a/g:\t&); Serial.print(ax/16384); Serial.print(&\t&); Serial.print(ay/16384); Serial.print(&\t&); Serial.print(az/16384); Serial.print(&\t&); Serial.print(gx/131); Serial.print(&\t&); Serial.print(gy/131); Serial.print(&\t&); Serial.println(gz/131); blinkState = !blinkS } 校准的方法 IMU 在水平放置的状态下,Z 轴加速度计的输出应该是 1g,其余轴的加速度计和 陀螺仪的输出均应该为 0。对 1000 个输出值的误差取平均,利用其对输出进行 校准.
同时增加将输出值进行换算的算法 观察输出值,可以看到常数误差已经基本被消除了,剩下的都些是较小的随机误差

我要回帖

更多关于 mpu6050中文数据手册 的文章

 

随机推荐