leech001 / MPU6050

STM32 HAL library for GY-521 (MPU6050) with Kalman filter
GNU General Public License v3.0
338 stars 82 forks source link

Fix for MPU6050's that don't start #7

Closed AlexBurgers closed 3 years ago

AlexBurgers commented 3 years ago

I had quite some trouble getting my MPU6050's to work. As it turns out they start with the PWR_MGMT_1_REG set as 0x40 (everything zero, reset flag 1), which doesn't result in a working chip if you try to overwrite it with zeros. What ended up working for me is first writing 0xFF to the PWR_MGMT_1_REG and subsequently writing the zeroes.

I'm not sure if I just had a batch of dud MPU6050's that way, or of this is going to be a common problem, but this is my request to add the line of code to the initialization function. :)

(MPU6050.c Line 77-78)

        // power management register 0X6B we should write all 0's to wake the sensor up
          Data = 0;
          HAL_I2C_Mem_Write(I2Cx, MPU6050_ADDR, PWR_MGMT_1_REG, 1, &Data, 1, i2c_timeout);

to:

        // power management register 0X6B we should write all 0's to wake the sensor up
          Data = 0xFF;
          HAL_I2C_Mem_Write(I2Cx, MPU6050_ADDR, PWR_MGMT_1_REG, 1, &Data, 1, i2c_timeout);
          Data = 0x00;
          HAL_I2C_Mem_Write(I2Cx, MPU6050_ADDR, PWR_MGMT_1_REG, 1, &Data, 1, i2c_timeout);
leech001 commented 3 years ago

Sorry, but I do not see this error. Perhaps you have a special case.