SparkFun SAMD21 Dev Breakout: How to setup an External Interrupt

Hi,

After some exhaustive reading it seems one cannot use attachInterrupt( interrupt pin, callback function, edge type) on SAMD21g18.

I have tried using this command in my sketch on a pwm pin (pin8) but it fails. Also tried on non-pwm pin (pin2) but to no avail.

However I found an example code using what is referred to as “bare metal interrupt setup” where one has to muck around with registeres at a low level in order to setup a reliable interrupt except I ran into a brick wall where at the end of the example sketch they say one must use specifically a callback function called void EIC_Handler() {…}.

When I tried to compile my code I go the error:

C:\Users\labbady\AppData\Local\Arduino15\packages\SparkFun\hardware\samd\1.7.5\cores\arduino/WInterrupts.c:185: multiple definition of `EIC_Handler’

It so happens sparkfun has this function already defined here: “WInterrupts.c” on line 185

I need help from anybody how to deal with this problem. Below is my function for setting up an external Interrupt. Anybody out there that is an expert with SAMD21G18 interrupt setup, please look at this code and see if it is good and also help with the above compiler error. If it is not please point out the relevant corrections I need to make to get it to work. I am using the Arduino sketch editor and it is set for compiling the “SparkFun SAMD21 Dev Breakout” MCU. Thanks in advance

void interruptSetup()
{
 
  /* -------------------------------------------------
   * 1) Disable Interrupt and Set Priority
   */
  // disable external interrupt controller
  NVIC_DisableIRQ(EIC_IRQn);
  
  // clear device specific interrupt from pending
  NVIC_ClearPendingIRQ(EIC_IRQn);
  
  // set interrupt priority
  NVIC_SetPriority(EIC_IRQn, 0);
  
  
  /* -------------------------------------------------
   * 2) Setup Interrupt Pin
   */
  PORT->Group[PORTA].PINCFG[ (07ul) ].reg = PORT_PINCFG_PMUXEN; // Pin pullup and enable MUX'ing
  PORT->Group[PORTA].PMUX[ (07ul) << 1 ].bit.PMUXE = MUX_PA07A_EIC_EXTINT7; // Set up IRQ-pin (PA7) to special function A (External Interrupt 7)
  
  
  /* -------------------------------------------------
   * 3) select EIC clock
   */
  GCLK->CLKCTRL.reg = 
  GCLK_CLKCTRL_ID(EIC_GCLK_ID) |  // select EIC clock
  GCLK_CLKCTRL_CLKEN |            // enable the clock
  GCLK_CLKCTRL_GEN(0);            //  select GCLK GEN0
  
  
  /* -------------------------------------------------
   * 4) Set to Vanilla State
   */
  // software reset on EIC
  EIC->CTRL.bit.SWRST = 1;
  
  // wait for synchronization
  while ((EIC->CTRL.bit.SWRST == 1) && (EIC->STATUS.bit.SYNCBUSY == 1));
  
  
  /* -------------------------------------------------
   * 5) Configure and Enable Interrupt
   */
  
  // falling edge detection
  // filter 7 enable
  // config 0 for EXTINT 0-7 and config 1 for EXTINT 8-15
  EIC->CONFIG[0].reg |= EIC_CONFIG_SENSE7_RISE | EIC_CONFIG_FILTEN7;
  
    
  // enable the interrupt
  EIC->INTENSET.bit.EXTINT7 = 1;
  EIC->CTRL.bit.ENABLE = 1;
  
  // wait for synchronization 
  while(EIC->STATUS.bit.SYNCBUSY == 1);
  
  // enable the interrupt
  NVIC_EnableIRQ(EIC_IRQn);
}

/*
 * Function:        void EIC_Handler(void)
 * PreCondition:    None
 * Input:           None
 * Output:          None
 * Side Effects:    None
 * Overview:        This function is our external interrupt handler
 */
void EIC_Handler()
{
  // if external interrupt detected
  if ( (EIC->INTFLAG.reg & (EXT0_PIN_MASK) ) != 0 )
  {
    // Turn the LED on PA17 ON
    REG_PORT_OUTSET0 = P8_PIN_MASK;
    
    // delay 3000 ms
    myDelay(3000);
    
    // clear interrupt flag
    EIC->INTFLAG.reg = (EXT0_PIN_MASK);
  }
}

:?

Try using enableInterrupt instead? https://forum.mysensors.org/topic/1409/ … terrupts/9 & https://github.com/GreyGnome/EnableInterrupt/issues/33 and see how that goes