Jump to content

DS18B20 Temperature Sensor / 1-Wire / FEX


Andy

Recommended Posts

Hy

 

I'm currently trying to run a DS18B20 Temperature Sensor on the PA20 Port on my Neo Core 2.

The w1_gpio und w1_therm modules are loaded

image.png.8d9f665faab5e444c75b872dc995d87c.png

but still I can't see the senors in the /sys/bus/w1/devices/ folder. (28-xxxx)

image.png.a442d0ea98e7e81d0005cfe002855831.png

 

Now I read in different threads to edit the FEX file in the /boot/ folder. So I would bee to first covert the script.bin to the script.fex.

However I can't find any *.bin file in the /boot/ folder...

 

So is the PA20 Port the correct 1Wire port? And how can I change this port to eg. GPIOG11 if I can't find the script.bin in the /boot/ folder?

 

Andy

Link to comment
Share on other sites

hmm so I found something. With the Neo Core 2 I have a 64-bit SoCs so it does not use FEX files instead the dtbo files in the /boot/dtb/allwinner/overlay/ folder.

With fdtdump I can read the w1-gpio file where the port is written.

fdtdump sun50i-h5-w1-gpio.dtbo
/dts-v1/;
// magic:               0xd00dfeed
// totalsize:           0x31f (799)
// off_dt_struct:       0x38
// off_dt_strings:      0x2b4
// off_mem_rsvmap:      0x28
// version:             17
// last_comp_version:   16
// boot_cpuid_phys:     0x0
// size_dt_strings:     0x6b
// size_dt_struct:      0x27c

/ {
    compatible = "allwinner,sun50i-h5";
    fragment@0 {
        target = <0xffffffff>;
        __overlay__ {
            w1_pins {
                pins = "PD14";
                function = "gpio_in";
                linux,phandle = <0x00000001>;
                phandle = <0x00000001>;
            };
        };
    };
    fragment@1 {
        target-path = "/";
        __overlay__ {
            onewire@0 {
                compatible = "w1-gpio";
                pinctrl-names = "default";
                pinctrl-0 = <0x00000001>;
                gpios = <0xffffffff 0x00000003 0x0000000e 0x00000000>;
                status = "okay";
            };
        };
    };
    __symbols__ {
        w1_pins = "/fragment@0/__overlay__/w1_pins";
    };
    __fixups__ {
        pio = "/fragment@0:target:0", "/fragment@1/__overlay__/onewire@0:gpios:0";
    };
    __local_fixups__ {
        fragment@1 {
            __overlay__ {
                onewire@0 {
                    pinctrl-0 = <0x00000000>;
                };
            };
        };
    };
};

 

 

From the file I can see that the port used for the 1Wire interfaceis PD14 (GPIOD14) which on the Core 2 is used to reset the RTL8211E chip on the board:

image.png.8d035cd726e82298da42303794edddd7.png

 

So I definitely can't use this pin for my 1Wire interface.

Now what I didn't figure out is now how to change the PIN for the 1 Wire interface in the file.

 

 

I tired to copy the content of the w1-gpio file to a new w1-gpioPA20.dts file and then use the command

armbian-add-overlay <overlay_file.dts>

to put the dts in to the /boot/dtb/allwinner/overlay/ folder. 

Now in the /boot/overlay-user/ I can see the new w1-gpioPA20.dtbo File.

Also in the armbianEnv.txt there is now an additional entry where the w1-gpioPA20 gets launched

and during booting I can see that the module gets activated.

 

However still I don't see the DS18B20 now on the new pin in the /sys/bus/w1/devices/ folder.

Where did I make a mistake?

 

Andy

 

 

 

 

 

 

 

Link to comment
Share on other sites

cat /sys/kernel/debug/gpio

gpiochip1: GPIOs 0-223, parent: platform/1c20800.pinctrl, 1c20800.pinctrl:
 gpio-20  (                    |nanopi:blue:status  ) out lo
 gpio-102 (                    |gmac-3v3            ) out hi
 gpio-166 (                    |cd                  ) in  hi IRQ
 gpio-203 (                    |w1                  ) in  lo
 gpio-204 (                    |usb0_id_det         ) in  hi IRQ

gpiochip0: GPIOs 352-383, parent: platform/1f02c00.pinctrl, 1f02c00.pinctrl:
 gpio-354 (                    |usb0-vbus           ) out hi
 gpio-359 (                    |reset               ) out lo
 gpio-362 (                    |nanopi:green:pwr    ) out hi

 

dmesg | grep w1

[   16.082602] w1_master_driver w1_bus_master1: w1_search: max_slave_count 64 reached, will continue next search.
[   62.978597] w1_master_driver w1_bus_master1: Attaching one wire slave 00.800000000000 crc 8c
[   62.981824] w1_master_driver w1_bus_master1: Family 0 for 00.800000000000.8c is not registered.

 

Link to comment
Share on other sites

great it works!

Now I don't know why the 1Wire is now on PG11 and not PA20...

How can I set the port for the 1Wire interface then apparently the method I described above did not work... (DT overlay)

 

Andy

Link to comment
Share on other sites

Probably because it is how it has been defined in main DT, not by overlays, and trying to use your PA20 overlay failed to be loaded since PA20 is already in-use by kernel LEDS blue:status in main DT.

In other words, you have to analyse the main DT before trying any kind of overlays ...

 

Link to comment
Share on other sites

If PA20 is busy by some other drivers, such LEDS, pins controller will refuse to assign PA to W1 driver, therefore existing W1 setting to PG11 won't be overwritten.

If PA20 were not it use, yes the W1 settings will overwrite the main DT, but it is not the case here since PA20 is busy.

 

Link to comment
Share on other sites

3 hours ago, Andy said:

Now I don't know why the 1Wire is now on PG11 and not PA20...

 

16 minutes ago, Andy said:

hmm sounds logic but I also tried PG7 but no success with this either...

 

What are you changing exactly in the overlay? GPIO pin number is defined in the "gpios" property of the "onewire@0" block, not in the "w1_pins" block - it controls nothing by default unless you add bias-pull-up, bias-pull-down or drive-strength properties if you need to change the pin controller defaults for that pin.

Link to comment
Share on other sites

In the overlay I tried to change the default pin where the 1Wire interface is connected. So the default is PD14.

Then I tried to use the PA20 and because this didn't worked I also tried PG7.

so I nee to change the gpios = <0xffffffff 0x00000003 0x0000000e 0x00000000>; part in the "onewire@0" Block?

but is the 0xffffffff not the reference to the "w1_pins" block and there to the PD14 pin?

 

Andy

Link to comment
Share on other sites

13 minutes ago, Andy said:

so I nee to change the gpios = <0xffffffff 0x00000003 0x0000000e 0x00000000>; part in the "onewire@0" Block?

but is the 0xffffffff not the reference to the "w1_pins" block and there to the PD14 pin?

Please look at the original (not decompiled) overlay: https://github.com/armbian/sunxi-DT-overlays/blob/master/sun50i-h5/sun50i-h5-w1-gpio.dts

In your decompiled overlay the first cell of the "gpios" property (0xffffffff) will be the reference to the pin controller node (from the "main" DT), the second cell (0x00000003) is the pin bank number (PD) and the third cell (0x0000000e) is the pin number in the bank (14).

 

Alternatively the pin number can be easily changed with the base overlay, as noted in the README in the overlays directory.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines