Go Down

Topic: interrupt and sleep mode : how to make it work on attiny84 ? (Read 2 times) previous topic - next topic

bozoo0038

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 :
Code: [Select]
#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

Nick Gammon

Code: [Select]

  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.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

bozoo0038


Code: [Select]

  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 ?
]http://www.flickr.com/photos/nathanchantrell/6897568559/[url]
http://www.atmel.com/Images/doc8006.pdf[/url]

Nick Gammon

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.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

strykeroz

#4
Nov 28, 2012, 10:37 pm Last Edit: Nov 28, 2012, 10:43 pm by strykeroz Reason: 1
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
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Nick Gammon

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


Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

strykeroz


I make it physical pin 5, which is why I am asking which pin he actually is using.
Of course - the first param is the interrupt number not the pin number.  Apologies.
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

bozoo0038


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




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

Nick Gammon

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

http://www.gammon.com.au/interrupts

There is a pin change interrupt library, not sure if it supports that processor.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

bozoo0038

Quote
http://www.gammon.com.au/interrupts


there is a lot of very valuable information there !

Thank you Nick !

pratto

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

Go Up