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

gpiote interrupt does not work when called for main loop

hello Nordic

i am working on nrf52840, SDK16.0 developing on the peripheral app_ble_blinky example.

i am use a pin as input interrupt from other device,

if i does all the init and enable (as shown in the first code below) before entering the main loop then i see i am getting in the interrupt handler, but if i try to do the same init or just the enable line after first part of init is done before main loop, then the interrupt handler doesnot get called, its like the interrupt is not enabled

void Accelerometer_init(void)
{
    ret_code_t err_code = 0;

    nrf_drv_spi_config_t accelo_spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
    // comm timer ppi config:

    // spi comm config:
    accelo_spi_config.ss_pin   = ACCELO_COMM_SPI_CS;
    accelo_spi_config.miso_pin = ACCELO_COMM_SPI_MISO;
    accelo_spi_config.mosi_pin = ACCELO_COMM_SPI_MOSI;
    accelo_spi_config.sck_pin  = ACCELO_COMM_SPI_CLK;   
    accelo_spi_config.frequency = NRF_SPI_FREQ_4M;
    //accelo_spi_config.orc = 0x00;
    err_code = nrf_drv_spi_init(&accelo_spi, &accelo_spi_config, accelo_spi_event_handler, NULL);
    APP_ERROR_CHECK(err_code);
//    nrf_gpio_pin_clear(DEBUG);
// config activity/free fall interrupt pin -> config in main
// config data ready pin input: 
    nrf_drv_gpiote_in_config_t int2_in_config = GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
    int2_in_config.pull = NRF_GPIO_PIN_NOPULL;

    err_code = nrf_drv_gpiote_in_init(ACCELO_INT2_SAMPLE_READY_INPUT_PIN_2, &int2_in_config, accelo_sample_ready_event_handler);
    APP_ERROR_CHECK(err_code);
    nrf_drv_gpiote_in_event_enable(ACCELO_INT2_SAMPLE_READY_INPUT_PIN_2, true); 
   
}

but if i call it like this:

void Accelerometer_init(void)
{
    ret_code_t err_code = 0;

    nrf_drv_spi_config_t accelo_spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
    // comm timer ppi config:

    // spi comm config:
    accelo_spi_config.ss_pin   = ACCELO_COMM_SPI_CS;
    accelo_spi_config.miso_pin = ACCELO_COMM_SPI_MISO;
    accelo_spi_config.mosi_pin = ACCELO_COMM_SPI_MOSI;
    accelo_spi_config.sck_pin  = ACCELO_COMM_SPI_CLK;   
    accelo_spi_config.frequency = NRF_SPI_FREQ_4M;
    //accelo_spi_config.orc = 0x00;
    err_code = nrf_drv_spi_init(&accelo_spi, &accelo_spi_config, accelo_spi_event_handler, NULL);
    APP_ERROR_CHECK(err_code);
//    nrf_gpio_pin_clear(DEBUG);
// config activity/free fall interrupt pin -> config in main
// config data ready pin input: 
    nrf_drv_gpiote_in_config_t int2_in_config = GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
    int2_in_config.pull = NRF_GPIO_PIN_NOPULL;

    err_code = nrf_drv_gpiote_in_init(ACCELO_INT2_SAMPLE_READY_INPUT_PIN_2, &int2_in_config, accelo_sample_ready_event_handler);
    APP_ERROR_CHECK(err_code);
//    nrf_drv_gpiote_in_event_enable(ACCELO_INT2_SAMPLE_READY_INPUT_PIN_2, true); 

}

and somewhere in main loop i call this:

        nrf_drv_gpiote_in_event_enable(ACCELO_INT2_SAMPLE_READY_INPUT_PIN_2, true);

after words i will call disable and then enable again since this interrupt should not be handled at all time of the program

any idea why?

i also left the spi in the init cause i saw on the forum that there maybe some priority issues but i am not sure it is relevant to my case cause if the init of the interrupt is done in the raise of the program it works

hope to read from you soon

best regards

Ziv  

  • Hi,

    Have you tried setting an error check when calling it in the main to see what the return value is?

    "after words i will call disable and then enable again since this interrupt should not be handled at all time of the program"

    I assume you have tried to enable it in the main without the disable and re-enable part?

  • hi Mttrinh

    Have you tried setting an error check

    the function :  void nrfx_gpiote_in_event_disable(nrfx_gpiote_pin_t pin)

    returns a void as can be seen, so i don't have a way to check for errors but passing the assertions.

    first loop when the init is called form initialization part it goes fine, then when i enter main loop after some time i disable like this:

    nrf_drv_gpiote_in_event_disable(ACCELO_INT2_SAMPLE_READY_INPUT_PIN_2);

    at later time in the program i go into:

    nrf_drv_gpiote_in_event_enable(ACCELO_INT2_SAMPLE_READY_INPUT_PIN_2, true);

    but if i put a breakpoint at the event handler i see no events are generated

    hope the scenario is clearer now.. any idea what i am doing wrong or how to fix that ?

    best regards

    Ziv

  • issue solved, the problem was not with the event enabling 

    since the sensing is of an input gpio, this gpio was held high while the event was disabled, when re-enabled it is still high but no event since the trigger was raise LOTOHI. fixed that and it works now 

    best regrds

    Ziv

Related