HMC5883L通过XCL\XDA连接到MPU6050,通过I2C无法直接访问HMC5883L,需要配置一下MPU6050的寄存器才能正常访问。
1、设置 Register 106(0x6A) ,I2C_MST_EN(0x00)//不让MPU6050 控制AUXI2C;
2、设置 Register(0x37),I2C_BYPASS_EN(0x02) //主控制器的I2C与 MPU6050的AUXI2C 直通。控制器可以直接访问HMC5883L
1、// Register 106(0x6A) ,I2C_MST_EN(0x00) is set to 1, I2C Master Mode is enabled. In this mode, the MPU-60X0 acts as the I2C Master to the external sensor slave devices on the auxiliary I2C bus. When this bit is cleared to 0, the auxiliary I2C bus lines (AUX_DA and AUX_CL) are logically driven by the primary I2C bus (SDA and SCL).
2、//configuration of the compass module :activate the I2C bypass to directly access the Sub I2C
Register(0x37)I2C_BYPASS_EN(0x02) When this bit is equal to 1 and I2C_MST_EN (Register 106 bit[5]) is equal to 0, the host application processor will be able to directly access the auxiliary I2C bus of the MPU-60X0. When this bit is equal to 0, the host application processor will not be able to directly access the auxiliary I2C bus of the MPU-60X0 regardless of the state of I2C_MST_EN (Register 106 bit[5]).
使用函数库的写法:
mpu6050.setI2CMasterModeEnabled(0); //不让MPU6050 控制AUXI2C
mpu6050.setI2CBypassEnabled(1); //主控制器的I2C与 MPU6050的AUXI2C 直通。控制器可以直接访问HMC5883L