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

Handling multiple GPIO pin interrupts

Hello,

I am working on pin interrupts and was able to handle with 1 pin interrupt. I used GPIOTE port interrupt. This is the code snippet for initialising:

	NRF_GPIO->PIN_CNF[Pin_Key] = (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
                             | (NRF_GPIO_PIN_PULLUP << GPIO_PIN_CNF_PULL_Pos)
                             | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
                             | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
NRF_GPIO->PIN_CNF[Pin_Key] |=
(PIN_SENSE_ENABLE | key_status) << GPIO_PIN_CNF_SENSE_Pos;
NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Set << GPIOTE_INTENSET_PORT_Pos;
NVIC_EnableIRQ(GPIOTE_IRQn);
NVIC_SetPriority(GPIOTE_IRQn, APP_IRQ_PRIORITY_LOW);

Here is the IRQ:

	if (NRF_GPIOTE->EVENTS_PORT == 0)		// Do we received port event?
{
	return;
}
NRF_GPIOTE->EVENTS_PORT = 0;			// Clear the port event

Now I need one more key to handle and configured in the same way as above. But I am not able to get for which pin interrupt, the ISR is called? Is there a pin interrupt flag bit in nRF51822?

Regards,
Sowmya

Parents
  • Hi Sowmya

    The only way to know this is to read the state of the GPIO's to see which of the pins are activated. This means you need to read the pins quick enough, to avoid the pin being de-activated before you have time to read it.

    In the nRF52832 we introduced a LATCH register that will latch the wakeup source, so that you won't lose wakeup events if they happen too quickly.

    Best regards
    Torbjørn

  • Correct. Just read the NRF_GPIO->IN register, and mask out the pins you are interested in.

    If you use GPIOTE IN events you will get independent events for each pin (up to 4 maximum in the nRF51822), and you will never drop events. The problem is that the sleep current will be significantly higher, so if you are trying to increase battery life you might want to stick to the PORT event.

Reply
  • Correct. Just read the NRF_GPIO->IN register, and mask out the pins you are interested in.

    If you use GPIOTE IN events you will get independent events for each pin (up to 4 maximum in the nRF51822), and you will never drop events. The problem is that the sleep current will be significantly higher, so if you are trying to increase battery life you might want to stick to the PORT event.

Children
No Data
Related