|
|
|
|
#ifndef __MPU6050_H
|
|
|
|
|
#define __MPU6050_H
|
|
|
|
|
#include "mpuiic.h"
|
|
|
|
|
|
|
|
|
|
//#define MPU_ACCEL_OFFS_REG 0X06 //accel_offs<EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>,<EFBFBD>ɶ<EFBFBD>ȡ<EFBFBD>汾<EFBFBD><EFBFBD>,<EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֲ<EFBFBD>δ<EFBFBD>ᵽ
|
|
|
|
|
//#define MPU_PROD_ID_REG 0X0C //prod id<EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>,<EFBFBD>ڼĴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֲ<EFBFBD>δ<EFBFBD>ᵽ
|
|
|
|
|
#define MPU_SELF_TESTX_REG 0X0D //<EFBFBD>Լ<EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>X
|
|
|
|
|
#define MPU_SELF_TESTY_REG 0X0E //<EFBFBD>Լ<EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>Y
|
|
|
|
|
#define MPU_SELF_TESTZ_REG 0X0F //<EFBFBD>Լ<EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>Z
|
|
|
|
|
#define MPU_SELF_TESTA_REG 0X10 //<EFBFBD>Լ<EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>A
|
|
|
|
|
#define MPU_SAMPLE_RATE_REG 0X19 //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD>ʷ<EFBFBD>Ƶ<EFBFBD><EFBFBD>
|
|
|
|
|
#define MPU_CFG_REG 0X1A //<EFBFBD><EFBFBD><EFBFBD>üĴ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
#define MPU_GYRO_CFG_REG 0X1B //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD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U_I2CSLV0_DO_REG 0X63 //IIC<EFBFBD>ӻ<EFBFBD>0<EFBFBD><EFBFBD><EFBFBD>ݼĴ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
#define MPU_I2CSLV1_DO_REG 0X64 //IIC<EFBFBD>ӻ<EFBFBD>1<EFBFBD><EFBFBD><EFBFBD>ݼĴ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
#define MPU_I2CSLV2_DO_REG 0X65 //IIC<EFBFBD>ӻ<EFBFBD>2<EFBFBD><EFBFBD><EFBFBD>ݼĴ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
#define MPU_I2CSLV3_DO_REG 0X66 //IIC<EFBFBD>ӻ<EFBFBD>3<EFBFBD><EFBFBD><EFBFBD>ݼĴ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
#define MPU_I2CMST_DELAY_REG 0X67 //IIC<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
#define MPU_SIGPATH_RST_REG 0X68 //<EFBFBD>ź<EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
#define MPU_MDETECT_CTRL_REG 0X69 //<EFBFBD>˶<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƼĴ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
#define MPU_USER_CTRL_REG 0X6A //<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƼĴ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
#define MPU_PWR_MGMT1_REG 0X6B //<EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFB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FBFBD><EFBFBD>Ϊģ<EFBFBD><EFBFBD>AD0Ĭ<EFBFBD>Ͻ<EFBFBD>GND,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>תΪ<EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>,Ϊ0XD1<EFBFBD><EFBFBD>0XD0(<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>VCC,<EFBFBD><EFBFBD>Ϊ0XD3<EFBFBD><EFBFBD>0XD2)
|
|
|
|
|
//#define MPU_READ 0XD1
|
|
|
|
|
//#define MPU_WRITE 0XD0
|
|
|
|
|
|
|
|
|
|
u8 MPU_Init(void); //<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>MPU6050
|
|
|
|
|
u8 MPU_Write_Len(u8 addr,u8 reg,u8 len,u8 *buf);//IIC<EFBFBD><EFBFBD><EFBFBD><EFBFBD>д
|
|
|
|
|
u8 MPU_Read_Len(u8 addr,u8 reg,u8 len,u8 *buf); //IIC<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
u8 MPU_Write_Byte(u8 reg,u8 data); //IICдһ<EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
|
|
|
|
u8 MPU_Read_Byte(u8 reg); //IIC<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
|
|
|
|
|
|
|
|
|
u8 MPU_Set_Gyro_Fsr(u8 fsr);
|
|
|
|
|
u8 MPU_Set_Accel_Fsr(u8 fsr);
|
|
|
|
|
u8 MPU_Set_LPF(u16 lpf);
|
|
|
|
|
u8 MPU_Set_Rate(u16 rate);
|
|
|
|
|
u8 MPU_Set_Fifo(u8 sens);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
short MPU_Get_Temperature(void);
|
|
|
|
|
u8 MPU_Get_Gyroscope(short *gx,short *gy,short *gz);
|
|
|
|
|
u8 MPU_Get_Accelerometer(short *ax,short *ay,short *az);
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|