Anything wrong w this pin change interrupt code?

I want to generate interrupts from digital input 0 and digital input 1.
I am already using the hardware interrupts on 2 and 3 so I am trying to implement the pin change interrupts for that port.

This what I did (the two pins are named: CLK2_pin and RST2_pin)

pinMode(CLK2_pin, INPUT);   // Make digital 0 (PCINT16/PD0) an input
  pinMode(RST2_pin, INPUT);   // Make digital 1 (PCINT17/PD1) an input
   // Pin change interrupt control register - enables interrupt vectors
    // Bit 2 = enable PC vector 2 (PCINT23..16)
    // Bit 1 = enable PC vector 1 (PCINT14..8)
    // Bit 0 = enable PC vector 0 (PCINT7..0)
   PCICR |= (1 << PCIE2);
   // Pin change mask registers decide which pins are enabled as triggers
   PCMSK2 |= (1 << PCINT16);
   PCMSK2 |= (1 << PCINT17);

I also have the other intterupts attached:

 attachInterrupt(0, clockAISR, RISING);  // attach our interrupt pin to it's ISR   CLK
  attachInterrupt(1, resetAISR, RISING);  // attach our interrupt pin to it's ISR   CLK
  interrupts(); // we need to call this to enable interrupts

Since I am looking for changes on two pins from the same port I need to check both of those pins in the same ISR

//digitalRead RST2 to see if it is high then do something
//digitalRead CLK2 to see if it is high then do something

So far this is not working. Am I missing something?


Are you still stuck or did you figure out what was wrong?

Which board + processor are you using?

I ended up just copying the whole section from the playground Arduino Playground - PcInt and it works.

I would still like to know what I did wrong though!

Which board + processor are you using?

oops sorry I should have answered before:

Atmega328 duemenlove

I can spot only one difference. The order the registers are changed...

   PCMSK2 |= (1 << PCINT16);
   PCMSK2 |= (1 << PCINT17);

   PCICR |= (1 << PCIE2);

But I really doubt that makes a difference. I can't find anything in the datasheet about setting the registers in a particular order.

This is a snippet from a Sketch I wrote for a Teensy...

  /* PCMSK0 is the Pin Change Interrupt Mask, there are 8 pin change interrupts on various ports. We are using pin 6 on port B (PCINT6). */
  PCMSK0 |= (1<<PCINT6);
  /* Then pin change interrupts must be enabled globally by enabling the Pin Change Interrupt Enable 0 (PCIE0) flag. */
  PCICR |= (1<<PCIE0);

Do you really want to use pin 0 and pin 1? Those are RX and TX for serial communications.