11. Nine-axis attitude sensor to obtain data 11.1. Experimental purpose 11.2. Configuration pin information 11.3. Analysis of the experimental flow chart 11.4. core code explanation 11.5. Hardware connection 11.6. Experimental effect
Use the GPIO port of STM32 to simulate IIC communication, read the raw data of the nine-axis attitude sensor MPU9250, and print it out through the serial port assistant.
According to the schematic diagram, the SDA/SDI pin of the nine-axis attitude sensor is connected to PB15, the SCL/SCLK pin is connected to PB13, and the AD0/SDO pin is connected to PB14.






According to the content of the IIC protocol, MPU_IIC_Start() generates the IIC start signal, and MPU_IIC_Stop() generates the IIC stop signal.

3.IIC response correlation function.

4.IIC send and read data related functions.


Pull the AD0 pin low to make the ID of the MPU6500 0x68.

Initialize MPU9250, return value: 0, success, other, error code

Read the gyroscope value (original value), return value: 0, success, other, error code

Read acceleration value (original value), return value: 0, success, other, error code

Read magnetometer value (raw value), return value: 0, success, other, error code

Read and print data, called every 10ms.



The MPU9250 nine-axis attitude sensor has been soldered on the expansion board, so there is no need to manually connect the device.

After the program is programmed, the LED light flashes every 200 milliseconds. Open the serial port assistant (the parameters are as shown in the figure below), you can see that the serial port assistant has been printing the data of the MPU9250's accelerometer accel, gyroscope gyro, and magnetometer mag.
