内核版本Rapsberry PI Linux/arm64 4.14.43,开启下列选项:
1 2 | Device Drivers -> Dalla's 1-wire support -> 1-wire Bus Masters -> GPIO 1-wire busmaster Device Drivers -> Dalla's 1-wire support -> 1-wire Slaves -> Thermal family implementation |
本文将其设置为y,当然设置为M也是可以的,那就需要加载驱动。
在soc下面添加节点:
1 2 3 4 5 6 7 8 | onewire: onewire@0 { compatible = "w1-gpio"; pinctrl-names = "default"; pinctrl-0 = <&w1_pins>; gpios = <&gpio 0x4 0x0>; rpi,parasitic-power = <0x0>; status = "okay"; }; |
在gpio下面添加节点:
1 2 3 4 5 | w1_pins: w1_pins0 { brcm,pins = <0x4>; brcm,function = <0x0>; brcm,pull = <0x0>; }; |
按下面的方法,在面包板上将DS18B20接到GPIO4。
1脚接地,3脚接3.3V,2脚接GPIO,同时2脚经过一个4.7K的电阻接3.3V。
启动过程将打印:
1 2 | [ 0.657304] w1-gpio soc:onewire@0: gpio pin 4, external pullup pin -1, parasitic power 0 [ 0.657338] w1_add_master_device: set_pullup requires write_byte or touch_bit, disabling |
读取数据:
1 2 3 | # cat /sys/bus/w1/devices/28-000009a3129b/w1_slave d3 01 4b 46 7f ff 0d 10 7b : crc=7b YES d3 01 4b 46 7f ff 0d 10 7b t=29187 |
当前温度为:29.187 ℃
总结:
由于使用自己的内核和系统,按照网上的设置config.txt并不生效,因此手动修改device tree添加节点。主要卡在device tree添加节点不熟悉,节点的参数不对。