Tag Archives: MPU6050 initialize failure

MPU6050 initialize failure [How to Solve]

1. 6050 initialization failed

If 6050 fails to initialize, first check whether the read address is wrong

res=MPU_Read_Byte(MPU_DEVICE_ID_REG);
	printf("mpu addr=%x\r\n",res);
	if(res==MPU_ADDR)//Device ID is correct
	{
		MPU_Write_Byte(MPU_PWR_MGMT1_REG,0X01); //set CLKSEL,PLL X-axis as reference
		MPU_Write_Byte(MPU_PWR_MGMT2_REG,0X00); //Acceleration and gyroscope both work
		MPU_Set_Rate(50); //Set the sampling rate to 50Hz
 	}
	else return 1;

I read out here is 0x68, different connection will also lead to different ID, if the address is correct, that is return 0, here for the initialization of the 6050 initialized through.

2, mpu initialization failure
Mpu initialization failure is common to return error code 8, you can step by step into the source code to analyze.

Solution I.
mpu_dmp_init() -> run_self_test() Here is the self-test, jump into the function can be seen, meaning that it needs to be placed horizontally in order to self-test successfully, so only the module can be placed horizontally, if not directly mask this part of the code can be.

Solution two.
Trace the source code: mpu_dmp_init() -> run_self_test() -> mpu_run_self_test(gyro, accel) -> accel_self_test(accel, accel_st)

Both the initialization is successful only when the absolute value of st_shift_var < the value of test.max_accel_var. And the absolute value of st_shift_var is different for different positions of MPU6050 modules. Only when the module is placed horizontally, the absolute value of st_shift_var is closest to the value of test.max_accel_var, if this parameter is not modified, the module needs to be placed horizontally according to method 1 for testing

Here you can print out the absolute value of st_shift_var and the value of test.max_accel_var when debugging, my solution here is to change the initialization value of test.max_accel_var from 0.14 to 0.16. Then the module will be initialized successfully when the module is placed horizontally. This is shown in the figure below:

3. Initialization passed, but the data is 0

Another situation is that all initialization passes, but the Euler angle data is all 0. This situation is because there is a hard delay in the code or the processing of other modules affects 6050, so the data is all 0. The personal test is to mask the data processing screen of a module after the test.