For some reason my pin change interrupts are not triggered on my Atmega324PB. To test, I'm using an eval board and connecting an output pin to a pin configured to trigger a pin change interrupt. Is there something I'm missing?

volatile uint16_t motorCount = 0;

// Configuring pin change interrupt on A7.
// A7 pin change interrupts are handled in
// "pin change interrupt request 3"
PCICR |= (1 << PCIE3);
PCMSK3 |= (1<<PCINT31);

// Interrupt routine

To test, I've wired it to an output pin, A2. I have verified with a multimeter that pin A2 and A7 are changing from low (0V), to high (~3.6V). This change doesn't trigger the interrupt. It doesn't trigger when changing back to low either.

// main.c
uint8_t test = 0;
DDRA |= (1 << DDRA2);   // A2 as output

while (1) {     
    if(kbhit())  // Wait's for serial input character (configured separately)
        if(('\n' == tmp) || ('\r'== tmp))
            test ^= 1; // Toggle first bit.
            test &= 1; // Mask to only first bit.
            if (test == 1) {
                // output high on A2
                PORTA |= (1 << PORTA2);
            else {
                // output low on A2
                PORTA &= ~(1 << PORTA2);

1 Answer 1


It turns out I misinterpreted the data sheet!

In this line in section 15.1...

"The Pin Change Interrupt Request 3 (PCI3) will trigger if any enabled PCINT[31:24] pin toggles."

I thought "PCINT[31:24]" was referring to pins 31 to 24. I missed the fact that there were pins defined as PCINT31, PCINT30, PCINT29, ..., PCINT24. For the atmega324pb, PCINT31 is the same pin as D7, as pointed out in the comments.

  • 1
    \$\begingroup\$ "It turns out there is an error in the Atmega324pb datasheet!" - where is the error? ww1.microchip.com/downloads/en/DeviceDoc/40001908A.pdf Table 16-12. port pin PD7 alternate function PCINT31 \$\endgroup\$ Commented Mar 13, 2018 at 4:46
  • \$\begingroup\$ I just realized the mistake was in my interpretation. I interpreted the "PCINT[31:24]" as pins 31 to 24. Thanks! I'll update the answer to point out my misinterpretation, in case someone else is as hasty as myself and misses that glaring detail. \$\endgroup\$
    – Scampbell
    Commented Mar 13, 2018 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.