1-Wire

One Wire
1-Wire is a device communications bus system designed by Dallas Semiconductor that provides low-speed data, signaling, and power over a single signal. 1-Wire is similar in concept to I²C, but with lower data rates and longer range. It is typically used to communicate with small inexpensive devices such as digital thermometers and weather instruments. A network of 1-Wire devices with an associated master device is called a MicroLan.

Linux kernel 3.4
Edit the script.fex file and set the gpio pin for 1-wire bus



[gpio_para] gpio_used = 1 gpio_num = 67 gpio_pin_1 = port:PG03<1> <1> .... gpio_pin_66 = port:PB10<1> <1>

[w1_para] gpio = 66

Connect the data pin of devices to gpio pin PB10 and in sys folder you have

/sys/bus/w1/devices/ 28-000004bfae30 28-000004c022c5

what are connect 2 DS18B20 devices

cat /sys/bus/w1/devices/28-000004bfae30/w1_slave 45 01 4b 46 7f ff 0b 10 84 : crc=84 YES 45 01 4b 46 7f ff 0b 10 84 t=20312

the temp is 20.312 °C

Read Data Sensor
simple bash script for read 1-wire temp sensor




 * 1) !/bin/bash

file="/sys/bus/w1/devices/28-000004bfae30/w1_slave" function find{ "$1" =~ "$2" && true || false }

while : do DATE=$(date +"%d-%m-%Y-%H:%M:%S") #read device CRC=false while read curline; do		#check crc if( find "$curline" "crc" && find "$curline" "YES" ) then CRC=true DEVICE=`echo $curline|cut -d':' -f 1` fi if($CRC && find "$curline" "t=") then TEMP=`echo $curline|cut -d'=' -f 2` echo $DEVICE ";" $DATE ";" `echo "scale=3;$TEMP/1000"|bc -l` fi done <$file sleep 10 done

Device Tree
For configure an pin for use with w1-gpio add this line to device tree in pinctrl@01c20800 section

w1_pins_cubieboard: w1_pins@0 { allwinner,pins = "PB10"; allwinner,function = "gpio_out"; allwinner,drive = <1>; allwinner,pull = <0>; };

Add this lines to file w1@0 { compatible = "w1-gpio"; pinctrl-names = "default"; pinctrl-0 = <&w1_pins_cubieboard>; gpios = <&pio 1 10 0>; status = "okay"; };

Rebuild dts and reboot the board. For test try this command

cat /sys/kernel/debug/pinctrl/1c20800.pinctrl/pinmux-pins |grep PB10

The pin is configurated if you have an output like

pin 42 (PB10): w1.7 1c20800.pinctrl:42 function gpio_out group PB10