I'm implementing an I2C communication and I need to set an interruption every time the sensor sets the interrupt pin to 0. I've been checking some other posts from devzone and arrived at the conclusion that the code should look like this:
Initialization
void init_externalInterrupt(void){
nrf_gpio_cfg_input(0x08, NRF_GPIO_PIN_NOPULL);
NVIC_DisableIRQ(GPIOTE_IRQn);
NVIC_ClearPendingIRQ(GPIOTE_IRQn);
NRF_GPIOTE->CONFIG[0] = (GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos)
| (0x08 << GPIOTE_CONFIG_PSEL_Pos)
| (GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos);
NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN0_Set << GPIOTE_INTENSET_IN0_Pos;
NRF_GPIOTE->CONFIG[0] = (GPIOTE_CONFIG_POLARITY_HiToLo <<
GPIOTE_CONFIG_POLARITY_Pos)
| (0x1D << GPIOTE_CONFIG_PSEL_Pos)
| (GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos);
NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN1_Set << GPIOTE_INTENSET_IN1_Pos;
__NOP();
__NOP();
__NOP();
/* Clear the event that appears in some cases */
NRF_GPIOTE->EVENTS_IN[0] = 0;
NRF_GPIOTE->EVENTS_IN[1] = 0;
NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN0_Enabled << GPIOTE_INTENSET_IN0_Pos;
NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN1_Enabled << GPIOTE_INTENSET_IN1_Pos;
NVIC_EnableIRQ(GPIOTE_IRQn);
}
Vector Interrupt
/**@brief Function for handling the GPIOTE interrupt.
*/
void GPIOTE_IRQHandler(void)
{
uint8_t i;
uint32_t pins_changed = 1;
uint32_t pins_sense_enabled = 0;
uint32_t pins_sense_disabled = 0;
uint32_t pins_state = NRF_GPIO->IN;
// Event causing the interrupt must be cleared.
nrf_gpio_pin_set(28);
if ((NRF_GPIOTE->EVENTS_IN[0] == 1) || (NRF_GPIOTE->EVENTS_IN[1] == 1)
{
NVIC_DisableIRQ(GPIOTE_IRQn);
NVIC_ClearPendingIRQ(GPIOTE_IRQn);
NRF_GPIOTE->INTENSET = 0x00000001;// enable interrupts for config[n] pins, n = 0 in this case so bitmask is 0x01
NVIC_SetPriority(GPIOTE_IRQn, 3); //optional: set priority of interrupt
NVIC_EnableIRQ(GPIOTE_IRQn);
NRF_GPIOTE->EVENTS_IN[0] = 0;
NRF_GPIOTE->EVENTS_IN[1] = 0;
nrf_gpio_pin_set(28);
}
}
As you can see, I set a LED pin to HIGH in order to see if the software has entered in the interrupt, but it keeps off all the time although the interruption pin is receiving a periodical 0 every 50 ms.