I'm working on a project which will run on a attiny84. I'm testing it with an Arduino Uno.
I want to tell the chip to go to sleep mode (SLEEP_MODE_PWR_DOWN), then to wake up on an external interrupt (INT0).
It works like a charm on arduino uno... but not at all on attiny84. The chip just does not go to sleep and the interrupt is not caught.
do i need to add some libraries to make it work on attiny ?
do i use the right syntax for attachInterrupt ? (i tried attachInterrupt(INT0,wakeUpNow, LOW); : it just freeze the chip.)
Here is the code :
#include <avr/sleep.h>
void sleepNow()
{
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
attachInterrupt(0,wakeUpNow, LOW); // interrupt : INT0 (pin 0)
sleep_mode(); // go to sleep...
sleep_disable(); // wake up !
detachInterrupt(0);
}
Arduino IDE D0 references ATtiny84 physical leg 2 which is also XTAL1 if you're using a crystal, and PB0.
The datasheet states this uC family has "Internal and External Interrupt Sources: Pin Change Interrupt on 12 Pins" which is promising, but potentially you've connected to the wrong leg?
[quote author=Nick Gammon link=topic=134698.msg1013219#msg1013219 date=1354139195]
I make it physical pin 5, which is why I am asking which pin he actually is using.
[/quote]Of course - the first param is the interrupt number not the pin number. Apologies.
Damned ! i was confused with "PCINT0" so i wired the switch on physical pin 13. I did not tried pin 5.
Too bad, physical pin 5 is also one of the 4 pwm output of the at84 and i need all of them !
The datasheet states "external interrupt on 12 pin" (from pin 2 to pin 13 / pcint0 to pcint11), but i have no clue on how to make it work in an arduino sketch. Is there someting like attachInterrupt() for external interrupts ?