// fs_sel = 3
// 2000°/s
-#define gyro_x_resolution 16.4
-#define gyro_y_resolution 16.4
-#define gyro_z_resolution 16.4
+/* #define gyro_x_resolution 16.4 */
+/* #define gyro_y_resolution 16.4 */
+/* #define gyro_z_resolution 16.4 */
+// XXX it works with 32.8, why?
+#define gyro_x_resolution 32.8
+#define gyro_y_resolution 32.8
+#define gyro_z_resolution 32.8
#define accel_x_resolution 2048.0
#define accel_y_resolution 2048.0
#define accel_z_resolution 2048.0
#define MPU6050_ADDRESS 0x69
-#define MPU6050_MAGNETO_ADDRESS 0x0D
#define SWAP_16(a) ((( (a) & 0xff)<<8) | (( (a) >> 8) & 0xff))
imu->gy = ToRad((double)(axes[5] - drift_g[1]) / gyro_y_resolution);
imu->gz = ToRad((double)(axes[6] - drift_g[2]) / gyro_z_resolution);
+ /* output data resolution is 13 bit (0.3 μT per LSB) */
imu->mx = (double) axes[7] * 0.3;
imu->my = (double) axes[8] * 0.3;
imu->mz = (double) axes[9] * 0.3;
+ //printf("%4.4x %4.4x %4.4x\n", axes[7], axes[8], axes[9]);
+
return err;
}
static uint8_t setup_mpu9150_magneto(void)
{
- //uint8_t i, err;
-
- //MPU9150_I2C_ADDRESS = 0x0C; //change Adress to Compass
-
- /* XXX doesn't work, no answer from magneto */
- /* for (i = 0; i < 127; i++) { */
- /* printf_P(PSTR("i=%d\r\n"), i); */
- /* err = send_mpu6050_cmd(i, 0x0A, 0x00); //PowerDownMode */
-
- /* if (err == 0) */
- /* printf_P(PSTR("COIN\r\n")); */
- /* } */
- send_mpu6050_cmd(MPU6050_MAGNETO_ADDRESS, 0x0A, 0x00); //PowerDownMode
- send_mpu6050_cmd(MPU6050_MAGNETO_ADDRESS, 0x0A, 0x0F); //SelfTest
- send_mpu6050_cmd(MPU6050_MAGNETO_ADDRESS, 0x0A, 0x00); //PowerDownMode
-
- //MPU9150_I2C_ADDRESS = 0x69; //change Adress to MPU
+ /* here we configure the mpu9150 to poll the magnetometer.
+ * See "MPU-9150 Register Map and Descriptions" section 4.14 */
+ /* When the WAIT_FOR_ES bit is set to 1, the Data Ready interrupt will
+ * be delayed until External Sensor data from the Slave Devices are
+ * loaded into the EXT_SENS_DATA registers. This is used to */
send_mpu6050_cmd(MPU6050_ADDRESS, 0x24, 0x40); //Wait for Data at Slave0
+
+ /* slave0: ask to read 6 bytes from reg 0x3 (start of magneto data, see
+ * section 5) of device 0xC */
send_mpu6050_cmd(MPU6050_ADDRESS, 0x25, 0x8C); //Set i2c address at slave0 at 0x0C
- //send_mpu6050_cmd(MPU6050_ADDRESS, 0x26, 0x02); //Set where reading at slave 0 starts
- send_mpu6050_cmd(MPU6050_ADDRESS, 0x26, 0x03); //Set where reading at slave 0 starts
- //send_mpu6050_cmd(MPU6050_ADDRESS, 0x27, 0x88); //set offset at start reading and enable
+ send_mpu6050_cmd(MPU6050_ADDRESS, 0x26, 0x03); //Set where reading at slave 0 starts // 3
send_mpu6050_cmd(MPU6050_ADDRESS, 0x27, 0x86); //set offset at start reading and enable
+
+ /* slave1: ask to write 1 byte (value = 0x01 = single measurement mode)
+ * at 0xA (control register) of device 0xC */
send_mpu6050_cmd(MPU6050_ADDRESS, 0x28, 0x0C); //set i2c address at slv1 at 0x0C
send_mpu6050_cmd(MPU6050_ADDRESS, 0x29, 0x0A); //Set where reading at slave 1 starts
send_mpu6050_cmd(MPU6050_ADDRESS, 0x2A, 0x81); //Enable at set length to 1
- send_mpu6050_cmd(MPU6050_ADDRESS, 0x64, 0x01); //overvride register
+ send_mpu6050_cmd(MPU6050_ADDRESS, 0x64, 0x01); //direction of slave1 write
+
+ /* enable reduced rate on slave 0 and slave 1 */
send_mpu6050_cmd(MPU6050_ADDRESS, 0x67, 0x03); //set delay rate
+
+ /* XXX ? */
send_mpu6050_cmd(MPU6050_ADDRESS, 0x01, 0x80);
+ /* set i2c master delay, XXX move before? */
send_mpu6050_cmd(MPU6050_ADDRESS, 0x34, 0x04); //set i2c slv4 delay
+
+ /* XXX useless */
send_mpu6050_cmd(MPU6050_ADDRESS, 0x64, 0x00); //override register
+
+ /* disable i2c master, the auxiliary I2C bus lines (AUX_DA and AUX_CL)
+ * are logically driven by the primary I2C bus (SDA and SCL). */
send_mpu6050_cmd(MPU6050_ADDRESS, 0x6A, 0x00); //clear usr setting
+
+ /* XXX useless */
send_mpu6050_cmd(MPU6050_ADDRESS, 0x64, 0x01); //override register
+
+ /* enable i2c master mode */
send_mpu6050_cmd(MPU6050_ADDRESS, 0x6A, 0x20); //enable master i2c mode
+
+ /* change again XXX the i2c master delay */
send_mpu6050_cmd(MPU6050_ADDRESS, 0x34, 0x13); //disable slv4
return 0;
break;
}
- /* XX use one of the gyro for clock ref: if we don't do that, some i2c
+ /* XXX use one of the gyro for clock ref: if we don't do that, some i2c
* commands fail... why ?? */
send_mpu6050_cmd(MPU6050_ADDRESS, MPU6050_RA_PWR_MGMT_1, 0b00000010);
/* Disable accel self tests, scale of +-16g, no DHPF */
send_mpu6050_cmd(MPU6050_ADDRESS, MPU6050_RA_ACCEL_CONFIG, 0b00011000);
+
+ /* XXX all is set to 0, useless?
+ The reset value is 0x00 for all registers other than the registers below.
+ • Register 107: 0x40.
+ • Register 117: 0x68.
+ */
/* Freefall threshold of <|0mg| */
send_mpu6050_cmd(MPU6050_ADDRESS, MPU6050_RA_FF_THR, 0x00);
/* Freefall duration limit of 0 */