Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
diobg opened this issue Oct 17, 2017 · 4 comments
Open

Comments

@diobg
Copy link

diobg commented Oct 17, 2017

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
Copy link

crackwitz commented Apr 14, 2019

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
Copy link

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
Copy link

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
Copy link
Author

diobg commented Apr 21, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants