Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
RF24
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
RF24
Commits
4ef1f4b8
Commit
4ef1f4b8
authored
May 10, 2011
by
maniacbug
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed power_all/enable/disable, useless. Added a multiples of the wakeup.
parent
ee4568ed
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
8 deletions
+13
-8
examples/pingpair_sleepy/pingpair_sleepy.pde
examples/pingpair_sleepy/pingpair_sleepy.pde
+13
-8
No files found.
examples/pingpair_sleepy/pingpair_sleepy.pde
View file @
4ef1f4b8
...
...
@@ -70,6 +70,9 @@ typedef enum { wdt_16ms = 0, wdt_32ms, wdt_64ms, wdt_128ms, wdt_250ms, wdt_500ms
void
setup_watchdog
(
uint8_t
prescalar
);
void
do_sleep
(
void
);
const
short
sleep_cycles_per_transmission
=
4
;
volatile
short
sleep_cycles_remaining
=
sleep_cycles_per_transmission
;
//
// Normal operation
//
...
...
@@ -106,7 +109,7 @@ void setup(void)
// Only the ping out role sleeps. Wake up every 4s to send a ping
if
(
role
==
role_ping_out
)
setup_watchdog
(
wdt_
4
s
);
setup_watchdog
(
wdt_
1
s
);
//
// Setup and configure rf radio
...
...
@@ -192,13 +195,19 @@ void loop(void)
// Shut down the system
//
// Experiment with some delay here to see if it has an effect
delay
(
500
);
// Power down the radio. Note that the radio will get powered back up
// on the next write() call.
radio
.
powerDown
();
// Sleep the MCU. The watchdog timer will awaken in a short while, and
// continue execution here.
do_sleep
();
while
(
sleep_cycles_remaining
)
do_sleep
();
sleep_cycles_remaining
=
sleep_cycles_per_transmission
;
}
//
...
...
@@ -242,10 +251,9 @@ void loop(void)
// Sleep helpers
//
// 0=16ms, 1=32ms,2=64ms,3=12
8
ms,4=250ms,5=500ms
// 0=16ms, 1=32ms,2=64ms,3=12
5
ms,4=250ms,5=500ms
// 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec
void
setup_watchdog
(
uint8_t
prescalar
)
{
prescalar
=
min
(
9
,
prescalar
);
...
...
@@ -258,8 +266,8 @@ void setup_watchdog(uint8_t prescalar)
WDTCSR
=
_BV
(
WDCE
)
|
wdtcsr
|
_BV
(
WDIE
);
}
// Even though it does nothing, it's necessary to have a WDT ISR
ISR
(
WDT_vect
)
{
--
sleep_cycles_remaining
;
}
void
do_sleep
(
void
)
...
...
@@ -267,12 +275,9 @@ void do_sleep(void)
set_sleep_mode
(
SLEEP_MODE_PWR_DOWN
);
// sleep mode is set here
sleep_enable
();
power_all_disable
();
sleep_mode
();
// System sleeps here
sleep_disable
();
// System continues execution here when watchdog timed out
power_all_enable
();
}
// vim:ai:cin:sts=2 sw=2 ft=cpp
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment