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

I cannot set gpio in interrupt funtion?example in examples/peripheral/pin_change_int?

I want to set gpio using one interrupt and want to clear it using another interrupt funtion?

void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
    nrf_drv_gpiote_out_set(PIN_OUT);
}
/**
 * @brief Function for configuring: PIN_IN pin for input, PIN_OUT pin for output,
 * and configures GPIOTE to give an interrupt on pin change.
 */
static 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(true);

    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_LOTOHI(true);
    in_config.pull = NRF_GPIO_PIN_PULLUP;

    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);
}

It seems i can only use the toggle funtion ,if i use the nrf_drv_gpiote_out_set it does not set it.

Parents
  • Is there a reason why you use gpiote for the output pin?

    Try something like this instead:

    void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {
        if(pin == PIN_SET)
        {
            nrf_gpio_pin_set(PIN_OUT);
        }
        else if(pin == PIN_CLEAR)
        {
            nrf_gpio_pin_clear(PIN_OUT);
        }
    }
    
    /**
     * @brief Function for configuring: PIN_IN pin for input, PIN_OUT pin for output,
     * and configures GPIOTE to give an interrupt on pin change.
     */
    static void gpio_init(void)
    {
        ret_code_t err_code;
        
        nrf_gpio_cfg_output(PIN_OUT);
    
        err_code = nrf_drv_gpiote_init();
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
        in_config.pull = NRF_GPIO_PIN_PULLUP;
    
        err_code = nrf_drv_gpiote_in_init(PIN_SET, &in_config, in_pin_handler);
        APP_ERROR_CHECK(err_code);
        
        err_code = nrf_drv_gpiote_in_init(PIN_CLEAR, &in_config, in_pin_handler);
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_gpiote_in_event_enable(PIN_SET, true);
        nrf_drv_gpiote_in_event_enable(PIN_CLEAR, true);
    }

  • I am little confused. If PIN_SET and PIN_CLEAR are two pins what is the value of (pin). and nrf_drv_gpiote_in_event_enable(PIN_SET,true) is used to set the interrupt.

  • 'pin' is the pin number of the GPIO that triggered the GPIOTE interrupt.

Reply Children
No Data
Related