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

Interrupt Configurations in pin_change_init example

Hi,

I am working on the "pin_change_init" example to develop my interrupt based function.

I have added three pins/buttons into it and out of which only are working properly. I don't know why it is like so.

Is their any limitation or setting in which we have define the max pin/buttons which we are going to used ... ???

For more I am sharing my developed code for reference ... if I am going wrong please correct me ...

My code : 

/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
 *
 * The information contained herein is property of Nordic Semiconductor ASA.
 * Terms and conditions of usage are described in detail in NORDIC
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 *
 * Licensees are granted free, non-transferable use of the information. NO
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 * the file.
 *
 */

/** @file
 * @defgroup pin_change_int_example_main main.c
 * @{
 * @ingroup pin_change_int_example
 * @brief Pin Change Interrupt Example Application main file.
 *
 * This file contains the source code for a sample application using interrupts triggered by GPIO pins.
 *
 */

#include <stdbool.h>
#include "nrf.h"
#include "nrf_drv_gpiote.h"
#include "app_error.h"
#include "boards.h"
#include "nrf_delay.h"
#include "nrf_gpio.h"


#define PIN_IN 			06
#define PIN_IN_1 		07
#define PIN_IN_2 		03
#define PIN_OUT 		13
#define PIN_OUT_1		14


void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
  if(pin == PIN_IN)  
	{
		nrf_drv_gpiote_out_toggle(PIN_OUT);
	}
	
	if(pin == PIN_IN_1){
	nrf_drv_gpiote_out_toggle(PIN_OUT);
	}
	
	if(pin == PIN_IN_2)
	{
		nrf_drv_gpiote_out_toggle(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(false);

    err_code = nrf_drv_gpiote_out_init(PIN_OUT, &out_config);
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_out_config_t out_config_1 = GPIOTE_CONFIG_OUT_SIMPLE(false);

    err_code = nrf_drv_gpiote_out_init(PIN_OUT_1, &out_config_1);
    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_NOPULL;

    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);
	
	
	
	nrf_drv_gpiote_in_config_t in_config_1 = GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
    in_config_1.pull = NRF_GPIO_PIN_PULLDOWN;

    err_code = nrf_drv_gpiote_in_init(PIN_IN_1, &in_config_1, in_pin_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_in_event_enable(PIN_IN_1, true);
	
	
		
	nrf_drv_gpiote_in_config_t in_config_2 = GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
    in_config_2.pull = NRF_GPIO_PIN_NOPULL;

    err_code = nrf_drv_gpiote_in_init(PIN_IN_2, &in_config_2, in_pin_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_in_event_enable(PIN_IN_2, true);
		
}

/**
 * @brief Function for application main entry.
 */
int main(void)
{
    gpio_init();
	
    while (true)
    {
					
        // Do nothing.
			
    }
}


/** @} */

Here My

nrf_drv_gpiote_in_config_t in_config_2 = GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
in_config_2.pull = NRF_GPIO_PIN_NOPULL;

err_code = nrf_drv_gpiote_in_init(PIN_IN_2, &in_config_2, in_pin_handler);
APP_ERROR_CHECK(err_code);

nrf_drv_gpiote_in_event_enable(PIN_IN_2, true);

IN this PIN_IN_2 was not working in my code .... 

Looking forward for the solution ....

Thanks

Related