[ATmega128RFA1] PinChange Interrupt not working [SOLVED]

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, so I've been trying to make this interrupt work on a ATmega128RFA1 without success.

I'm using PORT B4 and B5, which are PCINT4 and PCINT5 respectively.

I have enabled the PC interrupt in its config register, enabled the PCINT0 Mask and enabled the global interrupt, but still, the PC Interrupt Flag never changes and, obviously, the interrupt is never executed.

My code:

/* Includes */
#include 
#include 
#include 
#include "../../serial.c"

ISR(PCINT0_vect)
{
    printf("Interrupt Working\n");
}

int main(void)
{       
    serial_init();   // Initialize serial PORT E0&E1

    DDRB   &=~(1<<PORTB4 & 1<<PORTB5);
    PCICR  |= (1<<PCIE0);
    PCMSK0 |= (1<<PCINT0);          // On
    // PCMSK0 &=~(1<<PCINT0);       // Off
    sei();
    while(1)
    {
        // PCIFR = 0x02; // As a test, PCIFR never changes
        printf("PCIFR:%02X\r",PCIFR);
    }
}

So, that's my code.
Am I missing something?

Last Edited: Mon. Feb 10, 2014 - 01:13 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I'm using PORT B4 and B5, which are PCINT4 and PCINT5 respectively.

But you are only looking at PCINT0 (which I assume is PB0).
Quote:

PCMSK0 |= (1<<PCINT0); // On

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
Quote:

I'm using PORT B4 and B5, which are PCINT4 and PCINT5 respectively.

But you are only looking at PCINT0 (which I assume is PB0).
Quote:

PCMSK0 |= (1<<PCINT0); // On

Yes, because a toggle in any pin PCINT7:0, triggers the interrupt PCINt0.
(A toggle in pins PCINT15:8 and PCINT23:16, triggers interrupt PCINT1 and PCINT2 respectively)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You missed Lee's point. It's the line where you enable the interrupt sources:

    PCMSK0 |= (1<<PCINT0);          // On

PCMSK0 is 8 bits that control the 8 pins of the PCINT0 interrupt. You want to 4 and 5 as the interrupting sources.

And yes this IS hugely confusing. Atmel stupidly used "PCINT0" for two things. Sometimes it means a whole port and sometimes it means one bit of a port. In the interrupt enable it's for the whole port but in the actual mask register it's just one of 8 pins.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
You missed Lee's point. It's the line where you enable the interrupt sources:

    PCMSK0 |= (1<<PCINT0);          // On

PCMSK0 is 8 bits that control the 8 pins of the PCINT0 interrupt. You want to 4 and 5 as the interrupting sources.

And yes this IS hugely confusing. Atmel stupidly used "PCINT0" for two things. Sometimes it means a whole port and sometimes it means one bit of a port. In the interrupt enable it's for the whole port but in the actual mask register it's just one of 8 pins.


Wow, you're totally right.
I thought that mask meant PCINT0 as the whole interrupt vector ... damn it.

Changed that line and now everything works.

I feel so stupid right now.
I knew it was a silly thing.
I wonder how much more time it would have taken me to realise this.

Thank you both!!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

And yes this IS hugely confusing. Atmel stupidly used "PCINT0" for two things.

A newer datasheet such as the omnibus Mega88PA family I have open now calls one of them "PCIn" instead. But then a confusion factor still exists when e.g. porting code across models, or when the toolchain "catches up" to the new nomenclature.

Lessee, CVAVR 3.07 has

...
// Interrupt vectors definitions

#define EXT_INT0 2
#define EXT_INT1 3
#define PC_INT0 4
#define PC_INT1 5
#define PC_INT2 6
...
/* PCICR - Pin Change Interrupt Control Register */
#define    PCIE0           0       // Pin Change Interrupt Enable 0
#define    PCIE1           1       // Pin Change Interrupt Enable 1
#define    PCIE2           2       // Pin Change Interrupt Enable 2

Quote:

Yes, because a toggle in any pin PCINT7:0, triggers the interrupt PCINt0.

Not exactly. Read the datasheet again. Mine (for Mega88PA) has

Quote:
The pin change interrupt PCI0 will trigger if any enabled PCINT[7:0] pin toggles.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.