Go Down

Topic: Pin2 interrupt on Leonardo (Read 1 time) previous topic - next topic

dc509

Hi
Cannot get pin interrupt to work on pin 2 on a Leonardo.  Using latest version of IDE.  My research indicates this is a known issue but i have been unable to find a solution anywhere.  Does anyone know how I can get a pin interrupt to work on pin 2 (I require pin 3 for something else), or failing that pin 1 or 0?

d

pylon

It's definitely so that IDE 1.0.1 defines pin 3 as interrupt 0 and pin 2 as interrupt 1 but I cannot find any error in the code that would implicate that this shouldn't work.

Defining pin 0 as interrupt:

Code: [Select]
EICRA = (EICRA & ~((1<<ISC20) | (1<<ISC21))) | (mode << ISC20);
EIMSK |= (1<<INT2);


Defining pin 1 as interrupt:

Code: [Select]
EICRA = (EICRA & ~((1<<ISC30) | (1<<ISC31))) | (mode << ISC30);
EIMSK |= (1<<INT3);


The interrupt routines are defined then as

Code: [Select]
SIGNAL(INT2_vect) {
  // pin 0 service routine
}

SIGNAL(INT3_vect) {
  // pin 1 service routine
}


You could use the same type of code to try to activate pin 2:

Code: [Select]
EICRA = (EICRA & ~((1<<ISC10) | (1<<ISC11))) | (mode << ISC10);
EIMSK |= (1<<INT1);

SIGNAL(INT1_vect) {
  // pin 2 service routine
}


Please keep in mind that you cannot use the I2C interface (Wire library) while using the pins 2 and 3 (these pins are multiplexed to SDA and SCL). On pins 0 and 1 is the Serial1 on the Leonardo, so you cannot use that object if you use the pins for interrupts.

Markus_L811


Hi
Cannot get pin interrupt to work on pin 2 on a Leonardo.  Using latest version of IDE.  My research indicates this is a known issue but i have been unable to find a solution anywhere.  Does anyone know how I can get a pin interrupt to work on pin 2 (I require pin 3 for something else), or failing that pin 1 or 0?

d


Take a look at this http://arduino.cc/forum/index.php/topic,124057.0.html

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy