QDEC sample code from zephyr is not running on nrf52840dk

I am using a rotary encoder with nrf52840dk and I am confused about how to run sample QDEC code from zephyr/sample/sensor/qdec on nrf52840dk.

I got this error when i tried to directly build the code for nrf52840

I tried to add an overlay file to add qdec0 in this project. It was compulsory to add reg and interrupts parameters. 

&{/} {
    qdec0: qdec0{
        compatible="nordic,nrf-qdec";
        a-pin = <38>;
        b-pin = <39>;
        enable-pin = <32>;
        led-pin = <13>;
        led-pre = <0>;
        steps = <20>;
        reg = <0x000f8000 0x00008000>;
        interrupts = <&gpio0>;
    };
    
    aliases {
        qdec0=&qdec;
    };
};

 C

Parents
  • Great to hear that. If you want can share your idea with the community. 

  • Hi, I'm struggling with the same problem.

    Based on your discussion above, I have created a device tree overlay file like this:

    &pinctrl {
        qdec_default: qdec_default {
            group1 {
                psels = <NRF_PSEL(QDEC_A, 0, 3)>,
                    <NRF_PSEL(QDEC_B, 0, 28)>;
            };
        };

        qdec_sleep: qdec_sleep {
            group1 {
                psels = <NRF_PSEL(QDEC_A, 0, 3)>,
                    <NRF_PSEL(QDEC_B, 0, 28)>;
                low-power-enable;
            };
        };
    };


    &qdec {
        status = "okay";
        enable-pin = <30>;
        led-pre = <0>;
        steps = <24>;
        pinctrl-0 = <&qdec_default>;
        pinctrl-1 = <&qdec_sleep>;
        pinctrl-names = "default", "sleep";
    };

    but when I try to build, I get this error:

    ../src/main.c: In function 'main':
    /home/willem/ncs/v2.1.0/zephyr/include/zephyr/device.h:96:39: error: '__device_dts_ord_DT_N_ALIAS_qdec_ORD' undeclared (first use in this function)
    96 | #define DEVICE_NAME_GET(name) _CONCAT(__device_, name)

    So I must be missing something...

    Can you help me to get this fixed?

  • Are you working on same DK? You need to create an overlay file the following way.
    &qdec {
        compatible = "nordic,nrf52840-dk-nrf52840";
        pinctrl-0 = <&qdec_default>;
        pinctrl-1 = <&qdec_sleep>;
        pinctrl-names = "default", "sleep";
        label = "qdec";
    };

    &pinctrl {
        qdec_default: qdec_default {
        group1 {
            psels = <NRF_PSEL(QDEC_A, 0, 3)>,
                <NRF_PSEL(QDEC_B, 0, 28)>;
        };
    };


        qdec_sleep: qdec_sleep {
        group1 {
            psels = <NRF_PSEL(QDEC_A, 0, 3)>,
                <NRF_PSEL(QDEC_B, 0, 28)>;
            low-power-enable;
        };
    };
    };


    Later in your device tree file you will add this-
    &qdec {
        status = "okay";
        enable-pin = <30>;
        led-pre = <0>;
        steps = <24>;
        pinctrl-0 = <&qdec_default>;
        pinctrl-1 = <&qdec_sleep>;
        pinctrl-names = "default", "sleep";
    };
    Check if it works.
Reply
  • Are you working on same DK? You need to create an overlay file the following way.
    &qdec {
        compatible = "nordic,nrf52840-dk-nrf52840";
        pinctrl-0 = <&qdec_default>;
        pinctrl-1 = <&qdec_sleep>;
        pinctrl-names = "default", "sleep";
        label = "qdec";
    };

    &pinctrl {
        qdec_default: qdec_default {
        group1 {
            psels = <NRF_PSEL(QDEC_A, 0, 3)>,
                <NRF_PSEL(QDEC_B, 0, 28)>;
        };
    };


        qdec_sleep: qdec_sleep {
        group1 {
            psels = <NRF_PSEL(QDEC_A, 0, 3)>,
                <NRF_PSEL(QDEC_B, 0, 28)>;
            low-power-enable;
        };
    };
    };


    Later in your device tree file you will add this-
    &qdec {
        status = "okay";
        enable-pin = <30>;
        led-pre = <0>;
        steps = <24>;
        pinctrl-0 = <&qdec_default>;
        pinctrl-1 = <&qdec_sleep>;
        pinctrl-names = "default", "sleep";
    };
    Check if it works.
Children
  • Alas, I still get the same error.

    I changed the contents of the overlay file to exactly what you advised. However, I don't quit understand what you mean by "Later in your device tree file". I put everything including the last &qdec definition in the same overlay file. Is this not ok?

    BTW, the IDE complains about this line: compatible = "nordic,nrf52840-dk-nrf52840";

    it says in a popup: Unknown node type "nordic,nrf52840-dk-nrf52840"

    I am working with the nrf52840dk PCA 10056 V3.0.0

  • You will probably need to add root node and declare aliases

    &{/} {
    
        aliases {
            qdec0=&qdec;
        };
    };

    Add this to your overlay file

  • "Later in your device tree file" I meant this file ''nRF52840dk_nrf52840.dts''. 

  • So I should modify the original nrf52840dk_nrf52840.dts file? I thought I should be using an overlay file to make configuration changes. Therefore I put everything in the file nrf52840dk_nrf52840.overlay which now has this content:

    &{/} {
        aliases {
            qdec0=&qdec;
        };
    };

    &qdec {
        compatible = "nordic,nrf52840-dk-nrf52840";
        pinctrl-0 = <&qdec_default>;
        pinctrl-1 = <&qdec_sleep>;
        pinctrl-names = "default", "sleep";
        label = "qdec";
    };

    &pinctrl {
        qdec_default: qdec_default {
            group1 {
                psels = <NRF_PSEL(QDEC_A, 0, 3)>,
                    <NRF_PSEL(QDEC_B, 0, 28)>;
            };
        };


        qdec_sleep: qdec_sleep {
            group1 {
                psels = <NRF_PSEL(QDEC_A, 0, 3)>,
                    <NRF_PSEL(QDEC_B, 0, 28)>;
                low-power-enable;
            };
        };
    };

    &qdec {
        status = "okay";
        enable-pin = <30>;
        led-pre = <0>;
        steps = <24>;
        pinctrl-0 = <&qdec_default>;
        pinctrl-1 = <&qdec_sleep>;
        pinctrl-names = "default", "sleep";
    };

    And this still produces the same error message '__device_dts_ord_DT_N_ALIAS_qdec_ORD' undeclared

    This does not mention qdec0, but qdec.

    In main.c the following line is used to get the device:

        const struct device *const dev = DEVICE_DT_GET(DT_ALIAS(qdec));

    Thank you BTW for your assistance; I am just starting with nrf/Zephyr development and this device tree configuration is quit confusing to me.

  • This does not mention qdec0, but qdec.

    Oh....Then just changing the value in aliases node from qdec0 to qdec should solve the problem 

Related