managing and isr for pin change interrupt

Hello,

I want to use pin change interrupt on my mega board. I mean specifically, the those referred to by Atmel as PCINT0 PCINT1 and PCINT2 branching to vectors 0x12, 0x14, 0x16.

For the regular interrupts, one uses attacheinterrupt(pin, isr_name, mode) but in this case it's not a pin but rather ports B, E, J and K. Also, how do i mask pins of the ports to filter off from my isr things like the serial and the spi (used by ethernet)

Thanks in advance for your help

Guy

For the regular interrupts, one uses attacheinterrupt(pin, isr_name, mode)

No. The first argument is the interrupt number, not the pin number.

There is a pin change interrupt library that makes what you want to do easy.

Thanks Paul,
Per
http://www.arduino.cc/en/Reference/AttachInterrupt
One can use pin. BTW, arduino numbers interrupts differently than Atmel.

As for the library, I will continue searching

Per
http://www.arduino.cc/en/Reference/AttachInterrupt
One can use pin.

If you have a Due. Do you?

Have a look at Nick Gammon's excellent treatise on Interrupts

...R

Robin2:
Have a look at Nick Gammon's excellent treatise on Interrupts

...R

I did, he mentions a syntax which is not recognized:

ISR (INT0_vect
Or
ISR (PCINT0_vect)

Erc

Honestly I've read a lot of stuff before posting here.

he mentions a syntax which is not recognized:

By you? Or by the compiler?

you a right: i wrongly used lower case.

So it appears that to match a hw event to a piece of code one can either

attacheInterrupt(int#, code, qualifier)
or
ISR (int#)

As for the masking, guess i can low level access the relevant port control reg

Paul, I awe you one!

PaulS:
If you have a Due. Do you?

i have a mega

But than, how one matches all 3 PCINTs to just one isr?

But than, how one matches all 3 PCINTs to just one isr?

An ISR is just a function.

void fun1()
{
   haveFun();
}

void fun2()
{
   haveFun();
}

void fun3()
{
   haveFun();
}

void haveFun()
{
   // have some fun
}

Full list if ISR's is here It also gives the full usage of ISR() and shows a better way of hooking two interrupts to the same code than PaulS gave.

Mark

and shows a better way of hooking two interrupts to the same code than PaulS gave.

It's a different way. I don't see that it's a better way, unless ISR() is a macro. Even then, I'm not convinced.

PaulS:
An ISR is just a function.

void fun1()

{
  haveFun();
}

void fun2()

{
  haveFun();
}

void fun3()
{
  haveFun();
}

void haveFun()
{
  // have some fun
}

so specifically?
ISR (PCINT0_vect){process();}
ISR (PCINT1_vect){process();}
ISR (PCINT2_vect){process();}

so specifically?
ISR (PCINT0_vect){process();}
ISR (PCINT1_vect){process();}
ISR (PCINT2_vect){process();}

Along those lines, yes. Though process() is a really crappy name.

PaulS:
Along those lines, yes. Though process() is a really crappy name.

doesnt the executing code do just that? I doubt the processor ever feels fun

doesnt the executing code do just that? I doubt the processor ever feels fun

Yes, but suppose that the Arduino team had decided that digitalRead() was going to be called f123() and analogRead() was going to be f124() and digitalWrite() was f125() and analogWrite() was f322145().

Pretty confusing knowing what a function named f123() is supposed to do, isn't it?

It isn't at all obvious what process() does. Is process a verb? Or is it a noun?

Yes I think ISR is a macro. The one I linked was

ISR(PCINT0_vect)
{
  ...
  // Code to handle the event.
}

ISR(PCINT1_vect, ISR_ALIASOF(PCINT0_vect));

Which is explained as

Two vectors sharing the same code
In some circumstances, the actions to be taken upon two different interrupts might be completely identical so a single implementation for the ISR would suffice. For example, pin-change interrupts arriving from two different ports could logically signal an event that is independent from the actual port (and thus interrupt vector) where it happened. Sharing interrupt vector code can be accomplished using the ISR_ALIASOF() attribute to the ISR macro:

Note that there is no body to the alias ISR

Mark

Mark

PaulS:
Yes, but suppose that the Arduino team had decided that digitalRead() was going to be called f123() and analogRead() was going to be f124() and digitalWrite() was f125() and analogWrite() was f322145().

How about f01189998819991197253()?

Now that's easy to remember!

holmes4:
Yes I think ISR is a macro. The one I linked was

ISR(PCINT0_vect)

{
  ...
  // Code to handle the event.
}

ISR(PCINT1_vect, ISR_ALIASOF(PCINT0_vect));




Which is explained as 

Note that there is no body to the alias ISR

Mark

Mark

Thanks Mark, This works perfectly well.
Is there a mean to use attachInterrupt for the pin change interrupts?