Skip to content

Commit c3524e8

Browse files
authored
Update mpu6050_i2c.c
The reset process requires to set DEVICE_RESET bit in PWR_MGMT_1 (0x6B) bits to one ===> 0x80. then the we must release the reset bit or the device will remain always in reset mode. detailed explanation is here: raspberrypi#319
1 parent a7ad171 commit c3524e8

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

i2c/mpu6050_i2c/mpu6050_i2c.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,15 @@ static int addr = 0x68;
3737
static void mpu6050_reset() {
3838
// Two byte reset. First byte register, second byte data
3939
// There are a load more options to set up the device in different ways that could be added here
40-
uint8_t buf[] = {0x6B, 0x00};
41-
i2c_write_blocking(i2c_default, addr, buf, 2, false);
40+
/* Register: PWR_MGMT_1 (0x6B), Value: 0x80, Action: Reset all internal registers (of MPU6050) to default values */
41+
uint8_t res[] = {0x6B, 0x80};
42+
i2c_write_blocking(i2c_default, addr, res, 2, false);
43+
sleep_ms(200); /* Give the device time to perform the reset */
44+
45+
/* Register: PWR_MGMT_1 (0x6B), Value: 0x00, Action: Take MPU6050 out of sleep mode (which is the default state after reset) */
46+
uint8_t wake[] = {0x6B, 0x00};
47+
i2c_write_blocking(i2c_default, addr, wake, 2, false);
48+
sleep_ms(200); /* Give the device time to get out of the reset */
4249
}
4350

4451
static void mpu6050_read_raw(int16_t accel[3], int16_t gyro[3], int16_t *temp) {

0 commit comments

Comments
 (0)