233 #include "pins_arduino.h"
241 #define RF69_FXOSC 32000000.0
244 #define RF69_FSTEP (RF69_FXOSC / 524288)
248 #define RF69_NUM_INTERRUPTS 3
251 #define RF69_SPI_WRITE_MASK 0x80
254 #define RF69_FIFO_SIZE 66
257 #define RF69_MAX_ENCRYPTABLE_PAYLOAD_LEN 64
261 #define RF69_HEADER_LEN 4
269 #ifndef RF69_MAX_MESSAGE_LEN
270 #define RF69_MAX_MESSAGE_LEN (RF69_MAX_ENCRYPTABLE_PAYLOAD_LEN - RF69_HEADER_LEN)
274 #define RF69_MODE_IDLE 0
275 #define RF69_MODE_RX 1
276 #define RF69_MODE_TX 2
279 #define RF69_DEFAULT_NODE_ADDRESS 0
282 #define RF69_BROADCAST_ADDRESS 0xff
285 #define RF69_REG_00_FIFO 0x00
286 #define RF69_REG_01_OPMODE 0x01
287 #define RF69_REG_02_DATAMODUL 0x02
288 #define RF69_REG_03_BITRATEMSB 0x03
289 #define RF69_REG_04_BITRATELSB 0x04
290 #define RF69_REG_05_FDEVMSB 0x05
291 #define RF69_REG_06_FDEVLSB 0x06
292 #define RF69_REG_07_FRFMSB 0x07
293 #define RF69_REG_08_FRFMID 0x08
294 #define RF69_REG_09_FRFLSB 0x09
295 #define RF69_REG_0A_OSC1 0x0a
296 #define RF69_REG_0B_AFCCTRL 0x0b
297 #define RF69_REG_0C_RESERVED 0x0c
298 #define RF69_REG_0D_LISTEN1 0x0d
299 #define RF69_REG_0E_LISTEN2 0x0e
300 #define RF69_REG_0F_LISTEN3 0x0f
301 #define RF69_REG_10_VERSION 0x10
302 #define RF69_REG_11_PALEVEL 0x11
303 #define RF69_REG_12_PARAMP 0x12
304 #define RF69_REG_13_OCP 0x13
305 #define RF69_REG_14_RESERVED 0x14
306 #define RF69_REG_15_RESERVED 0x15
307 #define RF69_REG_16_RESERVED 0x16
308 #define RF69_REG_17_RESERVED 0x17
309 #define RF69_REG_18_LNA 0x18
310 #define RF69_REG_19_RXBW 0x19
311 #define RF69_REG_1A_AFCBW 0x1a
312 #define RF69_REG_1B_OOKPEAK 0x1b
313 #define RF69_REG_1C_OOKAVG 0x1c
314 #define RF69_REG_1D_OOKFIX 0x1d
315 #define RF69_REG_1E_AFCFEI 0x1e
316 #define RF69_REG_1F_AFCMSB 0x1f
317 #define RF69_REG_20_AFCLSB 0x20
318 #define RF69_REG_21_FEIMSB 0x21
319 #define RF69_REG_22_FEILSB 0x22
320 #define RF69_REG_23_RSSICONFIG 0x23
321 #define RF69_REG_24_RSSIVALUE 0x24
322 #define RF69_REG_25_DIOMAPPING1 0x25
323 #define RF69_REG_26_DIOMAPPING2 0x26
324 #define RF69_REG_27_IRQFLAGS1 0x27
325 #define RF69_REG_28_IRQFLAGS2 0x28
326 #define RF69_REG_29_RSSITHRESH 0x29
327 #define RF69_REG_2A_RXTIMEOUT1 0x2a
328 #define RF69_REG_2B_RXTIMEOUT2 0x2b
329 #define RF69_REG_2C_PREAMBLEMSB 0x2c
330 #define RF69_REG_2D_PREAMBLELSB 0x2d
331 #define RF69_REG_2E_SYNCCONFIG 0x2e
332 #define RF69_REG_2F_SYNCVALUE1 0x2f
334 #define RF69_REG_37_PACKETCONFIG1 0x37
335 #define RF69_REG_38_PAYLOADLENGTH 0x38
336 #define RF69_REG_39_NODEADRS 0x39
337 #define RF69_REG_3A_BROADCASTADRS 0x3a
338 #define RF69_REG_3B_AUTOMODES 0x3b
339 #define RF69_REG_3C_FIFOTHRESH 0x3c
340 #define RF69_REG_3D_PACKETCONFIG2 0x3d
341 #define RF69_REG_3E_AESKEY1 0x3e
343 #define RF69_REG_4E_TEMP1 0x4e
344 #define RF69_REG_4F_TEMP2 0x4f
345 #define RF69_REG_58_TESTLNA 0x58
346 #define RF69_REG_5A_TESTPA1 0x5a
347 #define RF69_REG_5C_TSETPA2 0x5c
348 #define RF69_REG_6F_TESTDAGC 0x6f
349 #define RF69_REG_71_TESTAFC 0x71
355 #define RF69_OPMODE_SEQUENCEROFF 0x80
356 #define RF69_OPMODE_LISTENON 0x40
357 #define RF69_OPMODE_LISTENABORT 0x20
358 #define RF69_OPMODE_MODE 0x1c
359 #define RF69_OPMODE_MODE_SLEEP 0x00
360 #define RF69_OPMODE_MODE_STDBY 0x04
361 #define RF69_OPMODE_MODE_FS 0x08
362 #define RF69_OPMODE_MODE_TX 0x0c
363 #define RF69_OPMODE_MODE_RX 0x10
366 #define RF69_DATAMODUL_DATAMODE 0x60
367 #define RF69_DATAMODUL_DATAMODE_PACKET 0x00
368 #define RF69_DATAMODUL_DATAMODE_CONT_WITH_SYNC 0x40
369 #define RF69_DATAMODUL_DATAMODE_CONT_WITHOUT_SYNC 0x60
370 #define RF69_DATAMODUL_MODULATIONTYPE 0x18
371 #define RF69_DATAMODUL_MODULATIONTYPE_FSK 0x00
372 #define RF69_DATAMODUL_MODULATIONTYPE_OOK 0x08
373 #define RF69_DATAMODUL_MODULATIONSHAPING 0x03
374 #define RF69_DATAMODUL_MODULATIONSHAPING_FSK_NONE 0x00
375 #define RF69_DATAMODUL_MODULATIONSHAPING_FSK_BT1_0 0x01
376 #define RF69_DATAMODUL_MODULATIONSHAPING_FSK_BT0_5 0x02
377 #define RF69_DATAMODUL_MODULATIONSHAPING_FSK_BT0_3 0x03
378 #define RF69_DATAMODUL_MODULATIONSHAPING_OOK_NONE 0x00
379 #define RF69_DATAMODUL_MODULATIONSHAPING_OOK_BR 0x01
380 #define RF69_DATAMODUL_MODULATIONSHAPING_OOK_2BR 0x02
383 #define RF69_PALEVEL_PA0ON 0x80
384 #define RF69_PALEVEL_PA1ON 0x40
385 #define RF69_PALEVEL_PA2ON 0x20
386 #define RF69_PALEVEL_OUTPUTPOWER 0x1f
389 #define RF69_RSSICONFIG_RSSIDONE 0x02
390 #define RF69_RSSICONFIG_RSSISTART 0x01
393 #define RF69_DIOMAPPING1_DIO0MAPPING 0xc0
394 #define RF69_DIOMAPPING1_DIO0MAPPING_00 0x00
395 #define RF69_DIOMAPPING1_DIO0MAPPING_01 0x40
396 #define RF69_DIOMAPPING1_DIO0MAPPING_10 0x80
397 #define RF69_DIOMAPPING1_DIO0MAPPING_11 0xc0
399 #define RF69_DIOMAPPING1_DIO1MAPPING 0x30
400 #define RF69_DIOMAPPING1_DIO1MAPPING_00 0x00
401 #define RF69_DIOMAPPING1_DIO1MAPPING_01 0x10
402 #define RF69_DIOMAPPING1_DIO1MAPPING_10 0x20
403 #define RF69_DIOMAPPING1_DIO1MAPPING_11 0x30
405 #define RF69_DIOMAPPING1_DIO2MAPPING 0x0c
406 #define RF69_DIOMAPPING1_DIO2MAPPING_00 0x00
407 #define RF69_DIOMAPPING1_DIO2MAPPING_01 0x04
408 #define RF69_DIOMAPPING1_DIO2MAPPING_10 0x08
409 #define RF69_DIOMAPPING1_DIO2MAPPING_11 0x0c
411 #define RF69_DIOMAPPING1_DIO3MAPPING 0x03
412 #define RF69_DIOMAPPING1_DIO3MAPPING_00 0x00
413 #define RF69_DIOMAPPING1_DIO3MAPPING_01 0x01
414 #define RF69_DIOMAPPING1_DIO3MAPPING_10 0x02
415 #define RF69_DIOMAPPING1_DIO3MAPPING_11 0x03
418 #define RF69_DIOMAPPING2_DIO4MAPPING 0xc0
419 #define RF69_DIOMAPPING2_DIO4MAPPING_00 0x00
420 #define RF69_DIOMAPPING2_DIO4MAPPING_01 0x40
421 #define RF69_DIOMAPPING2_DIO4MAPPING_10 0x80
422 #define RF69_DIOMAPPING2_DIO4MAPPING_11 0xc0
424 #define RF69_DIOMAPPING2_DIO5MAPPING 0x30
425 #define RF69_DIOMAPPING2_DIO5MAPPING_00 0x00
426 #define RF69_DIOMAPPING2_DIO5MAPPING_01 0x10
427 #define RF69_DIOMAPPING2_DIO5MAPPING_10 0x20
428 #define RF69_DIOMAPPING2_DIO5MAPPING_11 0x30
430 #define RF69_DIOMAPPING2_CLKOUT 0x07
431 #define RF69_DIOMAPPING2_CLKOUT_FXOSC_ 0x00
432 #define RF69_DIOMAPPING2_CLKOUT_FXOSC_2 0x01
433 #define RF69_DIOMAPPING2_CLKOUT_FXOSC_4 0x02
434 #define RF69_DIOMAPPING2_CLKOUT_FXOSC_8 0x03
435 #define RF69_DIOMAPPING2_CLKOUT_FXOSC_16 0x04
436 #define RF69_DIOMAPPING2_CLKOUT_FXOSC_32 0x05
437 #define RF69_DIOMAPPING2_CLKOUT_FXOSC_RC 0x06
438 #define RF69_DIOMAPPING2_CLKOUT_FXOSC_OFF 0x07
441 #define RF69_IRQFLAGS1_MODEREADY 0x80
442 #define RF69_IRQFLAGS1_RXREADY 0x40
443 #define RF69_IRQFLAGS1_TXREADY 0x20
444 #define RF69_IRQFLAGS1_PLLLOCK 0x10
445 #define RF69_IRQFLAGS1_RSSI 0x08
446 #define RF69_IRQFLAGS1_TIMEOUT 0x04
447 #define RF69_IRQFLAGS1_AUTOMODE 0x02
448 #define RF69_IRQFLAGS1_SYNADDRESSMATCH 0x01
451 #define RF69_IRQFLAGS2_FIFOFULL 0x80
452 #define RF69_IRQFLAGS2_FIFONOTEMPTY 0x40
453 #define RF69_IRQFLAGS2_FIFOLEVEL 0x20
454 #define RF69_IRQFLAGS2_FIFOOVERRUN 0x10
455 #define RF69_IRQFLAGS2_PACKETSENT 0x08
456 #define RF69_IRQFLAGS2_PAYLOADREADY 0x04
457 #define RF69_IRQFLAGS2_CRCOK 0x02
460 #define RF69_SYNCCONFIG_SYNCON 0x80
461 #define RF69_SYNCCONFIG_FIFOFILLCONDITION_MANUAL 0x40
462 #define RF69_SYNCCONFIG_SYNCSIZE 0x38
463 #define RF69_SYNCCONFIG_SYNCSIZE_1 0x00
464 #define RF69_SYNCCONFIG_SYNCSIZE_2 0x08
465 #define RF69_SYNCCONFIG_SYNCSIZE_3 0x10
466 #define RF69_SYNCCONFIG_SYNCSIZE_4 0x18
467 #define RF69_SYNCCONFIG_SYNCSIZE_5 0x20
468 #define RF69_SYNCCONFIG_SYNCSIZE_6 0x28
469 #define RF69_SYNCCONFIG_SYNCSIZE_7 0x30
470 #define RF69_SYNCCONFIG_SYNCSIZE_8 0x38
471 #define RF69_SYNCCONFIG_SYNCSIZE_SYNCTOL 0x07
474 #define RF69_PACKETCONFIG1_PACKETFORMAT_VARIABLE 0x80
475 #define RF69_PACKETCONFIG1_DCFREE 0x60
476 #define RF69_PACKETCONFIG1_DCFREE_NONE 0x00
477 #define RF69_PACKETCONFIG1_DCFREE_MANCHESTER 0x20
478 #define RF69_PACKETCONFIG1_DCFREE_WHITENING 0x40
479 #define RF69_PACKETCONFIG1_DCFREE_RESERVED 0x60
480 #define RF69_PACKETCONFIG1_CRC_ON 0x10
481 #define RF69_PACKETCONFIG1_CRCAUTOCLEAROFF 0x08
482 #define RF69_PACKETCONFIG1_ADDRESSFILTERING 0x06
483 #define RF69_PACKETCONFIG1_ADDRESSFILTERING_NONE 0x00
484 #define RF69_PACKETCONFIG1_ADDRESSFILTERING_NODE 0x02
485 #define RF69_PACKETCONFIG1_ADDRESSFILTERING_NODE_BC 0x04
486 #define RF69_PACKETCONFIG1_ADDRESSFILTERING_RESERVED 0x06
489 #define RF69_FIFOTHRESH_TXSTARTCONDITION_NOTEMPTY 0x80
490 #define RF69_FIFOTHRESH_FIFOTHRESHOLD 0x7f
493 #define RF69_PACKETCONFIG2_INTERPACKETRXDELAY 0xf0
494 #define RF69_PACKETCONFIG2_RESTARTRX 0x04
495 #define RF69_PACKETCONFIG2_AUTORXRESTARTON 0x02
496 #define RF69_PACKETCONFIG2_AESON 0x01
499 #define RF69_TEMP1_TEMPMEASSTART 0x08
500 #define RF69_TEMP1_TEMPMEASRUNNING 0x04
503 #define RF69_TESTDAGC_CONTINUOUSDAGC_NORMAL 0x00
504 #define RF69_TESTDAGC_CONTINUOUSDAGC_IMPROVED_LOWBETAON 0x20
505 #define RF69_TESTDAGC_CONTINUOUSDAGC_IMPROVED_LOWBETAOFF 0x30
508 #define RF69_HAVE_SERIAL
510 #include <GenericSPI.h>
511 #include <HardwareSPI.h>
589 RF69(uint8_t slaveSelectPin = SS, uint8_t interrupt = 0,
GenericSPIClass *spi = &Hardware_spi);
615 void spiWrite(uint8_t reg, uint8_t val);
621 void spiBurstRead(uint8_t reg, uint8_t* dest, uint8_t len);
627 void spiBurstWrite(uint8_t reg,
const uint8_t* src, uint8_t len);
642 boolean setFrequency(
float centre,
float afcPullInRange = 0.05);
728 boolean recv(uint8_t* buf, uint8_t* len);
736 boolean send(
const uint8_t* data, uint8_t len);
780 static void printBuffer(
const char* prompt,
const uint8_t* buf, uint8_t len);
797 void setSyncWords(
const uint8_t* syncWords = NULL, uint8_t len = 0);
847 volatile uint8_t _mode;
850 uint8_t _slaveSelectPin;
855 volatile uint8_t _bufLen;
856 uint8_t _buf[RF69_MAX_MESSAGE_LEN];
859 uint8_t _thisAddress;
860 boolean _promiscuous;
864 uint8_t _rxHeaderFrom;
866 uint8_t _rxHeaderFlags;
870 uint8_t _txHeaderFrom;
872 uint8_t _txHeaderFlags;
874 volatile boolean _rxBufValid;
876 volatile boolean _txPacketSent;
878 volatile uint16_t _rxBad;
879 volatile uint16_t _rxGood;
880 volatile uint16_t _txGood;
882 volatile int8_t _lastRssi;
uint8_t mode()
Definition: RF69.cpp:376
void setHeaderFlags(uint8_t flags)
Definition: RF69.cpp:584
void setPromiscuous(boolean promiscuous)
Definition: RF69.cpp:609
boolean init()
Definition: RF69.cpp:84
void setMode(uint8_t mode)
Definition: RF69.cpp:335
FSK, No Manchester, Rb = 19.2kbs, Fd = 19.2kHz.
Definition: RF69.h:558
void readFifo()
Definition: RF69.cpp:202
void setHeaderFrom(uint8_t from)
Definition: RF69.cpp:574
void waitAvailable()
Definition: RF69.cpp:473
boolean setModemConfig(ModemConfigChoice index)
Definition: RF69.cpp:420
void setSyncWords(const uint8_t *syncWords=NULL, uint8_t len=0)
Definition: RF69.cpp:438
boolean send(const uint8_t *data, uint8_t len)
Definition: RF69.cpp:542
FSK, No Manchester, Rb = 250kbs, Fd = 250kHz.
Definition: RF69.h:562
Defines register values for a set of modem configuration registers.
Definition: RF69.h:536
uint8_t reg_19
Value for register RF69_REG_19_RXBW.
Definition: RF69.h:543
uint8_t reg_03
Value for register RF69_REG_03_BITRATEMSB.
Definition: RF69.h:539
static void isr1()
Low level interrupt service routine for RF69 connected to interrupt 1.
Definition: RF69.cpp:240
void setThisAddress(uint8_t thisAddress)
static void printBuffer(const char *prompt, const uint8_t *buf, uint8_t len)
Definition: RF69.cpp:507
void spiBurstRead(uint8_t reg, uint8_t *dest, uint8_t len)
Definition: RF69.cpp:279
GFSK, No Manchester, Rb = 38.4kbs, Fd = 38.4kHz.
Definition: RF69.h:571
GFSK, No Manchester, Rb = 55555kbs,Fd = 50kHz.
Definition: RF69.h:575
boolean recv(uint8_t *buf, uint8_t *len)
Definition: RF69.cpp:527
void setModeRx()
Definition: RF69.cpp:356
uint8_t headerFlags()
Definition: RF69.cpp:604
void waitPacketSent()
Definition: RF69.cpp:491
uint8_t reg_05
Value for register RF69_REG_05_FDEVMSB.
Definition: RF69.h:541
void setModeIdle()
Definition: RF69.cpp:347
FSK, No Manchester, Rb = 125kbs, Fd = 125kHz.
Definition: RF69.h:561
RF69(uint8_t slaveSelectPin=SS, uint8_t interrupt=0, GenericSPIClass *spi=&Hardware_spi)
Definition: RF69.cpp:67
void spiWrite(uint8_t reg, uint8_t val)
Definition: RF69.cpp:269
static void isr2()
Low level interrupt service routine for RF69 connected to interrupt 1.
Definition: RF69.cpp:245
GFSK, No Manchester, Rb = 2.4kbs, Fd = 2.4kHz.
Definition: RF69.h:567
boolean setFrequency(float centre, float afcPullInRange=0.05)
Definition: RF69.cpp:311
FSK, No Manchester, Rb = 57.6kbs, Fd = 120kHz.
Definition: RF69.h:560
uint8_t spiRead(uint8_t reg)
Definition: RF69.cpp:256
Base class for SPI interfaces.
Definition: GenericSPI.h:28
void setHeaderId(uint8_t id)
Definition: RF69.cpp:579
void setModeTx()
Definition: RF69.cpp:366
uint8_t headerId()
Definition: RF69.cpp:599
uint8_t reg_37
Value for register RF69_REG_37_PACKETCONFIG1.
Definition: RF69.h:544
FSK, No Manchester, Rb = 4.8kbs, Fd = 4.8kHz.
Definition: RF69.h:556
static void isr0()
Low level interrupt service routine for RF69 connected to interrupt 0.
Definition: RF69.cpp:235
GFSK, No Manchester, Rb = 19.2kbs, Fd = 19.2kHz.
Definition: RF69.h:570
FSK, No Manchester, Rb = 512bs, Fd = 2.5kHz for POCSAG compatibility.
Definition: RF69.h:564
uint8_t reg_04
Value for register RF69_REG_04_BITRATELSB.
Definition: RF69.h:540
void setModemRegisters(const ModemConfig *config)
Definition: RF69.cpp:411
int8_t lastRssi()
Definition: RF69.cpp:614
FSK, No Manchester, Rb = 55555kbs,Fd = 50kHz for RFM69 lib compatibility.
Definition: RF69.h:563
GFSK, No Manchester, Rb = 9.6kbs, Fd = 9.6kHz.
Definition: RF69.h:569
void setEncryptionKey(uint8_t *key=NULL)
Definition: RF69.cpp:453
int8_t rssiRead()
Definition: RF69.cpp:323
GFSK, No Manchester, Rb = 125kbs, Fd = 125kHz.
Definition: RF69.h:573
boolean available()
Definition: RF69.cpp:466
bool waitAvailableTimeout(uint16_t timeout)
Definition: RF69.cpp:482
void reset()
Definition: RF69.cpp:251
uint8_t headerTo()
Definition: RF69.cpp:589
static RF69 * _RF69ForInterrupt[]
Array of instances connected to interrupts 0 and 1.
Definition: RF69.h:845
GFSK, No Manchester, Rb = 250kbs, Fd = 250kHz.
Definition: RF69.h:574
FSK, No Manchester, Rb = 2kbs, Fd = 5kHz.
Definition: RF69.h:554
void setTxPower(int8_t power)
Definition: RF69.cpp:381
FSK, No Manchester, Rb = 2.4kbs, Fd = 2.4kHz.
Definition: RF69.h:555
void setPreambleLength(uint16_t bytes)
Definition: RF69.cpp:432
GFSK, No Manchester, Rb = 2kbs, Fd = 5kHz.
Definition: RF69.h:566
FSK, No Manchester, Rb = 9.6kbs, Fd = 9.6kHz.
Definition: RF69.h:557
ModemConfigChoice
Definition: RF69.h:552
uint8_t reg_02
Value for register RF69_REG_02_DATAMODUL.
Definition: RF69.h:538
uint8_t headerFrom()
Definition: RF69.cpp:594
uint8_t reg_06
Value for register RF69_REG_06_FDEVLSB.
Definition: RF69.h:542
Send and receive unaddressed, unreliable datagrams.
Definition: RF69.h:525
GFSK, No Manchester, Rb = 57.6kbs, Fd = 120kHz.
Definition: RF69.h:572
GFSK, No Manchester, Rb = 4.8kbs, Fd = 4.8kHz.
Definition: RF69.h:568
void spiBurstWrite(uint8_t reg, const uint8_t *src, uint8_t len)
Definition: RF69.cpp:290
FSK, No Manchester, Rb = 38.4kbs, Fd = 38.4kHz.
Definition: RF69.h:559
void handleInterrupt()
Definition: RF69.cpp:174
void setHeaderTo(uint8_t to)
Definition: RF69.cpp:569
int8_t temperatureRead()
Definition: RF69.cpp:301