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

What function should be used to associate an interrupt with an event?

I wanted to know the function or functions and the steps to associate an interrupt with an event.

I will be getting a single Pulse(Low To High) which will be my interrupt signal.

I wanted to read this and generate an event to sleep.

Can someone please let me know the step by step function's usage?

Parents Reply
  • Hello Andreas, Thank you for your reply.

    could you please explain me the function line by line or step by step in the code snippet.

    I did go through the links- 

    a.) https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v13.0.0%2Fgroup__nrf__drv__gpiote.html

    b.) https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.0.0%2Fgroup__nrf__drv__gpiote.html

    c.) https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.3.0%2Fgroup__nrf__drv__gpiote.html&anchor=ga00970227fc2c393fbbc71b3d362b58c2

    But I didnt understand anything properly. 

    Also, I wanted to know how to generate an event and associate it with the pins as I didnt understand anything.

    I would like to request you to kindly please not provide links with just 1 line explanations, but brief explanations as my knowledge is less. If required kindly please also provide links to tutorials or explanations needed to be read beforehand.

    I apologize if I am sounding rude, it was not the intention, but to give you a better idea in order to assist me. 

    Also how does this line work- nrf_drv_gpiote_in_init(PIN_IN, &in_config, in_pin_handler); ?  Please explain in brief

    As in_pin_handler is a function and also not of type  nrfx_gpiote_evt_handler_t   but void ? Please explain in brief

    And also why does nrf_drv_gpiote_in_init does throw an error when in_pin_handler is called on being of a void type and not nrfx_gpiote_evt_handler_t .?  Please explain in brief

    Q2- How are the parameters being passed to in_pin_handler in nrf_drv_gpiote_in_init?  Please explain in brief

    Q3- How and where are the "action" parameter being generated  and passed? Please explain in brief.

    Q4- Also how to associate the action(function name(s) too) with an event to put the device to sleep or any other event I want to use it for? Please explain in brief.

     

    tatic void gpio_init(void)
    {
        ret_code_t err_code;
    
        err_code = nrf_drv_gpiote_init();
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(false);
    
        err_code = nrf_drv_gpiote_out_init(PIN_OUT, &out_config);
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
        in_config.pull = NRF_GPIO_PIN_PULLDOWN;
    
        err_code = nrf_drv_gpiote_in_init(PIN_IN, &in_config, in_pin_handler);
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_gpiote_in_event_enable(PIN_IN, true);
    }

Children
  • Also, my input is a single pulse of Low To High To low of 50 ms.

    I want to read that , generate an event , pass that event to put the device to sleep

  • Hello ANdreas, there is another thing, I want to combine this code https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v17.0.2%2Fpin_change_int_example.html&cp=7_1_4_6_20

    and this https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v17.0.2%2Fpin_change_int_example.html&cp=7_1_4_6_20

    Basically I want to generate an event using the interrupt to put the device to sleep- or lets say a counterpart to bsp_event_to_button_action_assign(BTN_ID_RESET,BSP_BUTTON_ACTION_RELEASE,BSP_EVENT_RESET); this function.

  • Hi,

     

    First off, do yourself a favour and use the latest SDK (v17.0.2) as this contains improvements, bug fixes and supports the latest devices. This could save you time and frustration down the road.

     

    Summarized this example idles in the main loop until it gets an interrupt from the GPIO (button) being toggled, in which case it executes the code inside the event handler.

     

    RJD said:
    Also how does this line work- nrf_drv_gpiote_in_init(PIN_IN, &in_config, in_pin_handler);

     This initates GPIOTE on PIN_IN using the settings in in_config, and triggering an interrupt on the in event which will run the code in in_pin_handler.

     

     

    RJD said:
    As in_pin_handler is a function and also not of type  nrfx_gpiote_evt_handler_t   but void

     Not sure why this is done, you can change this if you want.

     

     

    RJD said:
    And also why does nrf_drv_gpiote_in_init does throw an error when in_pin_handler is called on being of a void type and not nrfx_gpiote_evt_handler_t

    Not sure what you mean, this builds fine on my side.

     

     

    RJD said:
    How are the parameters being passed to in_pin_handler in nrf_drv_gpiote_in_init

    Not sure I understand what you mean. This is handled by the driver though, you should look through the code and documentation.

     

     

    RJD said:
    Q3- How and where are the "action" parameter being generated  and passed

    Do you mean what is triggering the event?  This is determined through the settings in the in_config supplied when calling nrf_drv_gpiote_in_init: in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true).

     

     

    RJD said:
    Q4- Also how to associate the action(function name(s) too) with an event to put the device to sleep or any other event I want to use it for?

    Not sure I understand, but it is hard to give a generic solution. It depends on what you want to do, but in general when the chip has executed the event handler it will return to the main while loop in this case. To go to sleep you might need to add a __WFE(); in the main loop.

     

    Best regards,

    Andreas

Related