18 #define MPU_I2C_ADDR 0x68 // this is the MPU-9250A i2c address %1011000
19 #define MAG_I2C_ADDR 0x0C // MAG_PASS_THROUGH_I2C_ADDR
24 #define MPU_GYRO_CONFIG 27
25 #define MPU_ACCEL_CONFIG 28
26 #define MPU_ACCEL_XOUT 59
27 #define MPU_ACCEL_YOUT 61
28 #define MPU_ACCEL_ZOUT 63
29 #define MPU_TEMP_OUT 65
30 #define MPU_GYRO_XOUT 67
31 #define MPU_GYRO_YOUT 69
32 #define MPU_GYRO_ZOUT 71
33 #define MPU_WHO_AM_I 117
34 #define MPU_INT_BYPASS_ENABLE 55
38 #define MAG_HZL 7 // offsets in magnetometer, note little endian, so need to be read opposite way round
40 #define MAG_CNTL1 10 // Magnetometer control register
41 #define MAG_STA1 2 // read only gives flags at 1 for DRDY and 2 for DOR (data ready and overload), used in read cycle
47 i2cstring[0] = MPU_INT_BYPASS_ENABLE;
48 uint8_t i2cstatus = I2CReceive(I2C_IMU, MPU_I2C_ADDR ,MPU_INT_BYPASS_ENABLE);
49 i2cstring[1] = i2cstatus | MPU_INT_BYPASS_ENABLE;
51 I2CSendString(I2C_IMU, MPU_I2C_ADDR, i2cstring);
54 i2cstring[0] = MAG_CNTL1;
57 I2CSendString(I2C_IMU, MAG_I2C_ADDR, i2cstring);
59 I2CSendString(I2C_IMU, MAG_I2C_ADDR, i2cstring);
62 void IMU_set_accel_sensitivity(imu_accel_sensitivity_t imu_accel_sensitivity)
64 switch(imu_accel_sensitivity)
83 void IMU_set_accel_bandwidth(imu_bandwidth_t imu_accel_bandwidth)
85 switch(imu_accel_bandwidth)
113 void IMU_set_gyro_sensitivity(imu_gyro_sensitivity_t imu_gyro_sensitivity)
115 switch(imu_gyro_sensitivity)
117 case IMU_GYRO_250DEG_S:
120 case IMU_GYRO_500DEG_S:
123 case IMU_GYRO_1000DEG_S:
126 case IMU_GYRO_2000DEG_S:
134 void IMU_set_gyro_bandwidth(imu_bandwidth_t imu_gyro_bandwidth)
136 switch(imu_gyro_bandwidth)
173 *accel_x = (int16_t)I2CReceive16(I2C_IMU, MPU_I2C_ADDR, MPU_ACCEL_XOUT);
174 *accel_y = (int16_t)I2CReceive16(I2C_IMU, MPU_I2C_ADDR, MPU_ACCEL_YOUT);
175 *accel_z = (int16_t)I2CReceive16(I2C_IMU, MPU_I2C_ADDR, MPU_ACCEL_ZOUT);
182 *gyro_x = (int16_t)I2CReceive16(I2C_IMU, MPU_I2C_ADDR, MPU_GYRO_XOUT);
183 *gyro_y = (int16_t)I2CReceive16(I2C_IMU, MPU_I2C_ADDR, MPU_GYRO_YOUT);
184 *gyro_z = (int16_t)I2CReceive16(I2C_IMU, MPU_I2C_ADDR, MPU_GYRO_ZOUT);
191 *magno_x = (int16_t)I2CReceive16r(I2C_IMU, MAG_I2C_ADDR, MAG_HXL);
192 *magno_y = (int16_t)I2CReceive16r(I2C_IMU, MAG_I2C_ADDR, MAG_HYL);
193 *magno_z = (int16_t)I2CReceive16r(I2C_IMU, MAG_I2C_ADDR, MAG_HZL);
194 (void)I2CReceive16r(I2C_IMU, MAG_I2C_ADDR, MAG_ST2);
201 *temp_imu = (int16_t)I2CReceive16(I2C_IMU, MPU_I2C_ADDR, MPU_TEMP_OUT);
void IMU_read_temp(int16_t *temp_imu)
void IMU_read_magno(int16_t *magno_x, int16_t *magno_y, int16_t *magno_z)
void IMU_read_gyro(int16_t *gyro_x, int16_t *gyro_y, int16_t *gyro_z)
void IMU_read_accel(int16_t *accel_x, int16_t *accel_y, int16_t *accel_z)