Code is part of my project. Right now its for I2C1. Prior to calling any of these function you need to initialize I2C1.
One sample part to read accelerometer, temperature sensor and gyro data. I have tested this code on MPU6000 and MPU6050 on I2C bus.
Code: Select all
set_mpu_sample_rate(9);
set_mpu_config_regsiter(EXT_SYNC_SET0, DLPF_CFG0);
set_mpu_gyro(XG_ST_DIS, YG_ST_DIS, ZG_ST_DIS, FS_SEL_250);
set_mpu_accel(XA_ST_DIS, YA_ST_DIS, ZA_ST_DIS, AFS_SEL_2g, ACCEL_HPF0);
set_mpu_power_mgmt1(DEVICE_RESET_DIS, SLEEP_DIS, CYCLE_DIS, TEMPERATURE_EN, CLKSEL_XG);
set_mpu_user_control(USER_FIFO_DIS, I2C_MST_DIS, I2C_IF_DIS, FIFO_RESET_DIS, I2C_MST_RESET_DIS, SIG_COND_RESET_DIS);
write_mpu_power_mgmt1();
write_mpu_gyro();
write_mpu_accel();
write_mpu_sample_rate();
while (TRUE) {
mpu_i2c_read_data(0x3B, 14); /* Read accelerometer, temperature and gyro data */
chThdSleepMilliseconds(50);
}
Still this is work in progress. It sends data over UART in mpu60x0.c file. First three values are accelerometer, fourth one is temperature sensor and last three are gyro values. Havent explored FIFO and interrupt part yet.
Waiting for feedbacks.
Sapan