Need help configuring nrfx qdec irq in Zephyr project

Hello,

Currently I am implementing the nrfx qdec driver in our Zephyr project using the nRF52840 DK. We choose the nrfx driver as this provides events. I am using the nRF Connect vs code extension, toolchain v2.7.0 and Zephyr 3.5.0.

The setup and initialization of the driver is quite straight forward and works. But as soon as I turn the rotary encoder a spurious IRQ is thrown. It has something to do with the IRQ_CONNECT macro. The example provided in nrfx_qdec.h doesn't seems to work:

 * IRQ_DIRECT_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_QDEC_INST_GET(\<instance_index\>)), \<priority\>,
 *                    NRFX_QDEC_INST_HANDLER_GET(\<instance_index\>), 0);

Looking for examples didn't result in a solution.

Any help is appreciated.

  • Hi,

    The example

    Which example?

    Are you using a DK for this?
    Are you using an external sensor for this?

    Regards,
    Sigurd Hellesvik

  • Hi Sigurd,

    I'am using the nRF52840-DK with a quadrature rotary knob with signals connected to P1.10 and P1.11. The sample which I refer to is not more than a code snippet found in nrfx_qdec.h how to connect the IRQ. This is the part which is not working for me and need help configuring. Below is the code I use in the project to init the QDEC driver.

    #include <zephyr/device.h>
    #include <zephyr/devicetree.h>
    #include <zephyr/irq.h>
    #include <nrfx.h>
    #include <nrfx_qdec.h>
    
    nrfx_qdec_t g_qdec_dev = NRFX_QDEC_INSTANCE(0);
    volatile uint8_t g_test = 0;
    
    void qdec_event_handler(nrfx_qdec_event_t event, void *p_context)
    {
    	test++;
    }
    
    void qdec_init()
    {
    	// IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_QDEC_INST_GET(0)), IRQ_PRIO_LOWEST,
    	// NRFX_QDEC_INST_HANDLER_GET(0), 0);
    
    	nrfx_qdec_config_t config = NRFX_QDEC_DEFAULT_CONFIG(42, 43, NRF_QDEC_PIN_NOT_CONNECTED);
    
    	config.sample_inten = true;
    	config.reportper_inten = true;
    
    	nrfx_err_t err = nrfx_qdec_init(&g_qdec_dev, &config, qdec_event_handler, NULL);
    	nrfx_qdec_enable(&g_qdec_dev);
    }

    Kind regards,
    Ronald

  • I see that Zephyr has a QDEC sample. Could you try this with your setup?
    It should be kinda quick to try I think, and if it works it would be good to have it as a base-line.

    Maybe you are even happy to use the Zephyr drivers for this instead of using nrfx directly?

Related