Hello,
I know this has been discussed in several topic, but I really like to make it work.
First thing I must know is :
What should be the job of MPU-6050 as I2C master ?? take the compass value and keep it in a register ? that's all ?
Here is the registery settings of the MPU6050 from the MultiWii code, in order to make it operate as master for compass :
#if defined(MPU6050_I2C_AUX_MASTER)
i2c_writeReg(MPU6050_ADDRESS, 0x6A, 0b00100000);
//USER_CTRL -- DMP_EN=0 ; FIFO_EN=0 ; I2C_MST_EN=1 (I2C master mode) ; I2C_IF_DIS=0 ; FIFO_RESET=0 ; I2C_MST_RESET=0 ; SIG_COND_RESET=0
i2c_writeReg(MPU6050_ADDRESS, 0x37, 0x00);
//INT_PIN_CFG -- INT_LEVEL=0; INT_OPEN=0; LATCH_INT_EN=0; INT_RD_CLEAR=0; FSYNC_INT_LEVEL=0; FSYNC_INT_EN=0; I2C_BYPASS_EN=0; CLKOUT_EN=0
i2c_writeReg(MPU6050_ADDRESS, 0x24, 0x0D);
//I2C_MST_CTRL -- MULT_MST_EN=0 ; WAIT_FOR_ES=0 ; SLV_3_FIFO_EN=0 ; I2C_MST_P_NSR=0 ; I2C_MST_CLK=13 (I2C slave speed bus = 400kHz)
i2c_writeReg(MPU6050_ADDRESS, 0x25, 0x80|MAG_ADDRESS);
//I2C_SLV0_ADDR -- I2C_SLV4_RW=1 (read operation) ; I2C_SLV4_ADDR=MAG_ADDRESS
i2c_writeReg(MPU6050_ADDRESS, 0x26, MAG_DATA_REGISTER);
//I2C_SLV0_REG -- 6 data bytes of MAG are stored in 6 registers. First register address is MAG_DATA_REGISTER
i2c_writeReg(MPU6050_ADDRESS, 0x27, 0x86);
//I2C_SLV0_CTRL -- I2C_SLV0_EN=1 ; I2C_SLV0_BYTE_SW=0 ; I2C_SLV0_REG_DIS=0 ; I2C_SLV0_GRP=0 ; I2C_SLV0_LEN=3 (3x2 bytes)
#endif
Next step, take the value, again, here is the MultiWii code :
void Device_Mag_getADC() {
i2c_getSixRawADC(MPU6050_ADDRESS, 0x49); //0x49 is the first memory room for EXT_SENS_DATA
MAG_ORIENTATION( ((rawADC[0]<<8) | rawADC[1]) ,
((rawADC[4]<<8) | rawADC[5]) ,
((rawADC[2]<<8) | rawADC[3]) );
}
Am I on the right way ?