Go Down

Topic: How to create 3th interrupt (Read 5 times) previous topic - next topic

Arnonh

I am getting this error with your code
Code: [Select]


error: '__vector_3' was not declared in this scope

EriSan500

I gave it a try too, and i'm also getting an error:

Code: [Select]

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


void setup() {
//pin change interrupt on digital pin 5
//this corresponds to PCINT0_vect  
PCICR |= (1 << PCIE0);
PCMSK0 |= (1 << PCINT21);

//pin change interrupt on digital pin 6
//this corresponds to PCINT1_vect
PCICR |= (1 << PCIE1);
PCMSK1 |= (1 << PCINT22);

//pin change interrupt on digital pin 7
//this corresponds to PCINT2_vect
PCICR |= (1 << PCIE2);
PCMSK2 |= (1 << PCINT23);
}

[glow]ISR_0( PCINT0_vect )[/glow]
{
     //do something
}

ISR_1( PCINT1_vect )
{
     //do something else
}

ISR_2( PCINT2_vect )
{
     //do something different
}

void loop()
{

}


error pointing to highlighted line:
Code: [Select]
error: expected constructor, destructor, or type conversion before '(' token

Any idea what i might be doing wrong?

Greetings,
EriSan500

EriSan500

#12
Dec 07, 2009, 02:33 pm Last Edit: Dec 07, 2009, 02:33 pm by erisan500 Reason: 1
ok, made some progress (dunno if this is correct though).

I changed
Code: [Select]
ISR_0( PCINT0_vect )
{
     //do something
}
ISR_1( PCINT1_vect )
{
     //do something
}
ISR_2( PCINT2_vect )
{
     //do something
}

to
Code: [Select]
ISR( PCINT0_vect )
{
     //do something
}
ISR( PCINT1_vect )
{
     //do something
}
ISR( PCINT2_vect )
{
     //do something
}


and it compiled without errors.
Will test this as soon as my new arduino's arrive.

Do i use DigitalRead(pin) inside the ISR to check if the port is HIGH or LOW ? Or is there a better way?

All i need to happen inside the ISR is to increase a counter.

Greetings,
EriSan500

FusiveResonance

#13
Dec 07, 2009, 04:14 pm Last Edit: Dec 07, 2009, 04:22 pm by FusiveResonance Reason: 1
Yes you may use digitalRead inside the ISR, but if you're finding it too slow you might have to ready the binary data directly from the register.

Don't forget to declare any variables used by the ISR as volatile.

Also, at the end of your setup() method, you'll want to call sei(). This will set the global interrupt enable bit. In case you ever want to reset the bit, (thereby turning off interrupts), you may use cli().

EriSan500

I finally got my 2nd arduino and got a chance to test this.

And yes, it does not work as expexted. See below code, if you spot the mistake I made, please let me know.

Code: [Select]

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


void setup() {
 pinMode(5, INPUT);
 Serial.begin(9600);

//pin change interrupt on digital pin 5
//this corresponds to PCINT0_vect  
PCICR |= (1 << PCIE0);
PCMSK0 |= (1 << PCINT21);

//pin change interrupt on digital pin 6
//this corresponds to PCINT1_vect
PCICR |= (1 << PCIE1);
PCMSK1 |= (1 << PCINT22);

//pin change interrupt on digital pin 7
//this corresponds to PCINT2_vect
PCICR |= (1 << PCIE2);
PCMSK2 |= (1 << PCINT23);
}

ISR( PCINT0_vect )
{
     //do something
Serial.println("interrupt on 5");
}

ISR( PCINT1_vect )
{
     //do something else
}

ISR( PCINT2_vect )
{
     //do something different
}

void loop()
{

}


Go Up