MPU6050: Data Read (I2C)

The tutorial demonstration software simulates I2C communication to read the DMP data of MPU6050, then solves the data and prints it out on the serial port.

Hardware connection

image-20240822181904403

Just install it to the corresponding interface:

PeripheralsDevelopment BoardDescription
MPU6050: VCC5VOLED power supply
MPU6050: GNDGNDOLED common ground
MPU6050: SCLPB10Software I2C: Serial clock line (SDA) (pull-up resistor is connected to the module)
MPU6050: SDAPB11Software I2C: Serial data line (SCL) (pull-up resistor is connected to the module)
MPU6050: XDANot connectedI2C master serial data signal line, used for external sensors (pull-up resistors have been connected to the module)
MPU6050: XCLNot connectedI2C master serial clock signal line, used for external sensors (pull-up resistors have been connected to the module)
MPU6050: AD0Not connectedSlave address setting pin: 1. When grounded or floating, the address is 0x68; 2. When connected to VCC, the address is 0x69
MPU6050: INTPA12Interrupt output pin

Control principle

The software simulates I2C to obtain DMP data and calculates the pitch, roll, and heading angles.

ProductMPU6050
Communication methodIIC
Transmission rate400kHz (Max)
Output informationRotation matrix, quaternion, Euler angle
ADC bit number16-bit data output
Gyroscope range±250°, ±500°, ±1000°, ±2000° / s
Acceleration range±2, ±4, ±8, ±16 G
External interfaceExternal magnetometer module
InterruptINT interrupt trigger pin

image-20240806150245483

Basic functions

The attitude sensor integrates a three-axis gyroscope, a three-axis accelerometer, and a temperature sensor.

Three-axis gyroscope: can measure the angular velocity around the X, Y, and Z axes, and is used to detect the rotation and turning movement of an object.

Three-axis accelerometer: can measure the acceleration in the X, Y, and Z axis directions, including the acceleration of gravity and the linear acceleration of the object.

Temperature sensor: MPU6050 also integrates a temperature sensor that can measure the temperature of the environment.

Pin definition

Main control chipPinMain function (after reset)Default multiplexing functionRedefine function
STM32F103RCT6PB10PB10I2C2_SCL/USART3_TXTIM2_CH3
STM32F103RCT6PB11PB11I2C2_SDA/USART3_RXTIM2_CH4
STM32F103RCT6PA12PA12USART1_RTS/USBDP/CAN_TX/TIM1_ETR 

Software code

Since the tutorial is software simulation of I2C, the default pin function can be used.

Control function

The tutorial only briefly introduces the code, and you can open the project source code to read it in detail.

IIC_MPU6050_Init

MPU6050_initialize

DMP_Init

MPU6050_EXTI_Init

Experimental phenomenon

The MPU6050.hex file generated by the project compilation is located in the OBJ folder of the MPU6050 project. Find the MPU6050.hex file corresponding to the project and use the FlyMcu software to download the program to the development board.

After the program is successfully downloaded: the serial port will receive the data calculated by MPU6050.

image-20240808193540479