interrupt and sleep mode : how to make it work on attiny84 ?

Hi,

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);
}

thanks for your help !
Fab

  attachInterrupt(0,wakeUpNow, LOW); // interrupt : INT0 (pin 0)

What pin on the chip is that? I can't find the list of Arduino -> hardware pin mappings for the 84.

it should be pin 0 ?
[url=ATtiny84 Pin Layout for the arduino-tiny core | arduino-tiny… | Flickr]ATtiny84 Pin Layout for the arduino-tiny core | arduino-tiny… | Flickr
http://www.atmel.com/Images/doc8006.pdf

The Atmega84 has 14 pins, numbered 1 to 14. There is no pin 0. See the datasheet you linked.

Pin 1 is VCC and pin 14 is Gnd.

I'm trying to establish which, of those 14 pins, you are connecting the thing that is interrupting it to.

Hi guys

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?

Cheers ! Geoff

I make it physical pin 5, which is why I am asking which pin he actually is using.

[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 ?

thanks all for your advices !
Fab

I'm not sure exactly about the Attiny84, but pin change interrupts are easy enough:

There is a pin change interrupt library, not sure if it supports that processor.

Gammon Forum : Electronics : Microprocessors : Interrupts

there is a lot of very valuable information there !

Thank you Nick !

i agree. and thanks for your paper on microprocessors: power saving techniques.