bug fixes & performance improvements

This commit is contained in:
Felix Rusu 2013-07-13 23:49:26 -04:00
parent 3370ac6265
commit d23a4c95b9
3 changed files with 89 additions and 61 deletions

108
RFM69.cpp
View File

@ -1,28 +1,39 @@
// **********************************************************************************
// Driver definition for HopeRF RFM69W/RFM69HW, Semtech SX1231/1231H // Driver definition for HopeRF RFM69W/RFM69HW, Semtech SX1231/1231H
// **********************************************************************************
// Creative Commons Attrib Share-Alike License // Creative Commons Attrib Share-Alike License
// If you want to use/extend this library please abide with the license terms: http://creativecommons.org/licenses/by-sa/3.0/ // You are free to use/extend this library but please abide with the CCSA license:
// http://creativecommons.org/licenses/by-sa/3.0/
// 2013-06-14 (C) felix@lowpowerlab.com // 2013-06-14 (C) felix@lowpowerlab.com
// **********************************************************************************
#include <RFM69.h> #include <RFM69.h>
#include <RFM69registers.h> #include <RFM69registers.h>
#include <SPI.h> #include <SPI.h>
volatile byte RFM69::DATA[MAX_DATA_LEN];
volatile byte RFM69::_mode; // current transceiver state
volatile byte RFM69::DATALEN;
volatile byte RFM69::SENDERID;
volatile byte RFM69::TARGETID; //should match _address
volatile byte RFM69::PAYLOADLEN;
volatile byte RFM69::ACK_REQUESTED;
volatile byte RFM69::ACK_RECEIVED; /// Should be polled immediately after sending a packet with ACK request
RFM69* RFM69::selfPointer; RFM69* RFM69::selfPointer;
bool RFM69::initialize(byte freqBand, byte nodeID, byte networkID) bool RFM69::initialize(byte freqBand, byte nodeID, byte networkID)
{ {
const byte CONFIG[][2] = const byte CONFIG[][2] =
{ {
/* 0x01 */ { REG_OPMODE, RF_OPMODE_SEQUENCER_ON | RF_OPMODE_LISTEN_OFF | RF_OPMODE_STANDBY}, /* 0x01 */ { REG_OPMODE, RF_OPMODE_SEQUENCER_ON | RF_OPMODE_LISTEN_OFF | RF_OPMODE_STANDBY },
/* 0x02 */ { REG_DATAMODUL, RF_DATAMODUL_DATAMODE_PACKET | RF_DATAMODUL_MODULATIONTYPE_FSK | RF_DATAMODUL_MODULATIONSHAPING_00}, //gaussian, bt=1.0 /* 0x02 */ { REG_DATAMODUL, RF_DATAMODUL_DATAMODE_PACKET | RF_DATAMODUL_MODULATIONTYPE_FSK | RF_DATAMODUL_MODULATIONSHAPING_00 }, //gaussian, bt=1.0
/* 0x03 */ { REG_BITRATEMSB, RF_BITRATEMSB_55555}, //default is 4.8 KBPS /* 0x03 */ { REG_BITRATEMSB, RF_BITRATEMSB_55555}, //default:4.8 KBPS
/* 0x04 */ { REG_BITRATELSB, RF_BITRATELSB_55555}, /* 0x04 */ { REG_BITRATELSB, RF_BITRATELSB_55555},
/* 0x05 */ { REG_FDEVMSB, RF_FDEVMSB_50000}, //default is 5khz /* 0x05 */ { REG_FDEVMSB, RF_FDEVMSB_50000}, //default:5khz, (FDEV + BitRate/2 <= 500Khz)
/* 0x06 */ { REG_FDEVLSB, RF_FDEVLSB_50000}, /* 0x06 */ { REG_FDEVLSB, RF_FDEVLSB_50000},
/* 0x07 */ { REG_FRFMSB, (freqBand==RF69_315MHZ ? RF_FRFMSB_315 : (freqBand==RF69_433MHZ ? RF_FRFMSB_433 : (freqBand==RF69_868MHZ ? RF_FRFMSB_868 : RF_FRFMSB_915)))}, /* 0x07 */ { REG_FRFMSB, (freqBand==RF69_315MHZ ? RF_FRFMSB_315 : (freqBand==RF69_433MHZ ? RF_FRFMSB_433 : (freqBand==RF69_868MHZ ? RF_FRFMSB_868 : RF_FRFMSB_915))) },
/* 0x08 */ { REG_FRFMID, (freqBand==RF69_315MHZ ? RF_FRFMID_315 : (freqBand==RF69_433MHZ ? RF_FRFMID_433 : (freqBand==RF69_868MHZ ? RF_FRFMID_868 : RF_FRFMID_915)))}, /* 0x08 */ { REG_FRFMID, (freqBand==RF69_315MHZ ? RF_FRFMID_315 : (freqBand==RF69_433MHZ ? RF_FRFMID_433 : (freqBand==RF69_868MHZ ? RF_FRFMID_868 : RF_FRFMID_915))) },
/* 0x09 */ { REG_FRFLSB, (freqBand==RF69_315MHZ ? RF_FRFLSB_315 : (freqBand==RF69_433MHZ ? RF_FRFLSB_433 : (freqBand==RF69_868MHZ ? RF_FRFLSB_868 : RF_FRFLSB_915)))}, /* 0x09 */ { REG_FRFLSB, (freqBand==RF69_315MHZ ? RF_FRFLSB_315 : (freqBand==RF69_433MHZ ? RF_FRFLSB_433 : (freqBand==RF69_868MHZ ? RF_FRFLSB_868 : RF_FRFLSB_915))) },
// looks like PA1 and PA2 are not implemented on RFM69W, hence the max output power is 13dBm // looks like PA1 and PA2 are not implemented on RFM69W, hence the max output power is 13dBm
// +17dBm and +20dBm are possible on RFM69HW // +17dBm and +20dBm are possible on RFM69HW
@ -30,23 +41,26 @@ bool RFM69::initialize(byte freqBand, byte nodeID, byte networkID)
// +17dBm formula: Pout=-14+OutputPower (with PA1 and PA2)** // +17dBm formula: Pout=-14+OutputPower (with PA1 and PA2)**
// +20dBm formula: Pout=-11+OutputPower (with PA1 and PA2)** and high power PA settings (section 3.3.7 in datasheet) // +20dBm formula: Pout=-11+OutputPower (with PA1 and PA2)** and high power PA settings (section 3.3.7 in datasheet)
///* 0x11 */ { REG_PALEVEL, RF_PALEVEL_PA0_ON | RF_PALEVEL_PA1_OFF | RF_PALEVEL_PA2_OFF | RF_PALEVEL_OUTPUTPOWER_11111}, ///* 0x11 */ { REG_PALEVEL, RF_PALEVEL_PA0_ON | RF_PALEVEL_PA1_OFF | RF_PALEVEL_PA2_OFF | RF_PALEVEL_OUTPUTPOWER_11111},
/* 0x19 */ { REG_RXBW, RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_16 | RF_RXBW_EXP_2}, ///* 0x13 */ { REG_OCP, RF_OCP_ON | RF_OCP_TRIM_95 }, //over current protection (default is 95mA)
/* 0x25 */ { REG_DIOMAPPING1, RF_DIOMAPPING1_DIO0_01}, //DIO0 is the only IRQ we're using
/* 0x29 */ { REG_RSSITHRESH, 220}, // must be set to dBm = (-Sensitivity / 2) - default is 0xE4=228 so -114dBm // RXBW defaults are {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
/* 0x29 */ { REG_RSSITHRESH, 220 }, //must be set to dBm = (-Sensitivity / 2) - default is 0xE4=228 so -114dBm
///* 0x2d */ { REG_PREAMBLELSB, RF_PREAMBLESIZE_LSB_VALUE } // default 3 preamble bytes 0xAAAAAA ///* 0x2d */ { REG_PREAMBLELSB, RF_PREAMBLESIZE_LSB_VALUE } // default 3 preamble bytes 0xAAAAAA
/* 0x2e */ { REG_SYNCCONFIG, RF_SYNC_ON | RF_SYNC_FIFOFILL_AUTO | RF_SYNC_SIZE_2 | RF_SYNC_TOL_0}, /* 0x2e */ { REG_SYNCCONFIG, RF_SYNC_ON | RF_SYNC_FIFOFILL_AUTO | RF_SYNC_SIZE_2 | RF_SYNC_TOL_0 },
/* 0x2f */ { REG_SYNCVALUE1, 0x2D}, //attempt to make this compatible with sync1 byte of RFM12B lib /* 0x2f */ { REG_SYNCVALUE1, 0x2D }, //attempt to make this compatible with sync1 byte of RFM12B lib
/* 0x30 */ { REG_SYNCVALUE2, networkID}, //NETWORK ID /* 0x30 */ { REG_SYNCVALUE2, networkID }, //NETWORK ID
/* 0x37 */ { REG_PACKETCONFIG1, RF_PACKET1_FORMAT_VARIABLE | RF_PACKET1_DCFREE_OFF | RF_PACKET1_CRC_ON | RF_PACKET1_CRCAUTOCLEAR_ON | RF_PACKET1_ADRSFILTERING_OFF }, /* 0x37 */ { REG_PACKETCONFIG1, RF_PACKET1_FORMAT_VARIABLE | RF_PACKET1_DCFREE_OFF | RF_PACKET1_CRC_ON | RF_PACKET1_CRCAUTOCLEAR_ON | RF_PACKET1_ADRSFILTERING_OFF },
/* 0x38 */ { REG_PAYLOADLENGTH, 66 }, //in variable length mode: the max frame size, not used in TX /* 0x38 */ { REG_PAYLOADLENGTH, 66 }, //in variable length mode: the max frame size, not used in TX
//* 0x39 */ { REG_NODEADRS, nodeID}, //turned off because we're not using address filtering //* 0x39 */ { REG_NODEADRS, nodeID }, //turned off because we're not using address filtering
/* 0x3C */ { REG_FIFOTHRESH, RF_FIFOTHRESH_TXSTART_FIFONOTEMPTY | RF_FIFOTHRESH_VALUE }, //TX on FIFO not empty
/* 0x3d */ { REG_PACKETCONFIG2, RF_PACKET2_RXRESTARTDELAY_2BITS | RF_PACKET2_AUTORXRESTART_ON | RF_PACKET2_AES_OFF }, //RXRESTARTDELAY must match transmitter PA ramp-down time (bitrate dependent) /* 0x3d */ { REG_PACKETCONFIG2, RF_PACKET2_RXRESTARTDELAY_2BITS | RF_PACKET2_AUTORXRESTART_ON | RF_PACKET2_AES_OFF }, //RXRESTARTDELAY must match transmitter PA ramp-down time (bitrate dependent)
/* 0x6F */ { REG_TESTDAGC, RF_DAGC_CONTINUOUS }, // run DAGC continuously in RX mode /* 0x6F */ { REG_TESTDAGC, RF_DAGC_CONTINUOUS }, // run DAGC continuously in RX mode
{255, 0} {255, 0}
}; };
pinMode(_slaveSelectPin, OUTPUT); pinMode(_slaveSelectPin, OUTPUT);
unselect();
SPI.setDataMode(SPI_MODE0); SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST); SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV2); //max speed, except on Due which can run at system clock speed SPI.setClockDivider(SPI_CLOCK_DIV2); //max speed, except on Due which can run at system clock speed
@ -100,7 +114,7 @@ void RFM69::setMode(byte newMode)
} }
// we are using packet mode, so this check is not really needed // we are using packet mode, so this check is not really needed
// but waiting for mode ready is necessary when going from to sleep because the FIFO may not be immediately available from previous mode // but waiting for mode ready is necessary when going from sleep because the FIFO may not be immediately available from previous mode
while (_mode == RF69_MODE_SLEEP && (readReg(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00); // Wait for ModeReady while (_mode == RF69_MODE_SLEEP && (readReg(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00); // Wait for ModeReady
_mode = newMode; _mode = newMode;
@ -112,7 +126,7 @@ void RFM69::sleep() {
void RFM69::setAddress(byte addr) void RFM69::setAddress(byte addr)
{ {
_address = addr; //& 0x7F; //make sure MSB is reserved for ACK flagging _address = addr;
writeReg(REG_NODEADRS, _address); writeReg(REG_NODEADRS, _address);
} }
@ -135,20 +149,21 @@ bool RFM69::canSend()
void RFM69::send(byte toAddress, const void* buffer, byte bufferSize, bool requestACK) void RFM69::send(byte toAddress, const void* buffer, byte bufferSize, bool requestACK)
{ {
writeReg(REG_PACKETCONFIG2, (readReg(REG_PACKETCONFIG2) & 0xFB) | RF_PACKET2_RXRESTART); // avoid RX deadlocks
while (!canSend()) receiveDone(); while (!canSend()) receiveDone();
sendFrame(toAddress, buffer, bufferSize, requestACK, false); sendFrame(toAddress, buffer, bufferSize, requestACK, false);
} }
//to dramatically increase the chance of getting a packet across, call this function instead of send // to increase the chance of getting a packet across, call this function instead of send
// and it handles all the ACK requesting/retrying for you :) // and it handles all the ACK requesting/retrying for you :)
// The only twist is that you have to manually listen to ACK requests on the other side and send back the ACKs // The only twist is that you have to manually listen to ACK requests on the other side and send back the ACKs
// The reason for the semi-automaton is that the lib is ingterrupt driven and // The reason for the semi-automaton is that the lib is ingterrupt driven and
// requires user action to read the received data and decide what to do with it // requires user action to read the received data and decide what to do with it
// rountrips usually take only 5-8ms at 50kbps // replies usually take only 5-8ms at 50kbps@915Mhz
bool RFM69::sendWithRetry(byte toAddress, const void* buffer, byte bufferSize, byte attempts, byte retryWaitTime) { bool RFM69::sendWithRetry(byte toAddress, const void* buffer, byte bufferSize, byte retries, byte retryWaitTime) {
long sentTime; long sentTime;
byte howLong=0; byte howLong=0;
for (byte i=0; i<attempts; i++) for (byte i=0; i<=retries; i++)
{ {
send(toAddress, buffer, bufferSize, true); send(toAddress, buffer, bufferSize, true);
sentTime = millis(); sentTime = millis();
@ -156,7 +171,6 @@ bool RFM69::sendWithRetry(byte toAddress, const void* buffer, byte bufferSize, b
{ {
if (ACKReceived(toAddress)) if (ACKReceived(toAddress))
{ {
////roundtrip millis
//Serial.print(" ~ms:");Serial.print(millis()-sentTime); //Serial.print(" ~ms:");Serial.print(millis()-sentTime);
return true; return true;
} }
@ -175,17 +189,16 @@ bool RFM69::ACKReceived(byte fromNodeID) {
/// Should be called immediately after reception in case sender wants ACK /// Should be called immediately after reception in case sender wants ACK
void RFM69::sendACK(const void* buffer, byte bufferSize) { void RFM69::sendACK(const void* buffer, byte bufferSize) {
byte sender = SENDERID;
while (!canSend()) receiveDone(); while (!canSend()) receiveDone();
sendFrame(SENDERID, buffer, bufferSize, false, true); sendFrame(sender, buffer, bufferSize, false, true);
} }
void RFM69::sendFrame(byte toAddress, const void* buffer, byte bufferSize, bool requestACK, bool sendACK) void RFM69::sendFrame(byte toAddress, const void* buffer, byte bufferSize, bool requestACK, bool sendACK)
{ {
setMode(RF69_MODE_STANDBY); //turn off receiver to prevent reception while filling fifo setMode(RF69_MODE_STANDBY); //turn off receiver to prevent reception while filling fifo
while ((readReg(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00); // Wait for ModeReady while ((readReg(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00); // Wait for ModeReady
writeReg(REG_DIOMAPPING1, (readReg(REG_DIOMAPPING1) & 0x3F) | RF_DIOMAPPING1_DIO0_00); // DIO0 is "Packet Sent" writeReg(REG_DIOMAPPING1, RF_DIOMAPPING1_DIO0_00); // DIO0 is "Packet Sent"
writeReg(REG_FIFOTHRESH, (readReg(REG_FIFOTHRESH) & 0x7F) | RF_FIFOTHRESH_TXSTART_FIFONOTEMPTY);
if (bufferSize > MAX_DATA_LEN) bufferSize = MAX_DATA_LEN; if (bufferSize > MAX_DATA_LEN) bufferSize = MAX_DATA_LEN;
//write to FIFO //write to FIFO
@ -208,68 +221,73 @@ void RFM69::sendFrame(byte toAddress, const void* buffer, byte bufferSize, bool
/* no need to wait for transmit mode to be ready since its handled by the radio */ /* no need to wait for transmit mode to be ready since its handled by the radio */
setMode(RF69_MODE_TX); setMode(RF69_MODE_TX);
// wait for IRQ when finished transmitting
while (digitalRead(_interruptPin) == 0); //wait for DIO0 to turn HIGH signalling transmission finish while (digitalRead(_interruptPin) == 0); //wait for DIO0 to turn HIGH signalling transmission finish
//while (readReg(REG_IRQFLAGS2) & RF_IRQFLAGS2_PACKETSENT == 0x00); // Wait for ModeReady
setMode(RF69_MODE_STANDBY); setMode(RF69_MODE_STANDBY);
} }
void RFM69::interruptHandler() { void RFM69::interruptHandler() {
//Serial.print("MODE:");Serial.print(readReg(REG_OPMODE), BIN); //pinMode(4, OUTPUT);
//Serial.print("\n IRQ1:");Serial.print(readReg(REG_IRQFLAGS1), BIN); //digitalWrite(4, 1);
//Serial.print(" IRQ2:");Serial.print(readReg(REG_IRQFLAGS2), BIN);
if (_mode == RF69_MODE_RX && (readReg(REG_IRQFLAGS2) & RF_IRQFLAGS2_PAYLOADREADY)) if (_mode == RF69_MODE_RX && (readReg(REG_IRQFLAGS2) & RF_IRQFLAGS2_PAYLOADREADY))
{ {
//Serial.print("\nRDY");
setMode(RF69_MODE_STANDBY); setMode(RF69_MODE_STANDBY);
select(); select();
SPI.transfer(REG_FIFO & 0x7f); SPI.transfer(REG_FIFO & 0x7f);
PAYLOADLEN = SPI.transfer(0); PAYLOADLEN = SPI.transfer(0);
DATALEN = PAYLOADLEN - 3;
PAYLOADLEN = PAYLOADLEN > 66 ? 66 : PAYLOADLEN; //precaution PAYLOADLEN = PAYLOADLEN > 66 ? 66 : PAYLOADLEN; //precaution
TARGETID = SPI.transfer(0); 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==0)) //match this node's address, or broadcast addr 0x0 or anything in promiscuous mode
{ {
PAYLOADLEN = 0; PAYLOADLEN = 0;
unselect(); unselect();
//digitalWrite(4, 0);
return; return;
} }
SENDERID = SPI.transfer(0); SENDERID = SPI.transfer(0);
byte CTLbyte = SPI.transfer(0); byte CTLbyte = SPI.transfer(0);
ACK_RECEIVED = CTLbyte & 0x80; //extract ACK-requested flag ACK_RECEIVED = CTLbyte & 0x80; //extract ACK-requested flag
ACK_REQUESTED = CTLbyte & 0x40; //extract ACK-received flag ACK_REQUESTED = CTLbyte & 0x40; //extract ACK-received flag
//Serial.print(" *** ");
DATALEN = PAYLOADLEN - 3;
for (byte i= 0; i < DATALEN; i++) for (byte i= 0; i < DATALEN; i++)
{ {
DATA[i] = SPI.transfer(0); DATA[i] = SPI.transfer(0);
//Serial.print((char)DATA[i]);
} }
//Serial.println(" ***");
//Serial.println(DATALEN);
unselect(); unselect();
setMode(RF69_MODE_RX); setMode(RF69_MODE_RX);
} }
//else Serial.println("UNK"); //digitalWrite(4, 0);
} }
void RFM69::isr0() { selfPointer->interruptHandler(); } void RFM69::isr0() { selfPointer->interruptHandler(); }
void RFM69::receiveBegin() { void RFM69::receiveBegin() {
DATALEN = SENDERID = TARGETID = PAYLOADLEN = ACK_REQUESTED = ACK_RECEIVED = 0; DATALEN = 0;
writeReg(REG_DIOMAPPING1, (readReg(REG_DIOMAPPING1) & 0x3F) | RF_DIOMAPPING1_DIO0_01); //set DIO0 to "PAYLOADREADY" in receive mode SENDERID = 0;
TARGETID = 0;
PAYLOADLEN = 0;
ACK_REQUESTED = 0;
ACK_RECEIVED = 0;
if (readReg(REG_IRQFLAGS2) & RF_IRQFLAGS2_PAYLOADREADY)
writeReg(REG_PACKETCONFIG2, (readReg(REG_PACKETCONFIG2) & 0xFB) | RF_PACKET2_RXRESTART); // avoid RX deadlocks
writeReg(REG_DIOMAPPING1, RF_DIOMAPPING1_DIO0_01); //set DIO0 to "PAYLOADREADY" in receive mode
setMode(RF69_MODE_RX); setMode(RF69_MODE_RX);
} }
bool RFM69::receiveDone() { bool RFM69::receiveDone() {
noInterrupts(); //will be re-enabled in the setMode() method // ATOMIC_BLOCK(ATOMIC_FORCEON)
// {
noInterrupts(); //re-enabled in unselect() via setMode()
if (_mode == RF69_MODE_RX && PAYLOADLEN>0) if (_mode == RF69_MODE_RX && PAYLOADLEN>0)
{ {
setMode(RF69_MODE_STANDBY); setMode(RF69_MODE_STANDBY);
return true; return true;
} }
receiveBegin(); receiveBegin();
return false; return false;
//}
} }
// To enable encryption: radio.encrypt("ABCDEFGHIJKLMNOP"); // To enable encryption: radio.encrypt("ABCDEFGHIJKLMNOP");

28
RFM69.h
View File

@ -1,11 +1,13 @@
// **********************************************************************************
// Driver definition for HopeRF RFM69W/RFM69HW, Semtech SX1231/1231H // Driver definition for HopeRF RFM69W/RFM69HW, Semtech SX1231/1231H
// **********************************************************************************
// Creative Commons Attrib Share-Alike License // Creative Commons Attrib Share-Alike License
// If you want to use/extend this library please abide with the license terms: http://creativecommons.org/licenses/by-sa/3.0/ // You are free to use/extend this library but please abide with the CCSA license:
// http://creativecommons.org/licenses/by-sa/3.0/
// 2013-06-14 (C) felix@lowpowerlab.com // 2013-06-14 (C) felix@lowpowerlab.com
// **********************************************************************************
#ifndef RFM69_h #ifndef RFM69_h
#define RFM69_h #define RFM69_h
#include <Arduino.h> //assumes Arduino IDE v1.0 or greater #include <Arduino.h> //assumes Arduino IDE v1.0 or greater
#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 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)
@ -29,13 +31,14 @@
class RFM69 { class RFM69 {
public: public:
volatile byte DATA[MAX_DATA_LEN]; // recv/xmit buf, including hdr & crc bytes static volatile byte DATA[MAX_DATA_LEN]; // recv/xmit buf, including hdr & crc bytes
volatile byte DATALEN; static volatile byte DATALEN;
volatile byte SENDERID; static volatile byte SENDERID;
volatile byte TARGETID; //should match _address static volatile byte TARGETID; //should match _address
volatile byte PAYLOADLEN; static volatile byte PAYLOADLEN;
volatile byte ACK_REQUESTED; static volatile byte ACK_REQUESTED;
volatile byte ACK_RECEIVED; /// Should be polled immediately after sending a packet with ACK request static volatile byte ACK_RECEIVED; /// Should be polled immediately after sending a packet with ACK request
static volatile byte _mode; //should be protected?
RFM69(byte slaveSelectPin=SPI_CS, byte interruptPin=RF69_IRQ_PIN, bool isRFM69HW=false) { RFM69(byte slaveSelectPin=SPI_CS, byte interruptPin=RF69_IRQ_PIN, bool isRFM69HW=false) {
_slaveSelectPin = slaveSelectPin; _slaveSelectPin = slaveSelectPin;
@ -50,7 +53,7 @@ class RFM69 {
void setAddress(byte addr); void setAddress(byte addr);
bool canSend(); bool canSend();
void send(byte toAddress, const void* buffer, byte bufferSize, bool requestACK=false); void send(byte toAddress, const void* buffer, byte bufferSize, bool requestACK=false);
bool sendWithRetry(byte toAddress, const void* buffer, byte bufferSize, byte attempts=3, byte retryWaitTime=15); bool sendWithRetry(byte toAddress, const void* buffer, byte bufferSize, byte retries=2, byte retryWaitTime=15);
bool receiveDone(); bool receiveDone();
bool ACKReceived(byte fromNodeID); bool ACKReceived(byte fromNodeID);
void sendACK(const void* buffer = "", uint8_t bufferSize=0); void sendACK(const void* buffer = "", uint8_t bufferSize=0);
@ -75,10 +78,9 @@ class RFM69 {
static RFM69* selfPointer; static RFM69* selfPointer;
byte _slaveSelectPin; byte _slaveSelectPin;
byte _interruptPin; byte _interruptPin;
byte _mode;
byte _address; byte _address;
byte _powerLevel;
bool _promiscuousMode; bool _promiscuousMode;
byte _powerLevel;
bool _isRFM69HW; bool _isRFM69HW;
void receiveBegin(); void receiveBegin();

View File

@ -1,3 +1,11 @@
// **********************************************************************************
// Registers used in driver definition for HopeRF RFM69W/RFM69HW, Semtech SX1231/1231H
// **********************************************************************************
// Creative Commons Attrib Share-Alike License
// You are free to use/extend this library but please abide with the CCSA license:
// http://creativecommons.org/licenses/by-sa/3.0/
// 2013-06-14 (C) felix@lowpowerlab.com
// **********************************************************************************
//************************************************** //**************************************************
// RFM69/SX1231 Internal registers addresses // RFM69/SX1231 Internal registers addresses