Pages: [1]   Go Down
Author Topic: Pin2 interrupt on Leonardo  (Read 937 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
EICRA = (EICRA & ~((1<<ISC20) | (1<<ISC21))) | (mode << ISC20);
EIMSK |= (1<<INT2);

Defining pin 1 as interrupt:

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

The interrupt routines are defined then as

Code:
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:
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.
Logged

Germany
Offline Offline
Full Member
***
Karma: 10
Posts: 230
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: