License, add/update get/setFrequency(), & more
Update license to GPL 3.0 Add getFrequency() Update setFrequency(freq in hz) Add setNetwork(id) Modify IRQ pinout for atmega32u4 (Arduino Leonardo)
This commit is contained in:
parent
d6cadc7a96
commit
dc6b33d98b
35
RFM69.cpp
35
RFM69.cpp
|
|
@ -9,22 +9,21 @@
|
|||
// This program is free software; you can redistribute it
|
||||
// and/or modify it under the terms of the GNU General
|
||||
// Public License as published by the Free Software
|
||||
// Foundation; either version 2 of the License, or
|
||||
// Foundation; either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will
|
||||
// be useful, but WITHOUT ANY WARRANTY; without even the
|
||||
// implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
// PARTICULAR PURPOSE. See the GNU General Public
|
||||
// PARTICULAR PURPOSE. See the GNU General Public
|
||||
// License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General
|
||||
// Public License along with this program; if not, write
|
||||
// to the Free Software Foundation, Inc.,
|
||||
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
// Public License along with this program.
|
||||
// If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Licence can be viewed at
|
||||
// http://www.fsf.org/licenses/gpl.txt
|
||||
// http://www.gnu.org/licenses/gpl-3.0.txt
|
||||
//
|
||||
// Please maintain this license information along with authorship
|
||||
// and copyright notices in any redistribution of this code
|
||||
|
|
@ -110,11 +109,19 @@ bool RFM69::initialize(byte freqBand, byte nodeID, byte networkID)
|
|||
return true;
|
||||
}
|
||||
|
||||
void RFM69::setFrequency(uint32_t FRF)
|
||||
//return the frequency (in Hz)
|
||||
uint32_t RFM69::getFrequency()
|
||||
{
|
||||
writeReg(REG_FRFMSB, FRF >> 16);
|
||||
writeReg(REG_FRFMID, FRF >> 8);
|
||||
writeReg(REG_FRFLSB, FRF);
|
||||
return RF69_FSTEP * (((uint32_t)readReg(REG_FRFMSB)<<16) + ((uint16_t)readReg(REG_FRFMID)<<8) + readReg(REG_FRFLSB));
|
||||
}
|
||||
|
||||
//set the frequency (in Hz)
|
||||
void RFM69::setFrequency(uint32_t freqHz)
|
||||
{
|
||||
freqHz /= RF69_FSTEP; //divide down by FSTEP to get FRF
|
||||
writeReg(REG_FRFMSB, freqHz >> 16);
|
||||
writeReg(REG_FRFMID, freqHz >> 8);
|
||||
writeReg(REG_FRFLSB, freqHz);
|
||||
}
|
||||
|
||||
void RFM69::setMode(byte newMode)
|
||||
|
|
@ -159,6 +166,11 @@ void RFM69::setAddress(byte addr)
|
|||
writeReg(REG_NODEADRS, _address);
|
||||
}
|
||||
|
||||
void RFM69::setNetwork(byte networkID)
|
||||
{
|
||||
writeReg(REG_SYNCVALUE2, networkID);
|
||||
}
|
||||
|
||||
// set output power: 0=min, 31=max
|
||||
// this results in a "weaker" transmitted signal, and directly results in a lower RSSI at the receiver
|
||||
void RFM69::setPowerLevel(byte powerLevel)
|
||||
|
|
@ -225,7 +237,8 @@ bool RFM69::ACKRequested() {
|
|||
/// Should be called immediately after reception in case sender wants ACK
|
||||
void RFM69::sendACK(const void* buffer, byte bufferSize) {
|
||||
byte sender = SENDERID;
|
||||
while (!canSend()) receiveDone();
|
||||
long now = millis();
|
||||
while (!canSend() && millis()-now < RF69_CSMA_LIMIT_MS) receiveDone();
|
||||
sendFrame(sender, buffer, bufferSize, false, true);
|
||||
}
|
||||
|
||||
|
|
|
|||
22
RFM69.h
22
RFM69.h
|
|
@ -9,22 +9,21 @@
|
|||
// This program is free software; you can redistribute it
|
||||
// and/or modify it under the terms of the GNU General
|
||||
// Public License as published by the Free Software
|
||||
// Foundation; either version 2 of the License, or
|
||||
// Foundation; either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will
|
||||
// be useful, but WITHOUT ANY WARRANTY; without even the
|
||||
// implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
// PARTICULAR PURPOSE. See the GNU General Public
|
||||
// PARTICULAR PURPOSE. See the GNU General Public
|
||||
// License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General
|
||||
// Public License along with this program; if not, write
|
||||
// to the Free Software Foundation, Inc.,
|
||||
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
// Public License along with this program.
|
||||
// If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Licence can be viewed at
|
||||
// http://www.fsf.org/licenses/gpl.txt
|
||||
// http://www.gnu.org/licenses/gpl-3.0.txt
|
||||
//
|
||||
// Please maintain this license information along with authorship
|
||||
// and copyright notices in any redistribution of this code
|
||||
|
|
@ -37,14 +36,18 @@
|
|||
#define RF69_SPI_CS SS // SS is the SPI slave select pin, for instance D10 on atmega328
|
||||
|
||||
// INT0 on AVRs should be connected to RFM69's DIO0 (ex on Atmega328 it's D2, on Atmega644/1284 it's D2)
|
||||
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__) || defined(__AVR_ATmega32U4__)
|
||||
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__)
|
||||
#define RF69_IRQ_PIN 2
|
||||
#define RF69_IRQ_NUM 0
|
||||
#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
|
||||
#define RF69_IRQ_PIN 2
|
||||
#define RF69_IRQ_NUM 2
|
||||
#elif defined(__AVR_ATmega32U4__)
|
||||
#define RF69_IRQ_PIN 3
|
||||
#define RF69_IRQ_NUM 0
|
||||
#endif
|
||||
|
||||
|
||||
#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
|
||||
|
|
@ -62,6 +65,7 @@
|
|||
#define COURSE_TEMP_COEF -90 // puts the temperature reading in the ballpark, user can fine tune the returned value
|
||||
#define RF69_BROADCAST_ADDR 255
|
||||
#define RF69_CSMA_LIMIT_MS 1000
|
||||
#define RF69_FSTEP 61.03515625 // == FXOSC/2^19 = 32mhz/2^19 (p13 in DS)
|
||||
|
||||
class RFM69 {
|
||||
public:
|
||||
|
|
@ -87,6 +91,7 @@ class RFM69 {
|
|||
|
||||
bool initialize(byte freqBand, byte ID, byte networkID=1);
|
||||
void setAddress(byte addr);
|
||||
void setNetwork(byte networkID);
|
||||
bool canSend();
|
||||
void send(byte toAddress, const void* buffer, byte bufferSize, bool requestACK=false);
|
||||
bool sendWithRetry(byte toAddress, const void* buffer, byte bufferSize, byte retries=2, byte retryWaitTime=40); //40ms roundtrip req for 61byte packets
|
||||
|
|
@ -94,7 +99,8 @@ class RFM69 {
|
|||
bool ACKReceived(byte fromNodeID);
|
||||
bool ACKRequested();
|
||||
void sendACK(const void* buffer = "", uint8_t bufferSize=0);
|
||||
void setFrequency(uint32_t FRF);
|
||||
uint32_t getFrequency();
|
||||
void setFrequency(uint32_t freqHz);
|
||||
void encrypt(const char* key);
|
||||
void setCS(byte newSPISlaveSelect);
|
||||
int readRSSI(bool forceTrigger=false);
|
||||
|
|
|
|||
Loading…
Reference in New Issue