attachInterrupt() teensy 3.1 multiple ISR per interrupt

Status
Not open for further replies.

bloodline

Well-known member
Unfortunately I'm away from my Teensy 3.1 so I can't test this, but the documentation isn't clear so I'm going to ask to put my mind at rest.

The AVR can assign one ISR to a pin and one can select a trigger mode, Falling, Rising, Change etc...

With the ARM's more complex interrupt controller, is is possible to attach a separate ISR for each of the interrupt trigger modes of a single pin?

So one ISR for a rising state and another ISR for a falling state on a single pin?

Many thanks.
 
The pins can be configured to generate an interrupt request on either edge, i.e. rising and falling (PORTx_PCRn.IRQC, chapter 11.14.1). There is only one interrupt flag per port (!), so your ISR has to examine PORTx_ISFR (chapter 11.14.4) to see if an interrupt occured for your pin. If your signal doesn't change too quickly, you can read the pin level and then call the approriate subroutine (pin is low: there was a falling edge; pin is high: there was a rising edge). If only one pin per port generates interrupt requests, you don't have to check if it came from the right pin.

AFAIK (I'm a Cortex-M4 noob, btw) there is no method to get individual interrupts for each interrupt condition on one pin. If you have spare pins, you can feed your signal into two of them and configure one pin to generate an interrupt when a rising edge occurs, and one pin to generate an interrupt when a falling edge occurs.

So: what timing requirements do you have and what do you want to achieve? Maybe there's a totally different way to achieve what you want.

Regards

Christoph
 
Hi Christoph,

Many thanks for your reply. There is no problem only being able to attach a single ISR to a pin, I simply attachIntrrupt to the pin triggered by a state change and then do a check in the ISR for the state of the pin and direct the program flow after that.

My question was to see if this could be handled by the hardware, perhaps saving a few CPU cycles :)
 
Do you really need to save CPU cycles? If so, why? Don't try to optimize when there's no need.

I like to leave the ISR as quickly as possible, so a few cycles saved here and there are always a good idea :)
My programming history is writing games/demos on the Amiga, so optimization is everything ;)
 
Hi,

Where can I find a reference for ALL interrupt related functions that are available. The teensyduino interrupt.h file is empty, PJRC website has a page on using interrupts but it's not up to date for teensy 3.1, which I'm using, and no interrupts mentioned on the library compatibility page.

Thanks
 
Status
Not open for further replies.
Back
Top