sinadarvi / SD_HAL_MPU6050

Running MPU6050 with HAL drivers on STM32
67 stars 24 forks source link

Configuration of gyroscope and accelerometer sensitivity doesn't work #1

Open diobg opened 7 years ago

diobg commented 7 years ago

When configuring the mpu for the desired sensitivity only the data byte is being sent. The register address is also required.

Starting from line 226 of sd_hal_mpu6050.c: temp = (temp & 0xE7) | (uint8_t)GyroscopeSensitivity << 3; while(HAL_I2C_Master_Transmit(Handle, (uint16_t)address, &temp, 1, 1000) != HAL_OK);

Should be: temp = (temp & 0xE7) | (uint8_t)GyroscopeSensitivity << 3; uint8_t send[2]; send[0] = regAdd; send[1] = temp; while(HAL_I2C_Master_Transmit(Handle, (uint16_t)address, send, 2, 1000) != HAL_OK);

and the same for the accelerometer function

crackwitz commented 5 years ago

thanks for confirming my suspicions and thanks for the code. this applies to FS_SEL and AFS_SEL (acceleration stuck at 4G range for me), possibly more. it might be a good idea to fork this... the repo seems dead.

I'm forking and working on this right now.

crackwitz commented 5 years ago

besides this bug, it seems the data sheet is wrong. acceleration sensitivity is halved. maybe the chips received a bad factory calibration.

this seems to agree: https://github.com/jrowberg/i2cdevlib/blob/master/Arduino/MPU6050/MPU6050_6Axis_MotionApps20.h

frankzecaiwang commented 3 years ago

When configuring the mpu for the desired sensitivity only the data byte is being sent. The register address is also required.

Starting from line 230 of sd_hal_mpu6050.c: temp = (temp & 0xE7) | (uint8_t)GyroscopeSensitivity << 3; while(HAL_I2C_Master_Transmit(Handle, (uint16_t)address, send, 2, 1000) != HAL_OK);

Should be: temp = (temp & 0xE7) | (uint8_t)GyroscopeSensitivity << 3; uint8_t send[2]; send[0] = regAdd; send[1] = temp; while(HAL_I2C_Master_Transmit(Handle, (uint16_t)address, send, 2, 1000) != HAL_OK);

and the same for the accelerometer function

don't see issue from the original code if you look at details of HAL_I2C_Master_Transmit.

diobg commented 3 years ago

When configuring the mpu for the desired sensitivity only the data byte is being sent. The register address is also required. Starting from line 230 of sd_hal_mpu6050.c: temp = (temp & 0xE7) | (uint8_t)GyroscopeSensitivity << 3; while(HAL_I2C_Master_Transmit(Handle, (uint16_t)address, send, 2, 1000) != HAL_OK); Should be: temp = (temp & 0xE7) | (uint8_t)GyroscopeSensitivity << 3; uint8_t send[2]; send[0] = regAdd; send[1] = temp; while(HAL_I2C_Master_Transmit(Handle, (uint16_t)address, send, 2, 1000) != HAL_OK); and the same for the accelerometer function

don't see issue from the original code if you look at details of HAL_I2C_Master_Transmit.

I made a mistake when i quoted the original code i have edited it so now you can see the address is not sent on the original