I have a board with a 1284P and a UART tied to pin 42, which is digital pin 2 (Port PB2). I am trying to attach an interrupt to that pin to service the UART, but I can't seem to stumble upon the correct parameter values.
Below is the code from the example. I think they mean to be signaling an interrupt on pin 13, but I don;t understand how that related to pin 0 as passed to the attatchInterrupt function. Or maybe they mean to toggle an LED that is on pin 13 but don't include that code?
Anyhow, when I try to attach like this:
attachInterrupt(2, dataReceived, FALLING);
the call seems to succeed but the ISR is never called. I tried using pins 2, 42, 0 and 10 as arguments, no joy.
What did I screw up?
Thanks...
int pin = 13;
volatile int state = LOW;
void setup()
{
pinMode(pin, OUTPUT);
attachInterrupt(0, blink, CHANGE);
}
void loop()
{
digitalWrite(pin, state);
}
void blink()
{
state = !state;
}
The first argument is the interrupt vector number. On the Arduino UNO and similar boards, pin 2 is connected to external interrupt vector 0, and pin 3 is connected to interrupt vector 1.
I have a board with a 1284P and a UART tied to pin 42
Isn't there already an interrupt handling the receipt of serial data?
Below is the code from the example. I think they mean to be signaling an interrupt on pin 13, but I don;t understand how that related to pin 0 as passed to the attatchInterrupt function.
Something outside of the Arduino is sending a pulse to pin 2, which is connected to interrupt vector 0. When the pulse occurs, it ramps up, then back down. The interrupt handler identified (dataReceived) is called when the pulse begins to fall (because of the FALLING parameter).
In that interrupt handler, the state variable's value is changed. On each pass through loop, the value in that variable is used to set the state of pin 13.