This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Using NRF_Connect Zephyr with the Comparator interrupt

I am trying to set up the nRF52840DK to interrupt on the comparator input on A0 going above the threshold. I figured, I think, how to set the comparator up but I am havin trouble connecting the interrupt to the Zephyr interrupt. Looking at the examples for gpiote interrupt it appears that the interrupt must be 'connected' using the IRQ_CONNECT function but I cannot find an equivalent to gpiote for the comparator.

Can you point me to where I need to find the comparator interrupt data?

Parents
  • Hello,

    I understand the confusion. The board files don't seem to include any entry for the comparator, so we can't use the device tree labels like we did for the gpiote. Instead you will have to rely on hardcoded values as shown in my project below.

    nrfx sample with COMP driver

    0003.comp_sample.zip

    The IRQn number can be found in the nrf52840.h header: https://github.com/NordicSemiconductor/nrfx/blob/b5399066bd7f3dc32ee15510d06ef7137bcacf36/mdk/nrf52840.h#L105

  • Many thanks Vidar. I got your sample running. I had to change the definition for the port number to match the AIN0 port on the 52840 but then it worked fine. I then took your sample and tried to insert it into my program but I am running into an issue with the IRQ_CONNECT function. I am trying to use this with what is basically the Zigbee light switch sample using the ZBOSS zigbee stack. As soin as I call the IRA_CONNECT function the system faults and restarts.

    Is there some detail around how to make interrupts work with the ZBOSS stack?

  • Yes sorry, the pin number was wrong in my example. I didn't realize pin input was expressed as an index between 0-7. I thought you were supposed specify the actual GPIO pin number (P0.2 is assigned A0 on the 52840).

    The NRF_COMP_INPUT_n symbols defined in nrf_comp.h can be used instead.

    nrfx_comp_config_t  comp_config = NRFX_COMP_DEFAULT_CONFIG(NRF_COMP_INPUT_0);

    With regards to the fault you encountered, it turns out the OS is adding an offset to the input priority as you can see here link that causes the input priority to get out of range which cause an assertion to be raised. You can work around this you can increase priority to '5' as shown below.

        nrfx_comp_config_t  comp_config = NRFX_COMP_DEFAULT_CONFIG(NRF_COMP_INPUT_0);
        comp_config.interrupt_priority = 5;

    The reason it worked fine in the first sample is that the offset was only '1', while it's '2' when you use Zigbee.

    It's still not clear to me why Zephyr is changing the priority value. I will look more into that.

Reply
  • Yes sorry, the pin number was wrong in my example. I didn't realize pin input was expressed as an index between 0-7. I thought you were supposed specify the actual GPIO pin number (P0.2 is assigned A0 on the 52840).

    The NRF_COMP_INPUT_n symbols defined in nrf_comp.h can be used instead.

    nrfx_comp_config_t  comp_config = NRFX_COMP_DEFAULT_CONFIG(NRF_COMP_INPUT_0);

    With regards to the fault you encountered, it turns out the OS is adding an offset to the input priority as you can see here link that causes the input priority to get out of range which cause an assertion to be raised. You can work around this you can increase priority to '5' as shown below.

        nrfx_comp_config_t  comp_config = NRFX_COMP_DEFAULT_CONFIG(NRF_COMP_INPUT_0);
        comp_config.interrupt_priority = 5;

    The reason it worked fine in the first sample is that the offset was only '1', while it's '2' when you use Zigbee.

    It's still not clear to me why Zephyr is changing the priority value. I will look more into that.

Children
Related