|
MySensors Library & Examples
2.3.2
|
34 #if !defined(RFM69_SPI)
35 #define RFM69_SPI hwSPI
38 #define RFM69_MAX_DATA_LEN (61u) // 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 - 2 bytes crc)
40 #if defined(ARDUINO_ARCH_AVR)
41 #if defined(__AVR_ATmega32U4__)
42 #define DEFAULT_RFM69_IRQ_PIN (3)
44 #define DEFAULT_RFM69_IRQ_PIN (2)
46 #define DEFAULT_RFM69_IRQ_NUM digitalPinToInterrupt(MY_RFM69_IRQ_PIN)
47 #elif defined(ARDUINO_ARCH_ESP8266)
48 #define DEFAULT_RFM69_IRQ_PIN (5)
49 #define DEFAULT_RFM69_IRQ_NUM digitalPinToInterrupt(MY_RFM69_IRQ_PIN)
50 #elif defined(ARDUINO_ARCH_ESP32)
51 #define DEFAULT_RFM69_IRQ_PIN (16)
52 #define DEFAULT_RFM69_IRQ_NUM digitalPinToInterrupt(DEFAULT_RFM69_IRQ_PIN)
53 #elif defined(ARDUINO_ARCH_SAMD)
54 #define DEFAULT_RFM69_IRQ_PIN (2)
55 #define DEFAULT_RFM69_IRQ_NUM digitalPinToInterrupt(MY_RFM69_IRQ_PIN)
56 #elif defined(LINUX_ARCH_RASPBERRYPI)
57 #define DEFAULT_RFM69_IRQ_PIN (22)
58 #define DEFAULT_RFM69_IRQ_NUM DEFAULT_RFM69_IRQ_PIN
59 #elif defined(ARDUINO_ARCH_STM32F1)
60 #define DEFAULT_RFM69_IRQ_PIN (PA3)
61 #define DEFAULT_RFM69_IRQ_NUM DEFAULT_RFM69_IRQ_PIN
62 #elif defined(TEENSYDUINO)
63 #define DEFAULT_RFM69_IRQ_PIN (8)
64 #define DEFAULT_RFM69_IRQ_NUM digitalPinToInterrupt(MY_RFM69_IRQ_PIN)
66 #define DEFAULT_RFM69_IRQ_PIN (2)
67 #define DEFAULT_RFM69_IRQ_NUM (2)
70 #define DEFAULT_RFM69_CS_PIN (SS)
73 #if (MY_RFM69_SPI_SPEED >= F_CPU / 2)
74 #define RFM69_CLOCK_DIV SPI_CLOCK_DIV2
75 #elif (MY_RFM69_SPI_SPEED >= F_CPU / 4)
76 #define RFM69_CLOCK_DIV SPI_CLOCK_DIV4
77 #elif (MY_RFM69_SPI_SPEED >= F_CPU / 8)
78 #define RFM69_CLOCK_DIV SPI_CLOCK_DIV8
79 #elif (MY_RFM69_SPI_SPEED >= F_CPU / 16)
80 #define RFM69_CLOCK_DIV SPI_CLOCK_DIV16
81 #elif (MY_RFM69_SPI_SPEED >= F_CPU / 32)
82 #define RFM69_CLOCK_DIV SPI_CLOCK_DIV32
83 #elif (MY_RFM69_SPI_SPEED >= F_CPU / 64)
84 #define RFM69_CLOCK_DIV SPI_CLOCK_DIV64
85 #elif (MY_RFM69_SPI_SPEED >= F_CPU / 128)
86 #define RFM69_CLOCK_DIV SPI_CLOCK_DIV128
88 #define RFM69_CLOCK_DIV SPI_CLOCK_DIV256
92 #define RFM69_POWERUP_DELAY_MS (100u)
94 #define CSMA_LIMIT -90 // upper RX signal sensitivity threshold in dBm for carrier sense access
95 #define RFM69_MODE_SLEEP 0 // XTAL OFF
96 #define RFM69_MODE_STANDBY 1 // XTAL ON
97 #define RFM69_MODE_SYNTH 2 // PLL ON
98 #define RFM69_MODE_RX 3 // RX MODE
99 #define RFM69_MODE_TX 4 // TX MODE
102 #define RFM69_315MHZ 31 // non trivial values to avoid misconfiguration
103 #define RFM69_433MHZ 43
104 #define RFM69_868MHZ 86
105 #define RFM69_915MHZ 91
108 #define COURSE_TEMP_COEF -90 // puts the temperature reading in the ballpark, user can fine tune the returned value
109 #define RFM69_BROADCAST_ADDR 255
110 #define RFM69_CSMA_LIMIT_MS 1000
111 #define RFM69_TX_LIMIT_MS 1000
113 #define RFM69_FXOSC (32*1000000ul)
114 #define RFM69_FSTEP (RFM69_FXOSC / 524288ul)
117 #define RFM69_CTL_SENDACK 0x80
118 #define RFM69_CTL_REQACK 0x40
124 static volatile uint8_t
DATA[RFM69_MAX_DATA_LEN];
130 static volatile uint8_t
145 bool isRFM69HW=
false,
151 _mode = RFM69_MODE_STANDBY;
156 #if !defined(SPI_HAS_TRANSACTION)
157 #if defined (SPCR) && defined (SPSR)
164 #endif // SPI_HAS_TRANSACTION
167 bool initialize(uint8_t freqBand, uint8_t ID, uint8_t networkID=1);
171 virtual void send(uint8_t toAddress,
const void* buffer, uint8_t bufferSize,
172 bool requestACK=
false);
173 virtual bool sendWithRetry(uint8_t toAddress,
const void* buffer, uint8_t bufferSize,
174 uint8_t retries=5, uint8_t retryWaitTime=
179 virtual void sendACK(
const void* buffer =
"", uint8_t bufferSize=0);
183 void setCS(uint8_t newSPISlaveSelect);
184 int16_t
readRSSI(
bool forceTrigger=
false);
200 void writeReg(uint8_t addr, uint8_t val);
206 virtual void sendFrame(uint8_t toAddress,
const void* buffer, uint8_t size,
bool requestACK=
false,
217 #if defined (SPCR) && defined (SPSR)
226 virtual void setMode(uint8_t mode);
uint8_t readReg(uint8_t addr)
readReg
void encrypt(const char *key)
encrypt
virtual void unselect()
unselect
void rcCalibration()
rcCalibration (calibrate the internal RC oscillator for use in wide temperature variations - see data...
bool ACKRequested()
ACKRequested.
uint8_t _interruptNum
_interruptNum
uint8_t readTemperature(uint8_t calFactor=0)
readTemperature (get CMOS temperature (8bit))
static volatile uint8_t SENDERID
SENDERID.
static volatile uint8_t DATALEN
DATALEN.
static volatile uint8_t DATA[RFM69_MAX_DATA_LEN]
recv/xmit buf, including hdr & crc bytes
virtual void receiveBegin()
receiveBegin
virtual void interruptHandler()
interruptHandler
void setCS(uint8_t newSPISlaveSelect)
setCS
void setFrequency(uint32_t freqHz)
setFrequency
uint8_t _interruptPin
_interruptPin
void powerDown(void)
powerDown
static volatile uint8_t PAYLOADLEN
PAYLOADLEN.
bool ACKReceived(uint8_t fromNodeID)
ACKReceived.
virtual void select()
select
#define MY_RFM69_CS_PIN
RFM69 SPI chip select pin.
#define MY_RFM69_IRQ_PIN
Define this to override the default RFM69 IRQ pin assignment.
virtual void setMode(uint8_t mode)
setMode
static volatile uint8_t ACK_RECEIVED
Should be polled immediately after sending a packet with ACK requestwith ACK request.
bool initialize(uint8_t freqBand, uint8_t ID, uint8_t networkID=1)
initialize
virtual void setHighPowerRegs(bool onOff)
setHighPowerRegs
bool _promiscuousMode
_promiscuousMode
static RFM69 * selfPointer
selfPointer
void powerUp(void)
powerUp
static volatile uint8_t _mode
should be protected?
void standBy(void)
standBy
static volatile int16_t RSSI
most accurate RSSI during reception (closest to the reception)
virtual void sendFrame(uint8_t toAddress, const void *buffer, uint8_t size, bool requestACK=false, bool sendACK=false)
sendFrame
bool sanityCheck(void)
sanityCheck
virtual void sendACK(const void *buffer="", uint8_t bufferSize=0)
sendACK
virtual void interruptHook(uint8_t CTLbyte)
interruptHook
void setNetwork(uint8_t networkID)
setNetwork
bool _isRFM69HW
_isRFM69HW
virtual void setHighPower(bool onOFF=true)
setHighPower (have to call it after initialize for RFM69HW)
uint32_t getFrequency()
getFrequency
static volatile uint8_t ACK_REQUESTED
ACK_REQUESTED.
virtual void send(uint8_t toAddress, const void *buffer, uint8_t bufferSize, bool requestACK=false)
send
void promiscuous(bool onOff=true)
promiscuous
void writeReg(uint8_t addr, uint8_t val)
writeReg
RFM69(uint8_t slaveSelectPin=MY_RFM69_CS_PIN, uint8_t interruptPin=MY_RFM69_IRQ_PIN, bool isRFM69HW=false, uint8_t interruptNum=digitalPinToInterrupt(MY_RFM69_IRQ_PIN))
Constructor.
uint8_t _powerLevel
_powerLevel
uint8_t _slaveSelectPin
_slaveSelectPin
int16_t readRSSI(bool forceTrigger=false)
readRSSI
virtual void setPowerLevel(uint8_t level)
setPowerLevel (reduce/increase transmit power level)
virtual bool receiveDone()
receiveDone
void readAllRegs()
readAllRegs
void setAddress(uint8_t addr)
setAddress
virtual bool sendWithRetry(uint8_t toAddress, const void *buffer, uint8_t bufferSize, uint8_t retries=5, uint8_t retryWaitTime=200)
sendWithRetry (40ms roundtrip req for 61byte packets, adjusted)
static volatile uint8_t TARGETID
should match _address