staticuint8_tMPU_Basic_Init(void){uint8_t res =0;MPU_ADDR_CTRL();/* 设置IIC地址 */MPU_IIC_Init();/* IIC初始化 */MPU_Delay_ms(10);MPU_Write_Byte(MPU9250_ADDR, MPU_PWR_MGMT1_REG,0X80);// Reset MPU9250 //复位MPU9250 /* 1-重置所有寄存器和已经配置数据,重置后此位将自动清 0 */MPU_Delay_ms(100);// Delay 100 ms //延时100msMPU_Write_Byte(MPU9250_ADDR, MPU_PWR_MGMT1_REG,0X00);// Wake mpu9250 //唤醒MPU9250MPU_Set_Gyro_Fsr(1);// Gyroscope sensor //陀螺仪传感器,±500dps=±500°/s ±32768 (gyro/32768*500)*PI/180(rad/s)=gyro/3754.9(rad/s)MPU_Set_Accel_Fsr(0);// Acceleration sensor //加速度传感器,±2g=±2*9.8m/s^2 ±32768 accel/32768*19.6=accel/1671.84MPU_Set_Rate(50);// Set the sampling rate to 50Hz //设置采样率50HzMPU_Write_Byte(MPU9250_ADDR, MPU_INT_EN_REG,0X00);// Turn off all interrupts //关闭所有中断MPU_Write_Byte(MPU9250_ADDR, MPU_USER_CTRL_REG,0X00);// The I2C main mode is off //I2C主模式关闭MPU_Write_Byte(MPU9250_ADDR, MPU_FIFO_EN_REG,0X00);// Close the FIFO //关闭FIFO// The INT pin is low, enabling bypass mode to read the magnetometer directly// INT引脚低电平有效,开启bypass模式,可以直接读取磁力计MPU_Write_Byte(MPU9250_ADDR, MPU_INTBP_CFG_REG,0X82);// Read the ID of MPU9250 读取MPU9250的IDres =MPU_Read_Byte(MPU9250_ADDR, MPU_DEVICE_ID_REG);printf("MPU9250 RD ID=0x%02X\n", res);if(res == MPU9250_ID)// The device ID is correct //器件ID正确{MPU_Write_Byte(MPU9250_ADDR, MPU_PWR_MGMT1_REG,0X01);// Set CLKSEL,PLL X axis as reference //设置CLKSEL,PLL X轴为参考MPU_Write_Byte(MPU9250_ADDR, MPU_PWR_MGMT2_REG,0X00);// Acceleration and gyroscope both work //加速度与陀螺仪都工作MPU_Set_Rate(50);// Set the sampling rate to 50Hz //设置采样率为50Hz}elsereturn1;res =MPU_Read_Byte(AK8963_ADDR, MAG_WIA);// Read AK8963ID //读取AK8963IDprintf("AK8963 RD ID=0x%02X\n", res);if(res == AK8963_ID){MPU_Write_Byte(AK8963_ADDR, MAG_CNTL1,0X11);// Set AK8963 to single measurement mode //设置AK8963为单次测量模式}elsereturn1;MPU_Delay_ms(30);return0;}