heimi
heimi

Reputation: 539

Why is PCINTX-Interrupt on Attiny84 not working

My code works with signals on INT0 without problems. Output pins are enabled on PA2and PA3. Now I want to use PA7 for PCINT with no success. I followed the code of question 'Best way to handle multiple PCINT in AVR'.

volatile uint8_t portahistory = 0xFF;     // default is high because the pull-up
DDRA |= (1<<PA2); // LED
PORTA |= (1<<PA2); 
DDRA |= (1<<PA3); // LED
PORTA |= (1<<PA3);

Init PCINT:

void pcint7_init(void)
{
   DDRA &= ~(1<<PA7); // PA7 input
   PORTA |= (1<<PA7); // HI
   
   GIMSK |= (1<<PCIE0);    // General Interrupt Mask Register enable for pin 0:7
   PCMSK0 |= (1<<PCINT7);  // Pin Change Mask Register  for PA7
}

ISR for PA7:

ISR(PCINT7_vect) 
{
  uint8_t changedbits;
   
   changedbits = PINA ^ portahistory;
   portahistory = PINA;
   
   if(changedbits & (1 << PA7))
   {
      PORTA ^= (1<<PA4); // PA4 output for LED
   }
}

The interrupt is done with a switch from PA7 to ground.

Using the switch has no effect on the LED on PA4 but affects the LED outputs on PA2,3: Short flicker on both close and release of the switch.

Any idea what is coded wrong?

Upvotes: 0

Views: 140

Answers (1)

bigjosh
bigjosh

Reputation: 1393

Maybe you are seeing many, many fast consecutive interrupts on INT7 due to bounce on the switch? Just for testing, try adding a 50ms delay followed by a manual clear of the INT7 change flag at the end of the ISR and see if that changes anything.

Also generally best to post a full program rather than snippets just in case problem is elsewhere, and also this lets others potentially try the program out to verify. Also best if this program is the simplest possible program that shows the problem. Very often stripping away stuff that seems unrelated to the problem will fix it and then you get an "ah ha!" moment. :)

Upvotes: 0

Related Questions