Pro Mini interrupt on chage problem

Hi - Arduino newbie I'm afraid. Need to get an interrupt on change from pin A2 on a Pro mini with 328 chip. Input pins are correctly configured as tested with my meter. However no interrupt occurs.

Program simply sets up Interrupt on change and should trigger the service routine which sets a global variable (portrd) to 1 which then tells the main loop to print a message.

Any help much appreciated.

Best Regards

picclock

//My attempt at a single interrupt pin

volatile byte portrd;

void setup() { Serial.begin(9600); Serial.println("Simple Pin Change Interrupt"); // Define the input pins

static int pinB = A2; // hardware interrupt pin static int pinC = A1; // second input digital pin

pinMode(pinA, INPUT_PULLUP); // set pinA as switch input, pulled HIGH pinMode(pinB, INPUT_PULLUP); // set pinB as an input, pulled HIGH

void InitialiseInterrupt(); }

void InitialiseInterrupt(){ cli(); // switch interrupts off while messing with their settings PCICR =0x02; // Enable PCINT1 interrupt PCMSK1 = 0b00000100; // set mask for interrupts needed - just bit 2 sei(); // turn interrupts back on }

void loop() { // put your main code here, to run repeatedly: if (portrd != 0) {Serial.println("Int called"); portrd=0; } }

ISR(PCINT1_vect) { //interrupt service routine portrd = 1; }

Need to get an interrupt on change from pin A2 on a Pro mini with 328 chip. Input pins are correctly configured as tested with my meter. However no interrupt occurs.

Is A2 actually an external interrupt pin?

According to my info A2 is PC2, and PCINT10. I find the numbering confusing as its also pwm pin 16.

Best Regards

picclock

The name, A2, in your sketch refers to using analog pin 2 as a digital pin. Analog pins do not support external interrupts on any Arduinos that I know of.

That code won’t compile, for obvious reasons.

Please post code that will actually compile, using code tags (edit your original post and use the “</>” button).

All pins on 328P chips support PCINTs. Some pins also go to the Analog mux.
A0 to A5 are PCINT8 to PCINT13.

A2 = D10 is also a PWM capable pin, using analogWrite(A2, 127) is a common way to do that.

I think you need something along the lines of volatile byte portrd; before setup() so you can share info between the ISR and the loop() code.

Not sure where you got "pwm pin 16" from. I don't know how to put that in context with anything.

@jremington code compiles perfectly with no errors- or at least it would do if the pinC declaration is changed to PinA. This is not used anyway - the code is extracted from a much larger project.

@crossroads portrd declared as volatile byte

The port numbers and assignations were taken from The Unofficial ProMini diagram on the web.

http://t.co/3ACrZVFG89

Best Regards

picclock