INT0 and PCINT0 simultaneously with attiny13

Hi, I'm successfully using WDT and PCINT0 vector interrupts on the attiny13 at the same time with the following code, but I have set it up so that the interrupt is also supposed to happen while pressing a button on pin 1 (INT0 vector) although nothing happens.. Any idea why? Is it impossible to set PCINT0 and INT0 vector interrupts at the same time? thanks!!

/**************************************************************************************************************************************************************/
////LIBRARIES
/**************************************************************************************************************************************************************/

#include <avr/sleep.h>
#include <avr/interrupt.h>


/**************************************************************************************************************************************************************/
////PINS
/**************************************************************************************************************************************************************/

#define switchPin2  2
#define switchPin1  1
#define ledPin  0


/**************************************************************************************************************************************************************/
////VARIABLES
/**************************************************************************************************************************************************************/

//WDT variables
volatile int watchDog_counter;
int wd_target = 2; //target for wd counter


//PC interrupt variables
volatile int buttonFlag;
unsigned long last_interrupt_time;
int voltage;



/**************************************************************************************************************************************************************/
////OBJECTS
/**************************************************************************************************************************************************************/

/**************************************************************************************************************************************************************/
////SETUP
/**************************************************************************************************************************************************************/

void setup() {

  // watchDog_counter = 0;


  //pins setup
  DDRB &= ~(1 << switchPin1);
  PORTB |= (1 << switchPin1);
  DDRB &= ~(1 << switchPin2);
  PORTB |= (1 << switchPin2);
  DDRB |= (1 << ledPin);


  //Pin Change interrupt setup
  //Enable interrupts on pin 2 (PCINT2)
  GIMSK |= (1 << PCIE); //activate interrupts for PCINT0 vector
  GIMSK |= (1 << INT0);  //activate interrupts for INT0 vector
  PCMSK |= _BV(PCINT2); //turn pin 2 on to trigger PCINT0
  MCUCR |= (3 << ISC00); //set INT0 as low trigger
  sei();


  //EXT INTERRUPT STUFF
  //IMSK |= (1 << PCIE);
  //set low lvl trigger (keeps triggering while button not released)
  //MCUCR &= ~(1 << ISC01);
  //TRYING TO PUT THIS INSTEAD!! (FOR FALLING EDGE):  MCUCR |= (1 << ISC01);
  //MCUCR |= (1 << ISC00);

  //FALLING EDGE ON INT0 VECTOR (CAN SET HOW TRIGGERED COMPARED TO PCINT0)


  //avr/sleep enable
  sleep_enable();
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
}



/**************************************************************************************************************************************************************/
////LOOP
/**************************************************************************************************************************************************************/


void loop() {
  //Watchdog timer setup  //Putting this in setup causes a problem when servo writing
  //This order of commands is important and cannot be combined
  MCUSR &= ~(1 << WDRF); //Clear the watch dog reset
  WDTCR |= (1 << WDCE) | (1 << WDE); //Set WD_change enable, set WD enable
  WDTCR = 0B100001; //Set prescaler to 8 sec (see p.46 of datasheet to change prescaler), and OVERWRITE WDTCR value ( dont just use |= )
  WDTCR |= _BV(WDTIE); //Set the interrupt enable, this will keep unit from resetting after each int

  ADCSRA &= ~_BV(ADEN);      //Turn ADC off, saves ~230uA
  //ATmega328: ADCSRA &= ~(1 << 7);
  sleep_cpu();
  ADCSRA |= _BV(ADEN);        //will ADC need to be turned on after sleep?

  PORTB |= (1 << ledPin);
  delay(100);
  PORTB ^= (1 << ledPin);
  delay(100);


  if (!(watchDog_counter % wd_target)) {

  }


  if (buttonFlag) {

    buttonFlag = 0;
  }


}


/**************************************************************************************************************************************************************/
////FUNCTIONS
/**************************************************************************************************************************************************************/




ISR(PCINT0_vect) {
  if (!(PINB & (1 << PB2))) buttonFlag = 1; //tell the arduino a button was pressed, not released
}

ISR(INT0_vect) {
  buttonFlag = 1;
}


ISR(WDT_vect) {
  watchDog_counter++;
}

I don't know what your problem is, but I do have to wonder why buttonFlag needs to be a multi-byte type, when it will only ever hold 0 or 1.

PaulS:
I don't know what your problem is, but I do have to wonder why buttonFlag needs to be a multi-byte type, when it will only ever hold 0 or 1.

youre right, I switched it for a volatile Boolean.

My problem is that I wanted 2 buttons to trigger different effects, so I was planning on using the 2 attiny13 external interrupt vectors: PCINT0 and INT0. This way, when pressing button 1, the 1st vector should trigger, or when pressing button 2, the other vector should trigger instead. This would help me have a more complete user interface with a sleeping uC. However, the code I shared only works with PCINT0: that means only 1 of my two interrupt button pins actually trigger an interrupt. The other one, hooked up to INT0 (pin 1), isn't able to wake up the attiny when pushed.

So, I wanted to understand if something is wrong with my code! Thanks again

so I was planning on using the 2 attiny13 external interrupt vectors: PCINT0 and INT0.

Are you sure that PCINT0 is an external interrupt? Looks suspiciously like PCINT0 is a pin change interrupt. I would expect the two external interrupts, if there ARE two, to be INT0 and INT1.

PaulS:
Are you sure that PCINT0 is an external interrupt? Looks suspiciously like PCINT0 is a pin change interrupt. I would expect the two external interrupts, if there ARE two, to be INT0 and INT1.

You are right its a pin change interrupt. I thought it counted as a type of "external interrupt" so i was using this name for both interrupts. So I am trying to activate both the ONLY external interrupt and the pin change interrupt of the attiny13 at the same time, but the pin change interrupt is the only one working so far.
I was wondering if both were incompatible with eachother, but I tried the same code I shared with all of the pin change interrupt lines masked (basically I was trying to use the external interrupt by itself) and it didn't work, which made me think the first step in my problem is actually to make the ext int work at all! Thanks

Can anyone help with this puzzle please?

Have you carefully studied the cautions in the ATtiny13 data sheet, on using the INT0 LOW level interrupt, especially concerning wake from sleep?

jremington:
Have you carefully studied the cautions in the ATtiny13 data sheet, on using the INT0 LOW level interrupt, especially concerning wake from sleep?

No, I used ctrl+F to find any cautions and to find every instance of INT0 in the document, but nothing seems to be causing issues

INT0 and PCINT0 simultaneously with attiny13

Why both? Just use pin change interrupts.

Right, I didn't realize pin 1 was linked to both vectors. And then I check which button is pressed in the loop, just like we discussed in my other post from today. Looks like my other issue was actually linked to this one. Thanks