This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

detect button toggle with PORT event

Hi,

I am trying to use the PORT event to trigger interrupts when a button is toggled, i.e. both on LoToHi and HiToLo.

To my understanding PORT events are generated by the DETECT signal which is sent if a pin has sense enabled. It seems sense can only be set to disabled, high or low, there is no toggle option. Is it possible to use the PORT event to generate interrupts on button toggle? If so, how?

Below is my test code:

// Test application that toggles a LED on button click    
extern "C" void GPIOTE_IRQHandler(void) {
        // Any pin interrupt will trigger the PORT event
        if ((NRF_GPIOTE->EVENTS_PORT != 0) && (NRF_GPIOTE->INTENSET & GPIOTE_INTENSET_PORT_Msk)) {
          // Reset PORT event
          NRF_GPIOTE->EVENTS_PORT = 0;
          // Toggle LED
          pinToggle(LED_RED);
        }
    }

int main(void) {
  // LED Init
  setupLEDPins();

  // Set up interrupt
  pinInput(BUTTON_1, Pull::Up);
  // Here I want to find a way to generate the detect signal on toggle
  setPinSense(BUTTON_1, Sense::LOW); 

  // Enable interrupt
  NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Msk;
  NVIC_ClearPendingIRQ(GPIOTE_IRQn);
  NVIC_SetPriority(GPIOTE_IRQn, 3);
  NVIC_EnableIRQ(GPIOTE_IRQn);

  while (true) {
    pinToggle(LED_GREEN);
    delayMs(100);
  }
}

Grateful for some help, thanks!

Related