Skip to content

Commit

Permalink
Disable broken sleep mode
Browse files Browse the repository at this point in the history
- Sleep mode disabled by default
- added //#define ENABLE_SLEEP_MODE to RF24Network_config.h
- removed unneeded powerUp() and extra settings etc for enhanced sleep
mode until issues are resolved
  • Loading branch information
TMRh20 committed Apr 15, 2014
1 parent f88f3cb commit 9428e97
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 38 deletions.
59 changes: 22 additions & 37 deletions RF24Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@
#include "RF24.h"
#include "RF24Network.h"

#ifndef __arm__
#if defined (ENABLE_SLEEP_MODE)
#include <avr/sleep.h>
#include <avr/power.h>
volatile byte sleep_cycles_remaining;
#endif

uint16_t RF24NetworkHeader::next_id = 1;

uint64_t pipe_address( uint16_t node, uint8_t pipe );
bool is_valid_address( uint16_t node );

volatile byte sleep_cycles_remaining;

/******************************************************************/

RF24Network::RF24Network( RF24& _radio ): radio(_radio), next_frame(frame_queue)
Expand All @@ -45,13 +44,6 @@ void RF24Network::begin(uint8_t _channel, uint16_t _node_address )
radio.setDataRate(RF24_1MBPS);
radio.setCRCLength(RF24_CRC_16);

radio.maskIRQ(1,1,0); //TX,FAIL,RX
radio.enableAckPayload();
radio.enableDynamicPayloads();
radio.setPayloadSize(frame_size);
radio.setAutoAck(1);


// Setup our address helper cache
setup_address();

Expand All @@ -60,7 +52,7 @@ void RF24Network::begin(uint8_t _channel, uint16_t _node_address )
while (i--)
radio.openReadingPipe(i,pipe_address(_node_address,i));
radio.startListening();
radio.powerUp();

}

/******************************************************************/
Expand All @@ -85,25 +77,18 @@ void RF24Network::update(void)
IF_SERIAL_DEBUG(const uint16_t* i = reinterpret_cast<const uint16_t*>(frame_buffer + sizeof(RF24NetworkHeader));printf_P(PSTR("%lu: NET message %04x\n\r"),millis(),*i));

// Throw it away if it's not a valid address
if ( !is_valid_address(header.to_node) )
continue;


//TMRh20
// Throw it away if its a sleep packet
if (header.type == 'S'){
continue; //Discard the payload

if ( !is_valid_address(header.to_node) ){
continue;
}

// Is this for us?
if ( header.to_node == node_address )
if ( header.to_node == node_address ){
// Add it to the buffer of frames for us
enqueue();
else
// Relay it
write(header.to_node);

enqueue();
}else{
// Relay it
write(header.to_node);
}
// NOT NEEDED anymore. Now all reading pipes are open to start.
#if 0
// If this was for us, from one of our children, but on our listening
Expand Down Expand Up @@ -277,7 +262,6 @@ bool RF24Network::write(uint16_t to_node)

ok = write_to_pipe( send_node, send_pipe );


// NOT NEEDED anymore. Now all reading pipes are open to start.
#if 0
// If we are talking on our talking pipe, it's possible that no one is listening.
Expand Down Expand Up @@ -463,19 +447,19 @@ uint64_t pipe_address( uint16_t node, uint8_t pipe )
/************************ Sleep Mode ******************************************/


#if defined ENABLE_SLEEP_MODE


#if !defined( __AVR_ATtiny85__ ) || defined( __AVR_ATtiny84__) || defined(__arm__)
#if !defined( __AVR_ATtiny85__ ) && !defined( __AVR_ATtiny84__) && !defined(__arm__)

RF24NetworkHeader sleepHeader(/*to node*/ 00, /*type*/ 'S' /*Sleep*/);

bool awoke = 0;
//bool awoke = 0;

void wakeUp(){
//detachInterrupt(0);
sleep_disable();
sleep_cycles_remaining = 0;
awoke = 1;
//awoke = 1;
}

ISR(WDT_vect){
Expand All @@ -491,19 +475,19 @@ void RF24Network::sleepNode( unsigned int cycles, int interruptPin ){
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
sleep_enable();
if(interruptPin != 255){
attachInterrupt(interruptPin,wakeUp,LOW);
attachInterrupt(interruptPin,wakeUp, LOW);
}
WDTCSR |= _BV(WDIE);
while(sleep_cycles_remaining){
uint8_t junk = 23;
write(sleepHeader,&junk,1);
//uint8_t junk = 23;
//write(&junk,1);
sleep_mode(); // System sleeps here
} // The WDT_vect interrupt wakes the MCU from here
sleep_disable(); // System continues execution here when watchdog timed out
if(awoke){ update(); awoke = 0; }
//if(awoke){ update(); awoke = 0; }
detachInterrupt(interruptPin);
WDTCSR &= ~_BV(WDIE);
radio.startListening();
//radio.startListening();

}

Expand All @@ -518,4 +502,5 @@ void RF24Network::setup_watchdog(uint8_t prescalar){
}


#endif
#endif // not ATTiny
#endif // Enable sleep mode
2 changes: 1 addition & 1 deletion RF24Network.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class RF24Network
* @section Features Features
*
* The layer provides:
* @li <b>New</b> (2014): Power efficient sleep mode. Nodes can now sleep for extended periods of time with minimal power usage:
* @li <b>New</b> (2014): NOT WORKING Power efficient sleep mode. Nodes can now sleep for extended periods of time with minimal power usage:
* StandBy-I mode uses 22uA compared to 0.9uA in full power down mode. The Arduino is allowed to sleep,
* and is awoken via interrupt when payloads are received, or via a user defined time period. See the docs.
* @li <b>New</b> (2014): Extended timeouts. The maximum timeout period is approximately 60ms per payload with max delay between retries, and
Expand Down
5 changes: 5 additions & 0 deletions RF24Network_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include <stddef.h>

//#define ENABLE_SLEEP_MODE

// Stuff that is normally provided by Arduino
#ifndef ARDUINO
#include <stdint.h>
Expand All @@ -32,6 +34,9 @@ extern HardwareSPI SPI;
#define IF_SERIAL_DEBUG(x) ({x;})
#else
#define IF_SERIAL_DEBUG(x)
#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny85__)
#define printf_P(...)
#endif
#endif

// Avoid spurious warnings
Expand Down

0 comments on commit 9428e97

Please sign in to comment.