SD_HAL_MPU6050 icon indicating copy to clipboard operation
SD_HAL_MPU6050 copied to clipboard

Configuration of gyroscope and accelerometer sensitivity doesn't work

Open diobg opened this issue 7 years ago • 4 comments

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

diobg avatar Oct 17 '17 19:10 diobg

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 avatar Apr 14 '19 15:04 crackwitz

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

crackwitz avatar Apr 14 '19 17:04 crackwitz

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.

frankzecaiwang avatar Apr 15 '21 19:04 frankzecaiwang

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

diobg avatar Apr 21 '21 17:04 diobg