When to use attachInterruptVector() Function

Dimitri

Well-known member
Hi All,

I am using Quad Timers to measure an external PWM signal and I was wondering if anyone could tell me the difference between attaching a Interrupt Service routine using

Code:
void setup()
{
  attachInterrupt(digitalPinToInterrupt(11), ISR_TMR1_CH2, FALLING);
}

or using
Code:
attachInterruptVector(IRQ_QTIMER1,Timer_ISR);  
NVIC_ENABLE_IRQ(IRQ_QTIMER1);

within the following setup function
Code:
unsigned long t1,t2;
unsigned long TestValue;

void setup()
{
  Setup_TMR1_CH2();
  attachInterrupt(digitalPinToInterrupt(11), ISR_TMR1_CH2, FALLING);
  t1 = millis();
  t2 = t1;
}
///////////////////////////////////////////////////////////////////////////////////////////////
void loop()
{
  t1 = millis();
  if((t1-t2) >= 500)
  {
    Serial.println(TestValue);
  }
}

///////////////////////////////////////////////////////////////////////////////////////////////
void Setup_TMR1_CH2()
{
  CCM_CCGR6 |= CCM_CCGR6_QTIMER1(CCM_CCGR_ON);

  TMR1_CTRL2 = 0; // stop
  TMR1_LOAD2 = 0;
  TMR1_CSCTRL2 = 0;
  TMR1_LOAD2 = 0;  // start val after compare
  TMR1_COMP12 = 0x00FF;  // count up to this val, interrupt,  and start again
  TMR1_COMP22 = 0x000F;
  TMR1_CMPLD12 = 0x0000;

  TMR1_SCTRL2 = TMR_SCTRL_CAPTURE_MODE(1);  //rising  
  TMR1_SCTRL2 |= TMR_SCTRL_TOFIE | TMR_SCTRL_TCFIE;  // enable interrupts  
  TMR1_CSCTRL2 |= TMR_CSCTRL_TCF1EN;  // enable interrupt
  attachInterruptVector(IRQ_QTIMER1,Timer_ISR);  
  NVIC_ENABLE_IRQ(IRQ_QTIMER1);
  
 
  TMR1_CTRL2 |=  TMR_CTRL_CM(1) | TMR_CTRL_SCS(2) | TMR_CTRL_LENGTH ; // prescale
  //*(portConfigRegister(11)) = 1;  // ALT 1  
   __asm volatile ("dsb");
  
}
///////////////////////////////////////////////////////////////////////////////////////////////
void Timer_ISR()
{
  TestValue = TMR1_CNTR2;
  TMR1_CNTR2 = 0;
  asm volatile ("dsb");  // wait for clear  memory barrier  
}

In this case, do I really need to have this below?
Code:
attachInterruptVector(IRQ_QTIMER1,Timer_ISR);  
  NVIC_ENABLE_IRQ(IRQ_QTIMER1);


Thank You!
 
attachInterrupt(...) - is used to connect an interrupt handler to one or more IO pins.
This is processed by one or more InterruptHandlers assigned an interrupt vector. Typically by IO ports.

You call attachInterruptVector when your code is actually processing the actual interrupt. For example your Quad timer one.

So for example on a T4.x, there is one InterruptVector that all of the IO ports interrupts will funnel to: IRQ_GPIO6789
 
Back
Top