Pages: [1]   Go Down
Author Topic: interrupt and sleep mode : how to make it work on attiny84 ?  (Read 2148 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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
Logged

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 510
Posts: 19306
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  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.
Logged

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

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  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]
Logged

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 510
Posts: 19306
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: November 28, 2012, 04:43:35 pm by strykeroz » Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 510
Posts: 19306
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Logged

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

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 510
Posts: 19306
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote

there is a lot of very valuable information there !

Thank you Nick !
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: