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

How to use GPIOTE_IRQHandler for multiple interrupt request ?

Hi,

I have an issue in using GPIOTE_IRQHandler.

Let me give an explanation about our implementaiton.

we have nRF controller which is connected to STM32 controller.

Currently the GPIO pin P0.17 on nRF is used as a interrupt pin for NRF for some purpose.

Now i am planning to implement system off mode on nRF side, i am using GPIO P0.20 as nRF interrupt to wake up from the system off mode.

But how i can use GPIO interrupt handler GPIOTE_IRQHandler for the above two interrupt.

Can you please guide me on this and share some examples for the same.

Regards, Anand

Parents
  • Hi Anand,

    Could you upload your full code ?

    To configure a GPIO pin to work as input interrupt for GPIOTE Port event, besides enabling "NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Set << GPIOTE_INTENSET_PORT_Pos;"

    You would also need to configure the PIN_CNF[] register for that pin to set the SENSE level (high or low). You can have a look at chapter 14 in the nRF51 Reference Manual.

    You can use this API: nrf_gpio_cfg_sense_input() to configure a pin as input for SENSE signal.

    So if you have that configured for pin P0.17 you can apply the same for pin P0.20.

    PORT event and IN[] are different in the sense that for PORT event there is only one interrupt for all pins with Sense signal. IN events, you have 4 separated event for each, but you have maximum 4 pins can be used at a time when PORT event can have no limit pins with Sense signal. PORT event consume much less power (1uA) compare to IN event that can comsume upto 1mA. Also IN event can't wake system up from SystemOFF.

Reply
  • Hi Anand,

    Could you upload your full code ?

    To configure a GPIO pin to work as input interrupt for GPIOTE Port event, besides enabling "NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Set << GPIOTE_INTENSET_PORT_Pos;"

    You would also need to configure the PIN_CNF[] register for that pin to set the SENSE level (high or low). You can have a look at chapter 14 in the nRF51 Reference Manual.

    You can use this API: nrf_gpio_cfg_sense_input() to configure a pin as input for SENSE signal.

    So if you have that configured for pin P0.17 you can apply the same for pin P0.20.

    PORT event and IN[] are different in the sense that for PORT event there is only one interrupt for all pins with Sense signal. IN events, you have 4 separated event for each, but you have maximum 4 pins can be used at a time when PORT event can have no limit pins with Sense signal. PORT event consume much less power (1uA) compare to IN event that can comsume upto 1mA. Also IN event can't wake system up from SystemOFF.

Children
  • Hi ,

    I cannot share the full code due to confidentiality. But I can give some hint on that.

    for GPIO pin P0.17 .

    static void function_1(void) {

    	  NRF_GPIO->PIN_CNF[IO1_NRF] = (GPIO_PIN_CNF_SENSE_Low << GPIO_PIN_CNF_SENSE_Pos)
    	                                        | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
    	                                        | (NRF_GPIO_PIN_NOPULL << 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);
    

    // Set correct IRQ priority and clear any possible pending interrupt. NVIC_SetPriority(GPIOTE_IRQn, SPI1_TWI1_IRQ_PRI); NVIC_ClearPendingIRQ(GPIOTE_IRQn); NVIC_EnableIRQ(GPIOTE_IRQn); NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Set << GPIOTE_INTENSET_PORT_Pos; }

    void GPIOTE_IRQHandler(void) {

    // Event causing the interrupt must be cleared if ((NRF_GPIOTE->EVENTS_PORT != 0)) { NRF_GPIOTE->EVENTS_PORT = 0; }

    nrf_gpio_pin_clear(P0.12);

    }

    Now i am using GPIO P0.20 for nRF wake up from system sleep mode.

    How i can configure this pin to wake up from system off mode and how i can handle interrupt handler GPIOTE_IRQHandler. Please give some line of code for the same to test.

    Regards, Anand

  • @Anand: You can just make another PIN_CNF[] configuration for pin P0.20 and it will be able to do the same thing as P0.17:

    NRF_GPIO->PIN_CNF[20] = (GPIO_PIN_CNF_SENSE_Low << GPIO_PIN_CNF_SENSE_Pos)
                                            | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
                                            | (NRF_GPIO_PIN_NOPULL << 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);
    

    You can also have a look at ram_retention example where we use nrf_gpio_cfg_sense_input to configure the wakeup pin, it's pretty much the same.

  • @all, I have a simular question. I use the API nrf_gpio_cfg_sense_input() to configure two pin as input for SENSE signal. But the two pins have different SENSE level. One is "NRF_GPIO_PIN_SENSE_HIGH" and the other is "NRF_GPIO_PIN_SENSE_LOW". How can I confugure like this? Thanks a lot.

  • @Rita: Please create another question don't piggybacking a question here.

    I don't see any reason why you can't configure 2 pins with different sense level. You just have to call the nrf_gpio_cfg_sense_input() 2 times, one for each pin.

Related