SD_HAL_MPU6050
SD_HAL_MPU6050 copied to clipboard
Configuration of gyroscope and accelerometer sensitivity doesn't work
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
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.
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
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.
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