Welcome to MSPM0 Smart Robot Car repository
10.MPU6050 raw data acquisition
MPU6050 Raw Data Acquisition
MPU6050 Raw Data Acquisition1. Software and Hardware2. Basic Principles2.1 Hardware Schematic2.2 Physical Connection Diagram2.3 Control Principle3. Project Configuration3.1 Description3.2 Pin Configuration4. Main Functions4.1 User Functions5. Experimental Phenomenon
This tutorial demonstrates: how to obtain and print MPU6050 raw data through serial port.
1. Software and Hardware
KEIL5
MSPM0G3507 Development Board
MPU6050 Module
Type-C data cable or DAP-Link
For programming download or simulation to the development board
Serial Port Assistant
Receive and print serial port data
2. Basic Principles
2.1 Hardware Schematic
.png)
2.2 Physical Connection Diagram
.png)
2.3 Control Principle
| (Schematic Name) | Control Pin | Specific Meaning |
|---|---|---|
| I2C2_SCL | PA1 | I2C Clock End |
| I2C2_SDA | PA0 | I2C Data End |
I2C Communication:
Start Signal: The processor keeps the SCL clock high, then lets the SDA data signal go from high to low to indicate a start signal. At the same time, devices on the I2C bus detect this start signal and know that the processor is about to send data.
Stop Signal: The processor keeps the SCL clock high, then lets the SDA data signal go from low to high to indicate a stop signal. At the same time, devices on the I2C bus detect this stop signal and know that the processor has finished data transmission, and we can each go about our business, such as sleep, etc.

To read the value of MPU6050 registers, first the master device generates a start signal (S), then sends the slave device address bit and a write data bit, then sends the register address, before starting to read the register. Immediately after receiving the acknowledgment signal, the master device sends another start signal, then sends the slave device address bit and a read data bit. Then, the MPU6050 as the slave device generates an acknowledgment signal and starts sending register data. Communication ends with a not-acknowledge signal (NACK) and end flag (P) generated by the master device. The not-acknowledge signal (NACK) is defined as SDA data remaining high during the 9th clock cycle.
MPU6050 Module:
The MPU-6050 is an integrated 6-axis motion processing component. Compared to multi-component solutions, it eliminates the problem of axis differences when combining gyroscopes and accelerometers, reducing a large amount of packaging space. The MPU-6050 integrates a 3-axis gyroscope and 3-axis accelerometer, and includes a digital motion processing (DMP: Digital Motion Processor) hardware acceleration engine that can connect other brands of accelerometers, magnetic sensors, or other sensors through a second I2C port, outputting complete 9-axis fusion calculation technology to the application end in the form of a single data stream from the main I2C port.
MPU6050 Module Features:
- Digital output of 6-axis or 9-axis rotation matrix, quaternion, Euler angle format fusion calculation data.
- 3-axis angular velocity sensor (gyroscope) with 131 LSBs/°/sec sensitivity and full-scale sensing range of ±250, ±500, ±1000 and ±2000°/sec.
- Programmable control 3-axis accelerometer with control range of ±2g, ±4g, ±8g and ±16g.
- Removes sensitivity between accelerometer and gyroscope axes, reducing the impact of setup and sensor drift.
- Digital Motion Processing (DMP) engine can reduce the load of complex fusion calculation data, sensor synchronization, posture sensing, etc.
- Motion processing database supports Android, Linux and Windows
- Digital output temperature sensor
- Digital input synchronization pin (Sync pin) supports video electronic image stabilization technology and GPS
- Programmable interrupts support posture recognition, panning, picture zoom in/out, scrolling, fast drop interrupt, high-G interrupt, zero motion sensing, tap sensing, shake sensing functions
- VCC supply voltage is 3.3V or 5.0V
- Gyroscope operating current: 5mA, gyroscope standby current: 5uA; accelerometer operating current: 350uA, accelerometer power-saving mode current: 20uA@10Hz
- Up to 400kHz fast mode I2C, or up to 20MHz SPI serial host interface
- Built-in frequency generator has only ±1% frequency variation over full temperature range
Parameter information is as follows:

3. Project Configuration
3.1 Description
You can refer to the basic tutorial to complete the development environment setup.
3.2 Pin Configuration



4. Main Functions
4.1 User Functions
Function: Get_EulerAngles()
| Function Prototype | void Get_EulerAngles(void) |
|---|---|
| Function Description | Get MPU6050 data and send through serial port |
| Input Parameters | None |
| Return Value | None |
Function: MPU6050_Init
| Function Prototype | char MPU6050_Init(void) |
|---|---|
| Function Description | MPU6050 initialization |
| Input Parameters | None |
| Return Value | Judge whether MPU6050 is detected |
5. Experimental Phenomenon
After downloading the program, open the serial port assistant and set the parameters as shown in the figure below. Then open the serial port to receive the raw data of MPU6050.
For program download, refer to 【3. Development Environment Setup and Usage: 3. Uniflash burning】
The effect is as follows:
