HMC5883L通过XCL XDA连接MPU6050

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值