<b>1. Initialize IIC interface:</b>
Initialize the SDA and SCL data lines connected to the MPU6050, set AD0 to low level, and then select the I2C address as 0x68.
<b>2. Reset MPU6050:</b>
This step restores all registers inside the MPU6050 to their default values, which is achieved by writing 1 to bit7 of the power management register 1 (0X6B). After reset, the power management register 1 returns to the default value (0X40), and then this register must be set to 0X00 to wake up the MPU6050 and enter the normal working state.
<b>3. Set the full-scale range of the angular velocity sensor (gyro) and acceleration sensor:</b>
In this step, we set the full-scale range (FSR) of the two sensors through the gyroscope configuration register (0X1B) and the acceleration sensor configuration register (0X1C). We generally set the full-scale range of the gyroscope to ±2000dps and the full-scale range of the acceleration sensor to ±2g.
<b>4. Set other parameters:</b>
Here, we also need to configure the parameters: turn off interrupts, turn off the AUX IIC interface, disable FIFO, set the gyroscope sampling rate and set the digital low-pass filter (DLPF), etc. In this chapter, we do not use interrupts to read data, so we turn off interrupts. We do not use the AUXIIC interface to connect other external sensors, so we also turn off this interface. Controlled by interrupt enable register (0X38) and user control register (0X6A) respectively. MPU6050 can use FIFO to store sensor data, but we have not used it in this chapter, so all FIFO channels are closed. This is controlled by the FIFO enable register (0X23). The default value is 0 (that is, FIFO is disabled), so the default value can be used. The gyroscope sampling rate is controlled by the sampling rate division register (0X19). We generally set this sampling rate to 50. The digital low-pass filter (DLPF) is set through the configuration register (0X1A). Generally, the DLPF is set to 1/2 of the bandwidth;
<b>5. Configure the system clock source and enable the angular velocity sensor and acceleration sensor:</b>
The system clock source is also set through power management register 1 (0X1B). The lowest three bits of this register are used to set the system clock source selection. The default value is 0 (internal 8MRC oscillation), but we generally set it to 1 and select the x-axis. Gyro PLL is used as the clock source to obtain a higher precision clock. At the same time, the angular velocity sensor and acceleration sensor are enabled. These two operations are set through the power management register 2 (0X6C). Set the corresponding bit to 0 to enable it;