Go Down

Topic: MKRZERO D2 and D3 attachinterrupts (Read 984 times) previous topic - next topic

tjohnny88


I can't seem to get interrupts to work on D2 (PA10) and D3 (PA11) using:



attachInterrupt(digitalPinToInterrupt(2), count, CHANGE);



Are these 2 pins not interrupt compatible in Arduino?

THanks

pert

As stated in the attachInterrupt() documentation, the pins you can use with this function are:
https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/
Quote
MKR Family boards  0, 1, 4, 5, 6, 7, 8, 9, A1, A2

tjohnny88

Yes but pins 2,3 seem to have interrupts based on the chips datasheet.  I'm stuck using those 2 pins and trying to make it work.

pert

There are different types of interrupt capabilities of pins. For example, although only pins 2 and 3 of the Arduino Uno have the external interrupt capability required by attachInterrupt(), all the Uno's IO pins have pin change interrupt capability. You are welcome to use the interrupt functionality of pins 2 and 3 on your MKR Zero. You just can't use them with attachInterrupt().

tjohnny88

Do you have any idea on how to do that?


That is where I'm stuck

Juraj

#5
Aug 09, 2019, 10:40 pm Last Edit: Aug 09, 2019, 10:42 pm by Juraj
Do you have any idea on how to do that?


That is where I'm stuck
Why can't you use one of the pins available for attachInterrupt?

this is interrupt setup for pin 5. for 2 it is not enough to change the number

Code: [Select]

  REG_GCLK_CLKCTRL = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID (GCM_EIC)) ;
  while ( GCLK->STATUS.bit.SYNCBUSY == 1 );

  EIC->CTRL.bit.ENABLE = 1;
  while (EIC->STATUS.bit.SYNCBUSY == 1);

  const PinDescription& interruptPinDesc = g_APinDescription[5];

  PORT->Group[interruptPinDesc.ulPort].PINCFG[interruptPinDesc.ulPin].bit.PMUXEN = 1;
  PORT->Group[interruptPinDesc.ulPort].PMUX[interruptPinDesc.ulPin >> 1].reg |= PORT_PMUX_PMUXO_A;

  EIC->CONFIG[1].reg |= EIC_CONFIG_SENSE0_FALL_Val << ((interruptPinDesc.ulExtInt - 8) << 2);
  EIC->EVCTRL.reg |= 1<<interruptPinDesc.ulExtInt;
  EIC->INTENSET.reg = EIC_INTENSET_EXTINT(1<<interruptPinDesc.ulExtInt);
  NVIC_EnableIRQ(EIC_IRQn);

tjohnny88

Why can't you use one of the pins available for attachInterrupt?



The custom hardware has already been made. Trying to fix this with software

Juraj

The custom hardware has already been made. Trying to fix this with software
then create a custom hardware definition where you enable interrupt on pin 2.
it is simple.
start with https://github.com/jandrassy/my_boards
then modify variant.cpp

Go Up