我有2个VL6180X距离传感器正确连接到TCA9548A多路复用器,但是它只能识别多路复用器本身,而不能识别2个传感器(如0x70所示)。有什么方法可以配置i2c地址吗?
i2cdetect -y 1
给我以下输出
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: 70 -- -- -- -- -- -- --
Ofc,我确实已经在网上搜索以找到解决方案:
我已安装
sudo apt-get install -y python-smbus
sudo apt-get install -y i2c-tools
我在内核中启用了i2c(https://raspberrypi.stackexchange.com/questions/66145/raspberry-pi-3-not-detecting-i2c-device)
将所有内容添加到config.txt中,如下所示:I2C not detecting ? issues in hardware or any other?
为了在Linux中的多路复用器后面正确实例化VL6180X,您应该在设备树中对其进行描述。看看I2C MUX documentation。
因此,您应该像这样描述整个设置(I2C多路复用器+ 2x VL6180X):
&i2c1 { // the SoC bus controller
mux@70 {
compatible = "nxp,pca9548";
reg = <0x70>;
#address-cells = <1>;
#size-cells = <0>;
i2c@3 {
#address-cells = <1>;
#size-cells = <0>;
reg = <3>;
gpio1: gpio@29 {
compatible = "st,vl6180";
reg = <0x29>;
};
};
i2c@4 {
#address-cells = <1>;
#size-cells = <0>;
reg = <4>;
gpio1: gpio@29 {
compatible = "st,vl6180";
reg = <0x29>;
};
};
};
};
这将实例化两个新的总线(用i2cdetect -l
列出它们,并且一个vl6180传感器将出现在它们的下面,并被描述为常规IIO设备。
以上代码是i2c-mux和VL6180X sensor的设备树绑定文档的简单组合,可从内核源码中获得。
Luca的答案比这个要好,尽管这仍然可以使用。
这不是那样的。您不能通过多路复用器“ see”连接的设备。
相反,您打开多路复用器并向其中写入一个“控制字节”,以告知该设备应将以下数据转发到哪个设备。