No response after configuring QDEC peripheral

Hello!

I am struggling to configure a quadratic encoder with the nRF52840. As far as I know, the code should be working. However, when the encoder rotating, the terminal says zephyr is rebooting. I am thinking this means the system has crashed or something?

I know the encoder has an output signal of 3.6 volt, which is a little too high for the rated voltage on the development kit, but is this why it seems the device crashes?

My guess is that there is something wrong about the event handler, because I get no errors before the encoder is actually moving. But I think it should be set up correctly according to the documentation.

Here is my code:

#include <zephyr.h>
#include <sys/printk.h>
#include <devicetree.h>
#include <drivers/gpio.h>
#include <nrfx_qdec.h>

const uint32_t pin_a = 26;
const uint32_t pin_b = 27;
const uint32_t pin_led = 0xFFFFFFFF;

nrfx_qdec_config_t qdec_config = 
    {                                                                
        .reportper          = NRF_QDEC_REPORTPER_10,                 
        .sampleper          = NRF_QDEC_SAMPLEPER_128us,            
        .psela              = pin_a,                                
        .pselb              = pin_b,                                
        .pselled            = pin_led,                              
        .ledpre             = 500,                                   
        .ledpol             = NRF_QDEC_LEPOL_ACTIVE_HIGH,            
        .dbfen              = NRF_QDEC_DBFEN_DISABLE,                
        .sample_inten       = false,                                 
        .interrupt_priority = NRFX_QDEC_DEFAULT_CONFIG_IRQ_PRIORITY  
};

volatile int16_t acc_data = 0;

static void qdec_nrfx_event_handler(nrfx_qdec_event_t event)
{
    if (event.type == NRF_QDEC_EVENT_REPORTRDY)
    {
        acc_data = event.data.report.acc;
        printk("Data acquired");
    }
    printk("Trigger");
}

void main(void)
{
    nrfx_qdec_init(&qdec_config, qdec_nrfx_event_handler);

    nrfx_qdec_enable();

    printk("Running...\n");

    while(1)
	{
		__WFI();
	}
}

There isn't much documentation on how to use this peripheral with the new nRF connect sdk, only with the old sdk5. I don't know how different they are but I can't seem to get it working.

Thank you.

Parents Reply Children
No Data
Related