Go Down

Topic: Changing Interrupt Pins (Read 1 time) previous topic - next topic


Nov 21, 2010, 12:17 am Last Edit: Nov 21, 2010, 12:33 am by vex Reason: 1
Hey everyone, after hours of searching I am still very confused as to how to attach interrupts to pins. I am trying to make an interrupt on DP8; this is the part of my code I am having trouble with:
Code: [Select]

#include <avr/interrupt.h>
#include <avr/io.h>

int recpin = 8;
int ledPin3 = 11;

void setup() {
 pinMode(ledPin3, OUTPUT);
 pinMode(recpin, INPUT);
 PCICR |= (1 << PCIE0);
 PCMSK0 |= (1 << PCINT0);
 attachInterrupt(8, ISR(PCINT0_vect), CHANGE);

void loop(){
some other functions

   digitalWrite(ledPin3, HIGH);

I'm not getting the led to turn on when the button on DP8 changes states.
Could anyone point me in the proper direction? I would be most appreciative.


Nov 21, 2010, 12:36 am Last Edit: Nov 21, 2010, 12:36 am by vex Reason: 1
I realize that, so I'm trying to add additional pins using Atmega commands, in the same way that the Arduino Mega gains additional interrupts. As I understand it, all IO pins on Atmega are covered by Pin Change Interrupts.


Nov 21, 2010, 12:51 am Last Edit: Nov 21, 2010, 12:52 am by billroy Reason: 1
I believe the problem is this: there are two types of pin related interrupts, and attachInterrupt() only handles one kind.  The wrong one, for your application.

The kind that attachInterrupt() handles is the External Interrupt Request, which is bound to the INT0 and INT1 pins.

The kind you seem to be requiring is a Pin Change interrupt, a different beast.  Any pin can be configured to generate this kind of interrupt; you set PCICR, PCIFR, and the appropriate PCMSKn.

Searching on pin-change interrupt here in the forum may be helpful as will be a look at the data sheet for the '328 at Section 12.2/page 71 from this url:




edit: great links vex!


Hmm, that makes sence. The closest replacement I can find for attachInterrupt() is in the third link I posted, where this code is claimed to work for pin 5:
Code: [Select]
 if (PIND & B00100000) // evaluates to TRUE when PortD bit #5 (Arduino digital pin #5) is HIGH

Unfortunately, I have no idea what the binary part means as it seems to correspond to pin #4.

Go Up