Pin change interrupt

Is it possible to use the pin change interrupt function (library) on Pin 27 or pin 28. Reading through the documentation it doesn't look like it.

Of which Arduino?

I am expecting this program to set value to 1 or 2 when I ground pin 27 or 28.

It never leaves main.

#include <avr/interrupt.h>

volatile int value = 0;

void setup()
{
	cli();
	PCICR |= 0b00000010; // Enables C Pin Change Interrupts

	PCMSK1 |= 0b110000; // PCINT11
	sei();

	
									//SPI master in slave out


		pinMode(28, INPUT_PULLUP);								//pin 28
		pinMode(27, INPUT_PULLUP);							//pin 27
		digitalWrite(28, HIGH);
		digitalWrite(27, HIGH);
	
	}

	Serial.begin(9600);
}

void loop()
{
	Serial.println(value);
}

ISR(PCINT0_vect)
{
	value= 1;
}

ISR(PCINT1_vect)
{
 value= 2 ;
}

Processor?

sorry arduino uno

arduino uno sorry

mstadtler:
...when I ground pin 27 or 28.

mstadtler:
arduino uno

  • ? -

@mstadtler, are you serious? I have been replying to you on your other thread on this exact same topic. You have wasted my time. You have wasted @PaulS's time. You have wasted your time.

DO NOT CROSS-POST. Threads merged.

Let me guess, you are programming in Atmel Studio, and referring to pin numbers on the atmega328p chip?

Pins 27 and 28 are A4 and A5 for the Arduino IDE.

Anyways, pin change interrupts (PCINT) is available on those pins, but as I understand it, you get to define one ISR for all pins on the same port, in your case C port. Haven't played with the PCINT interrupts yet, only the two hardware interrupts, and only within the Arduino IDE.

Just wanted to help clearing this up, since the Arduino Uno has no pins 27 and 28, though the Atmel atmega328p of course does.

Would not ISR(PCINT2_vect) handle the PC-interrupts for these pins?

Whandall:
Would not ISR(PCINT2_vect) handle the PC-interrupts for these pins?

[Edit]
On closer thought, I’m not sure. The naming scheme can be a bit confusing. There is supposedly three PCINT-vectors, and I have read that these corresponds to the portd B, C and D of the atmega328p, but elsewhere I have read that each of the PCINT0_vect, PCINT1_vect and PCINT2_vect, work for 8 pins each.

Now this is a bit confusing, since ports B and D have 8 pins each, while port C only has 7 pins.
Still, it is reasonable to try using ISR(PCINT1_vect) for PC-interrupts on C port, to monitor PC4 and PC5.

:slight_smile:

There is also INT0_vect and INT1_vect, which refer to the single-pin hardware interrupts on Arduino Uno/Nano pins 2 and 3, otherwise known as PD2 and PD3.

:slight_smile:

http://ee-classes.usc.edu/ee459/library/documents/avr_intr_vectors/

Something like this then? Copied from somewhere and modified a bit, hopefully not too far off.

cli();
DDRC |=  (1 << PC4) | (1 << PC5);
PCMSK0 |= (1 << PCINT1);	//Pin Change Mask Register
PCICR |= (1 << PCIE0);	//Pin Change Interrupt Control Register
sei();

Bit twiddling has its own warped charm.

So it would be a good idea to have an ISR for that vector.

The presented program only has vectors for the other two groups.

ISR(PCINT0_vect)
{
  value= 1;
}

ISR(PCINT1_vect)
{
  value= 2 ;
}

Whandall:
So it would be a good idea to have an ISR for that vector.

The presented program only has vectors for the other two groups.

ISR(PCINT0_vect)

{
  value= 1;
}

ISR(PCINT1_vect)
{
  value= 2 ;
}

I updated the above message many times as I did some research, and now believe that PCINT1_vect is the proper one.

You would then do something like:

volatile int prevValuesPortC=0;
volatile int currValuesPortC=0;
volatile int someTriggerForMainLoopToProcessUpdates=0;

ISR(PCINT1_vect) {
   prevValuesPortC=currValuesPortC;
   currValuesPortC=PORTC;
   someTriggerForMainLoopToProcessUpdates=1;
}

In your mainloop you have an if on whether the uncomfortably-long-named variable above is set. If so you may compare the inputs you are looking for, using (PC5<<1) as usual to create mask for logical anding and examining, etc etc.

:slight_smile:

[Edit: forgot volatile]

You are right, pin 27 and 28 are PCINT12 and PCINT13, in group 1.

I recommend the book "AVR Programming: Learning to Write Software for Hardware". I have it on amazon kindle, and was going to confer with it now, but can not get it up in the online reader at Amazon. I think it goes into all the details of these interrupts, though I have not read it in full detail yet.

:slight_smile:

[Edit: book is by Elliot Williams]