Connection required for using Zephyr 1-wire driver on nrf52840DK

Hello,

I am trying to understand how to use the Zephyr 1-wire driver on nrf52840. I see from the "scanner" sample of the w1-serial driver that it supports the nrf52840DK, however, the sample readme does not provide a description of the hardware connections required. As I understand, this driver uses the UART module, and I understand the Tx and Rx pins have to be shorted by a 470k resistor or a Schottky diode, before it can be connected to a 1-wire device such as Dallas DS28E05 EEPROM.

Could you please confirm that this is required to be done? Also, would it be possible to have a simple workaround by assigning the Tx and Rx to the same pin in a DTS overlay? This would avoid the need for hardware modifications.

My ultimate aim is to get the w1-serial driver working on a custom board that a customer has provided, on which the DS28E05 is already wired to a GPIO pin (P0.5) of nrf52840. Previously, on the old bare-metal application software, there was a bit-banging driver that was used for this communication. My job is to port the old software to Zephyr, and I would like to use the proper Zephyr driver for this. Changing the hardware is not an option for me, as this board is already in production. If the only way to use the w1-serial driver is to wire up the Tx and Rx as above, I guess I would be forced to write a new Zephyr-compatibe version of the old bit-banging driver.

Thanks

regards

pnc 

  • Hello,

    I don't have a sensor to try myself. But from my understanding after reading the sample documentation:
    https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/sensor/ds18b20/README.html 
    https://github.com/nrfconnect/sdk-zephyr/tree/main/samples/sensor/ds18b20 

    It says you should hook up the hardware as descrbed in DS18B20 datasheet, the figure I can find that show this is:

    When compiling the sample application I can find the sample project adds two devictree overlay files to the nRF52840 DK:
    https://github.com/nrfconnect/sdk-zephyr/blob/main/samples/sensor/ds18b20/arduino_serial.overlay 
    https://github.com/nrfconnect/sdk-zephyr/blob/main/samples/sensor/ds18b20/boards/nrf52840dk_nrf52840.overlay 

    The nrd52840dk_nrf52840.overlay files says it should use port1 pin1 for uart rx and port1 pin2 for uart tx. Looking at the hardware configuration figure above I can see you need a ~4.7kohm pull up on the 1-wire line, however I can also see from the overlay files that there is an bias-pull-up; option used for uart rx, so with this option you should not need an external pull-up, instead simply connect the rx and tx together with the DQ pin of the DS18B20 should be sufficient.

    As a side note: I can see that the arduino_serial is used for communication, from the nRF52840dk_nrf52840.dts file I can see arduino_serial is &uart1:
    https://github.com/nrfconnect/sdk-zephyr/blob/main/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts 

    So uart1 can't be used for anything else than 1-wire in this case.

    Kenneth

  • Hi Kenneth,

    thanks for your answer! Actually, my main question was (I guess I should have highlighted it), was if I could avoid physically shorting Tx and Rx, and simply assign them to the same pin in a DTS overlay. This would avoid hardware changes. As I mentioned in my original post, I am creating a software update for a production board which is already in use at various client sites, and am not in a position to modify the hardware in any way. From your answer, I feel this should be possible, but would just like to verify.

    As a side note, my original impression was that a 470k resistor is required between Tx and Rx, as described in this technical note from Analog Devices (diagram below)

    https://www.analog.com/en/technical-articles/using-a-uart-to-implement-a-1wire-bus-master.html

      

    However, as you have indicated, and as I have seen in various other places too, a direct shorting also seems to work. That being so, assigning the same physical pin to both Tx and Rx in the DTS should have the same effect, unless it causes some internal problem in nrf52 UART module that you might be aware of.

    thanks

    regards

    pnc

  • Following on from my previous post, it seems connecting Tx and Rx via DTS is possible, as per this discussion:

     nrf52832-single-wire-uart

    So if I do something like this in the DTS overlay, going by the accepted solution in above discussion, it ought to work:

    &uart1_default {
    group1 {
    psels = <NRF_PSEL(UART_RX, 0, 5)>;
    bias-pull-up;
    };
    group2 {
    psels = <NRF_PSEL(UART_TX, 0, 5)>;

    drive-mode = NRF_DRIVE_S0D1;
    };
    };

    I'll try this out tomorrow. 

  • Hi Kenneth,

    I tried out the above idea with the following addition to the custom board definition of my custom nrf52840 board

    &uart1 {
        status = "okay";
        current-speed = <115200>;
        pinctrl-0 = <&uart1_default>;
        pinctrl-1 = <&uart1_sleep>;
        pinctrl-names = "default", "sleep";
        w1: w1 {
            compatible = "zephyr,w1-serial";
            status = "okay";
        };
    };
    &pinctrl {

        uart1_default: uart1_default {
            group1 {
                psels = <NRF_PSEL(UART_RX, 0, 5)>;
                bias-pull-up;
            };
            group2 {
                psels = <NRF_PSEL(UART_TX, 0, 5)>;
                nordic,drive-mode = <NRF_DRIVE_S0D1>;
            };
        };

        uart1_sleep: uart1_sleep {
            group1 {
                psels = <NRF_PSEL(UART_RX, 0, 5)>,
                    <NRF_PSEL(UART_TX, 0, 5)>;
                low-power-enable;
            };
        };

    Btw GPIO0.5 happens to be the pin to which the w1 device is connected on my board (with a pull-up). As I mentioned earlier, previously this was being used by a bit-bashing bare metal driver

    It is building fine with the Zephyr w1 scanner sample, however, I am getting an IO error in uart_poll_in() in line 89 of w1_zephyr_serial.c (in the serial_tx_rx() function).

    Could you please verify if my approach is feasible, or if what I am trying to do is simply impossible? In that case, I guess I have no option but to go back to bit bashing and forget the serial_w1 driver, since, as I said, I am not in a position to change the board wiring. Would it be possible for you to try it out with the nrf52840DK? I do not have access that board, and perhaps it is just an issue with my custom board.

    thanks

    regards

    pnc

  • pnc2 said:
    if what I am trying to do is simply impossible?

    It's not been designed or intended to share pins the way you are trying no. So you should not expect this to work unfortunately. So unless you can update the board to use two pins, it looks like you need to use some kind of bit bashing yes.

    Best regards,
    Kenneth

Related