0

I have a project which, to save on battery, is put to sleep until an interrupt pin is rising from LOW to HIGH.

This works well on Arduino Nano, however the translation doesn't on the ATTiny.

#include <avr/sleep.h>
void setup(){
    pinMode(2,INPUT);
    noInterrupts();
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    attachInterrupt(INT0,wakeUp,RISING);
    //Yadada
    Interrupts();
}
void wakeUp(){
   //Something Something
   sleep_mode();
}

Both on the Arduino Nano and the AtTiny, the interrupt Pin 0 is equivalent to Pin 2.

  • The Arduino is set to ISP
  • I have run the Bootloader (with internal clock as 8MHz if that makes a difference)
  • The program loads on the AtTiny45.

Yet, the interrupt pin does not interrupt.

Does the INT0 act differently on a ATTiny than on the Arduino, and if so, how can I wake up my AtTiny?

5
  • 2
    attachInterrupt(digitalPinToInterrupt(pin), ...
    – Juraj
    Oct 18, 2020 at 7:20
  • 2
    The INT0 value is 0 for Atmega328 and it's 6 for the Attiny45... It was working just by accident on the other Arduino. It's not even supposed to be used with attachInterrupt (it's used by attachInterrupt to setup registers correctly)
    – KIIV
    Oct 18, 2020 at 7:25
  • Aaaaah so that's why it's not recommended. I will give it a try and come back with corrections! Thank you both!
    – B7th
    Oct 18, 2020 at 9:09
  • @Juraj, For some reason my version of Arduino IDE does not recognize the digitalPinToInterrupt? Looks like a usual thing so will see how else I can do this. Currently diving in the GIMSK etc. :S
    – B7th
    Oct 19, 2020 at 7:15
  • 1
    it is possible that the Arduino core in this boards support package doesn't have the function
    – Juraj
    Oct 19, 2020 at 8:19

1 Answer 1

0

After going through a lot of documentation, it seemed best and more efficient to attach the interrupt without functions.

EIMSK  |=  (1<< INT0);//Attaches the interrupt
MCUCR  |=  (1<< SM1)  //Power-down mode
         | (1<<ISC01) //The rising edge of INT0
         | (1<<ISC00);// generates an interrupt request
1
  • I think it's great that you came back and answered your own question. But, this answer seems weirdly mismatched with the question "Does the INT0 act differently on a ATTiny than on the Arduino, and if so, how can I wake up my AtTiny?"
    – timemage
    Jan 13, 2021 at 14:43

Your Answer

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

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