new BROADCAST_ADDR=255, avoid calling receiveBegin() in RX

This commit is contained in:
Felix Rusu 2014-02-01 21:13:40 -05:00
parent c875e1b622
commit cec7f05940
2 changed files with 17 additions and 10 deletions

View File

@ -44,6 +44,8 @@ bool RFM69::initialize(byte freqBand, byte nodeID, byte networkID)
///* 0x11 */ { REG_PALEVEL, RF_PALEVEL_PA0_ON | RF_PALEVEL_PA1_OFF | RF_PALEVEL_PA2_OFF | RF_PALEVEL_OUTPUTPOWER_11111},
///* 0x13 */ { REG_OCP, RF_OCP_ON | RF_OCP_TRIM_95 }, //over current protection (default is 95mA)
///* 0x18*/ { REG_LNA, RF_LNA_ZIN_200 | RF_LNA_CURRENTGAIN }, //as suggested by mav here: http://lowpowerlab.com/forum/index.php/topic,296.msg1571.html
// RXBW defaults are { REG_RXBW, RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_24 | RF_RXBW_EXP_5} (RxBw: 10.4khz)
/* 0x19 */ { REG_RXBW, RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_16 | RF_RXBW_EXP_2 }, //(BitRate < 2 * RxBw)
/* 0x25 */ { REG_DIOMAPPING1, RF_DIOMAPPING1_DIO0_01 }, //DIO0 is the only IRQ we're using
@ -189,7 +191,7 @@ bool RFM69::sendWithRetry(byte toAddress, const void* buffer, byte bufferSize, b
/// Should be polled immediately after sending a packet with ACK request
bool RFM69::ACKReceived(byte fromNodeID) {
if (receiveDone())
return (SENDERID == fromNodeID || fromNodeID == 0) && ACK_RECEIVED;
return (SENDERID == fromNodeID || fromNodeID == RF69_BROADCAST_ADDR) && ACK_RECEIVED;
return false;
}
@ -243,7 +245,7 @@ void RFM69::interruptHandler() {
PAYLOADLEN = SPI.transfer(0);
PAYLOADLEN = PAYLOADLEN > 66 ? 66 : PAYLOADLEN; //precaution
TARGETID = SPI.transfer(0);
if(!(_promiscuousMode || TARGETID==_address || TARGETID==0)) //match this node's address, or broadcast addr 0x0 or anything in promiscuous mode
if(!(_promiscuousMode || TARGETID==_address || TARGETID==RF69_BROADCAST_ADDR)) //match this node's address, or broadcast address or anything in promiscuous mode
{
PAYLOADLEN = 0;
unselect();
@ -287,12 +289,17 @@ void RFM69::receiveBegin() {
bool RFM69::receiveDone() {
// ATOMIC_BLOCK(ATOMIC_FORCEON)
// {
noInterrupts(); //re-enabled in unselect() via setMode()
noInterrupts(); //re-enabled in unselect() via setMode() or via receiveBegin()
if (_mode == RF69_MODE_RX && PAYLOADLEN>0)
{
setMode(RF69_MODE_STANDBY);
setMode(RF69_MODE_STANDBY); //enables interrupts
return true;
}
else if (_mode == RF69_MODE_RX) //already in RX no payload yet
{
interrupts(); //explicitly re-enable interrupts
return false;
}
receiveBegin();
return false;
//}
@ -415,4 +422,4 @@ void RFM69::rcCalibration()
{
writeReg(REG_OSC1, RF_OSC1_RCCAL_START);
while ((readReg(REG_OSC1) & RF_OSC1_RCCAL_DONE) == 0x00);
}
}

10
RFM69.h
View File

@ -12,8 +12,7 @@
#define MAX_DATA_LEN 61 // to take advantage of the built in AES/CRC we want to limit the frame size to the internal FIFO size (66 bytes - 3 bytes overhead)
#define SPI_CS SS // SS is the SPI slave select pin, for instance D10 on atmega328
#define RF69_IRQ_PIN 2 // INT0 on AVRs should be connected to DIO0
// ex on Atmega328 it's D2
#define RF69_IRQ_PIN 2 // INT0 on AVRs should be connected to DIO0 (ex on Atmega328 it's D2)
#define CSMA_LIMIT -90 // upper RX signal sensitivity threshold in dBm for carrier sense access
#define RF69_MODE_SLEEP 0 // XTAL OFF
#define RF69_MODE_STANDBY 1 // XTAL ON
@ -27,8 +26,9 @@
#define RF69_868MHZ 86
#define RF69_915MHZ 91
#define null 0
#define COURSE_TEMP_COEF -90 // puts the temperature reading in the ballpark, user can fine tune the returned value
#define null 0
#define COURSE_TEMP_COEF -90 // puts the temperature reading in the ballpark, user can fine tune the returned value
#define RF69_BROADCAST_ADDR 255
class RFM69 {
public:
@ -74,7 +74,7 @@ class RFM69 {
byte readReg(byte addr);
void writeReg(byte addr, byte val);
void readAllRegs();
protected:
static void isr0();
void virtual interruptHandler();