Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions i2c/mpu6050_i2c/mpu6050_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,16 @@ static int addr = 0x68;
static void mpu6050_reset() {
// Two byte reset. First byte register, second byte data
// There are a load more options to set up the device in different ways that could be added here
uint8_t buf[] = {0x6B, 0x00};
i2c_write_blocking(i2c_default, addr, buf, 2, false);

/* Register: PWR_MGMT_1 (0x6B), Value: 0x80, Action: Reset all internal registers (of MPU6050) to default values */
uint8_t res[] = {0x6B, 0x80};
i2c_write_blocking(i2c_default, addr, res, 2, false);
sleep_ms(200); /* Give the device time to perform the reset */

/* Register: PWR_MGMT_1 (0x6B), Value: 0x00, Action: Take MPU6050 out of sleep mode (which is the default state after reset) */
uint8_t wake[] = {0x6B, 0x00};
i2c_write_blocking(i2c_default, addr, wake, 2, false);
sleep_ms(200); /* Give the device time to get out of the reset */
}

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