ATtiny84 Prevent external interrupts
i'm building sht21 based sensor runs off cr2032 battery, need sleep of time.
with in mind, found way of sleeping 'tiny , waking every x seconds using built in watchdog timer. perfect.... or thought.
i'm using srf radio uses serial. because didn't think through design of pcb enough, i've managed tie receive pin srf external interrupt pin on 'tiny. result, when there traffic on srf, sets pin low , wakes mcu. haven't defined external interrupts, , functionality unwanted.
is there way disabled external interrupts completely, while still allowing watchdog interrupt work?
normally srf disabled , won't receiving data, wanted know whether possible disable functionality anyway
this current testing code:
output:
then when simulate incoming serial:
with in mind, found way of sleeping 'tiny , waking every x seconds using built in watchdog timer. perfect.... or thought.
i'm using srf radio uses serial. because didn't think through design of pcb enough, i've managed tie receive pin srf external interrupt pin on 'tiny. result, when there traffic on srf, sets pin low , wakes mcu. haven't defined external interrupts, , functionality unwanted.
is there way disabled external interrupts completely, while still allowing watchdog interrupt work?
normally srf disabled , won't receiving data, wanted know whether possible disable functionality anyway
this current testing code:
code: [select]
// software serial
#include <softwareserial.h>
#define rxpin 3
#define txpin 2
softwareserial myserial (rxpin, txpin);
// low power
#include <avr/sleep.h> //needed sleep_mode
#include <avr/wdt.h> //needed enable/disable watch dog timer
// sleep variables
volatile boolean f_wdt = 1;
volatile int watch_dog_counter = 0;
int sleep_loops = 0;
int awake_loops = 0;
// missing attiny44, 84
#ifndef wdtcr
#define wdtcr _sfr_io8(0x21)
#endif
isr(wdt_vect) {
watch_dog_counter++;
f_wdt = 1;
}
void setup() {
// setup serial
myserial.begin(9600);
myserial.println("starting");
// setup sleep watchdog
setup_watchdog(6);
}
void loop() {
if (f_wdt == 1) {
f_wdt = 0;
sleep_loops++;
}
awake_loops++;
myserial.print("watchdog: ");
myserial.print(watch_dog_counter);
myserial.print(" sleep: ");
myserial.print(sleep_loops);
myserial.print(" wake: ");
myserial.println(awake_loops);
steve_sleep();
}
// 0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms
// 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec
void setup_watchdog(int timerprescaler) {
if (timerprescaler > 9 ) {
timerprescaler = 9; //correct incoming amount if need be
}
byte bb = timerprescaler & 7;
if (timerprescaler > 7) {
bb |= (1<<5); //set special 5th bit if necessary
}
//this order of commands important , cannot combined
mcusr &= ~(1<<wdrf); //clear watch dog reset
wdtcr |= (1<<wdce) | (1<<wde); //set wd_change enable, set wd enable
wdtcr = bb; //set new watchdog timeout value
wdtcr |= _bv(wdie); //set interrupt enable, keep unit resetting after each int
}
void steve_sleep() {
set_sleep_mode(sleep_mode_pwr_down);
cli();
sleep_enable();
sei();
sleep_cpu();
sleep_disable();
}
output:
code: [select]
starting
watchdog: 0 sleep: 1 wake: 1
watchdog: 1 sleep: 2 wake: 2
watchdog: 2 sleep: 3 wake: 3
watchdog: 3 sleep: 4 wake: 4
watchdog: 4 sleep: 5 wake: 5
watchdog: 5 sleep: 6 wake: 6
watchdog: 6 sleep: 7 wake: 7
watchdog: 7 sleep: 8 wake: 8
then when simulate incoming serial:
code: [select]
watchdog: 42 sleep: 43 wake: 46
watchdog: 42 sleep: 43 wake: 47
watchdog: 42 sleep: 43 wake: 48
watchdog: 43 sleep: 44 wake: 49
watchdog: 43 sleep: 44 wake: 50
watchdog: 43 sleep: 44 wake: 51
watchdog: 43 sleep: 44 wake: 52
watchdog: 43 sleep: 44 wake: 53
watchdog: 43 sleep: 44 wake: 54
watchdog: 43 sleep: 44 wake: 55
watchdog: 44 sleep: 45 wake: 56
watchdog: 45 sleep: 46 wake: 57
watchdog: 46 sleep: 47 wake: 58
watchdog: 47 sleep: 48 wake: 59
watchdog: 48 sleep: 49 wake: 60
Arduino Forum > Using Arduino > Programming Questions > ATtiny84 Prevent external interrupts
arduino
Comments
Post a Comment