Arduino BLE interrupt 83ms

I was trying to enable interrupts for my Arduino BLE sense, but it takes 83ms from the rising edge to the LED activating. That is HUGE (at 64MHz, ~5M instructions)!

Also, the LED blinks (but my code never turns it off).

#include "nrf.h"
#include "nrf_gpio.h"

#define LED1_PIN 13

void setup() {
  nrf_gpio_cfg_input(IN_PIN, NRF_GPIO_PIN_PULLDOWN);

  // interrupts
  NVIC_EnableIRQ(GPIOTE_IRQn); // enable interrupts
  NRF_GPIOTE->CONFIG[0] =  (GPIOTE_CONFIG_POLARITY_LoToHi << GPIOTE_CONFIG_POLARITY_Pos) // rising edge
                          | (IN_PIN << GPIOTE_CONFIG_PSEL_Pos) // pin
                          | (GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos); // input interrupts
  NRF_GPIOTE->INTENSET  = GPIOTE_INTENSET_IN0_Set << GPIOTE_INTENSET_IN0_Pos; // enable IN0 interrupt
   
  nrf_gpio_pin_clear(LED1_PIN);
}

void loop() {
}

void GPIOTE_IRQHandler(void)
{
  // for multiple interrupts:
  //if ((NRF_GPIOTE->EVENTS_IN[0] == 1) && (NRF_GPIOTE->INTENSET & GPIOTE_INTENSET_IN0_Msk));
  
  NRF_GPIOTE->EVENTS_IN[0] = 0; // clear interrupt flag
  nrf_gpio_pin_write(LED1_PIN, true);
}

Using Arduino's functions reduced the time to 10us, but even that I need to reach the function before 400ns from the interrupt.

#include "nrf.h"
#include "nrf_gpio.h"

#define LED1_PIN 13
#define IN_ARDUINO_PIN 9
#define IN_PIN 27

void myInterrupt() {
  nrf_gpio_pin_write(LED1_PIN, true);
}

void setup() {
  nrf_gpio_cfg_input(IN_PIN, NRF_GPIO_PIN_PULLDOWN);

  // interrupts
  NVIC_EnableIRQ(GPIOTE_IRQn); // enable interrupts
  attachInterrupt( digitalPinToInterrupt( IN_ARDUINO_PIN ), myInterrupt, RISING );
   
  nrf_gpio_pin_clear(LED1_PIN);
}

void loop() {
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.