Basic analog comparator code

Hello,
I'm trying to get an analog comparator working on the nrf52833DK. I am using NRF Connect SDK version 2.2.0.
I have the following code:

#include <zephyr/kernel.h>
#include <nrfx_comp.h>

static void comparator_handler(nrf_comp_event_t event)
{
		printk("EVENT\n");
}

void main(void)
{

	uint32_t err;

	nrfx_comp_config_t comp_config = NRFX_COMP_DEFAULT_CONFIG(NRF_COMP_INPUT_1);
	comp_config.ext_ref = NRF_COMP_REF_VDD;


	nrfx_comp_event_handler_t comp_event_config = comparator_handler;

	err = nrfx_comp_init(&comp_config, comp_event_config);
	if (err != NRFX_SUCCESS)
	{
		printk("ERR comp init\n");
		return ;
	}

	nrfx_comp_start(NRFX_COMP_EVT_EN_UP_MASK, 0);

	while(1){
		k_msleep(1);
	}

}

At the moment when I would expect to execute the service routine, the device reboots.

*** Booting Zephyr OS build v3.2.99-ncs1 ***
*** Booting Zephyr OS build v3.2.99-ncs1 ***
*** Booting Zephyr OS build v3.2.99-ncs1 ***
*** Booting Zephyr OS build v3.2.99-ncs1 ***
*** Booting Zephyr OS build v3.2.99-ncs1 ***

Thank you for your help.

Parents Reply Children
No Data
Related