David Rimer / RadioHead-148
Embed: (wiki syntax)

« Back to documentation index

RH_RF69 Class Reference

Driver to send and receive unaddressed, unreliable datagrams via an RF69 and compatible radio transceiver. More...

#include <RH_RF69.h>

Inherits RHSPIDriver.

Data Structures

struct  ModemConfig
 Defines register values for a set of modem configuration registers. More...

Public Types

enum  ModemConfigChoice {
  FSK_Rb2Fd5 = 0, FSK_Rb2_4Fd4_8, FSK_Rb4_8Fd9_6, FSK_Rb9_6Fd19_2,
  FSK_Rb19_2Fd38_4, FSK_Rb38_4Fd76_8, FSK_Rb57_6Fd120, FSK_Rb125Fd125,
  FSK_Rb250Fd250, FSK_Rb55555Fd50, GFSK_Rb2Fd5, GFSK_Rb2_4Fd4_8,
  GFSK_Rb4_8Fd9_6, GFSK_Rb9_6Fd19_2, GFSK_Rb19_2Fd38_4, GFSK_Rb38_4Fd76_8,
  GFSK_Rb57_6Fd120, GFSK_Rb125Fd125, GFSK_Rb250Fd250, GFSK_Rb55555Fd50,
  OOK_Rb1Bw1, OOK_Rb1_2Bw75, OOK_Rb2_4Bw4_8, OOK_Rb4_8Bw9_6,
  OOK_Rb9_6Bw19_2, OOK_Rb19_2Bw38_4, OOK_Rb32Bw64
}
 

Choices for setModemConfig() for a selected subset of common modulation types, and data rates.

More...
enum  RHMode {
  RHModeInitialising = 0, RHModeSleep, RHModeIdle, RHModeTx,
  RHModeRx
}
 

Defines different operating modes for the transport hardware.

More...

Public Member Functions

 RH_RF69 (PINS slaveSelectPin, PINS interruptPin, RHGenericSPI &spi=hardware_spi)
 Constructor.
bool init ()
 Initialises this instance and the radio module connected to it.
int8_t temperatureRead ()
 Reads the on-chip temperature sensor.
bool setFrequency (float centre, float afcPullInRange=0.05)
 Sets the transmitter and receiver centre frequency.
int8_t rssiRead ()
 Reads and returns the current RSSI value.
void setOpMode (uint8_t mode)
 Sets the parameters for the RF69 OPMODE.
void setModeIdle ()
 If current mode is Rx or Tx changes it to Idle.
void setModeRx ()
 If current mode is Tx or Idle, changes it to Rx.
void setModeTx ()
 If current mode is Rx or Idle, changes it to Rx.
void setTxPower (int8_t power)
 Sets the transmitter power output level.
void setModemRegisters (const ModemConfig *config)
 Sets all the registers required to configure the data modem in the RF69, including the data rate, bandwidths etc.
bool setModemConfig (ModemConfigChoice index)
 Select one of the predefined modem configurations.
bool available ()
 Starts the receiver and checks whether a received message is available.
bool recv (uint8_t *buf, uint8_t *len)
 Turns the receiver on if it not already on.
bool send (const uint8_t *data, uint8_t len)
 Waits until any previous transmit packet is finished being transmitted with waitPacketSent().
void setPreambleLength (uint16_t bytes)
 Sets the length of the preamble in bytes.
void setSyncWords (const uint8_t *syncWords=NULL, uint8_t len=0)
 Sets the sync words for transmit and receive Caution: SyncWords should be set to the same value on all nodes in your network.
void setEncryptionKey (uint8_t *key=NULL)
 Enables AES encryption and sets the AES encryption key, used to encrypt and decrypt all messages.
uint32_t getLastPreambleTime ()
 Returns the time in millis since the most recent preamble was received, and when the most recent RSSI measurement was made.
uint8_t maxMessageLength ()
 The maximum message length supported by this driver.
bool printRegister (uint8_t reg)
 Prints the value of a single register to the Serial device if RH_HAVE_SERIAL is defined for the current platform For debugging/testing only.
bool printRegisters ()
 Prints the value of all the RF69 registers to the Serial device if RH_HAVE_SERIAL is defined for the current platform For debugging/testing only.
void setIdleMode (uint8_t idleMode)
 Sets the radio operating mode for the case when the driver is idle (ie not transmitting or receiving), allowing you to control the idle mode power requirements at the expense of slower transitions to transmit and receive modes.
virtual bool sleep ()
 Sets the radio into low-power sleep mode.
uint8_t spiRead (uint8_t reg)
 Reads a single register from the SPI device.
uint8_t spiWrite (uint8_t reg, uint8_t val)
 Writes a single byte to the SPI device.
uint8_t spiBurstRead (uint8_t reg, uint8_t *dest, uint8_t len)
 Reads a number of consecutive registers from the SPI device using burst read mode.
uint8_t spiBurstWrite (uint8_t reg, const uint8_t *src, uint8_t len)
 Write a number of consecutive registers using burst write mode.
virtual void waitAvailable ()
 Starts the receiver and blocks until a valid received message is available.
virtual bool waitPacketSent ()
 Blocks until the transmitter is no longer transmitting.
virtual bool waitPacketSent (uint16_t timeout)
 Blocks until the transmitter is no longer transmitting.
virtual bool waitAvailableTimeout (uint16_t timeout)
 Starts the receiver and blocks until a received message is available or a timeout.
virtual void setThisAddress (uint8_t thisAddress)
 Sets the address of this node.
virtual void setHeaderTo (uint8_t to)
 Sets the TO header to be sent in all subsequent messages.
virtual void setHeaderFrom (uint8_t from)
 Sets the FROM header to be sent in all subsequent messages.
virtual void setHeaderId (uint8_t id)
 Sets the ID header to be sent in all subsequent messages.
virtual void setHeaderFlags (uint8_t set, uint8_t clear=RH_FLAGS_APPLICATION_SPECIFIC)
 Sets and clears bits in the FLAGS header to be sent in all subsequent messages First it clears he FLAGS according to the clear argument, then sets the flags according to the set argument.
virtual void setPromiscuous (bool promiscuous)
 Tells the receiver to accept messages with any TO address, not just messages addressed to thisAddress or the broadcast address.
virtual uint8_t headerTo ()
 Returns the TO header of the last received message.
virtual uint8_t headerFrom ()
 Returns the FROM header of the last received message.
virtual uint8_t headerId ()
 Returns the ID header of the last received message.
virtual uint8_t headerFlags ()
 Returns the FLAGS header of the last received message.
int8_t lastRssi ()
 Returns the most recent RSSI (Receiver Signal Strength Indicator).
RHMode mode ()
 Returns the operating mode of the library.
void setMode (RHMode mode)
 Sets the operating mode of the transport.
uint16_t rxBad ()
 Returns the count of the number of bad received packets (ie packets with bad lengths, checksum etc) which were rejected and not delivered to the application.
uint16_t rxGood ()
 Returns the count of the number of good received packets.
uint16_t txGood ()
 Returns the count of the number of packets successfully transmitted (though not necessarily received by the destination)

Static Public Member Functions

static void printBuffer (const char *prompt, const uint8_t *buf, uint8_t len)
 Prints a data buffer in HEX.

Protected Member Functions

void handleInterrupt ()
 This is a low level function to handle the interrupts for one instance of RF69.
void readFifo ()
 Low level function to read the FIFO and put the received data into the receive buffer Should not need to be called by user code.

Static Protected Member Functions

static void isr0 ()
 Low level interrupt service routine for RF69 connected to interrupt 0.
static void isr1 ()
 Low level interrupt service routine for RF69 connected to interrupt 1.
static void isr2 ()
 Low level interrupt service routine for RF69 connected to interrupt 1.

Protected Attributes

InterruptIn _interruptPin
 The configured interrupt pin connected to this instance.
uint8_t _interruptPin
 The configured interrupt pin connected to this instance.
uint8_t _myInterruptIndex
 The index into _deviceForInterrupt[] for this device (if an interrupt is already allocated) else 0xff.
uint8_t _idleMode
 The radio OP mode to use when mode is RHModeIdle.
uint8_t _deviceType
 The reported device type.
int8_t _power
 The selected output power in dBm.
volatile uint8_t _bufLen
 The message length in _buf.
uint8_t _buf [RH_RF69_MAX_MESSAGE_LEN]
 Array of octets of teh last received message or the next to transmit message.
volatile bool _rxBufValid
 True when there is a valid message in the Rx buffer.
uint32_t _lastPreambleTime
 Time in millis since the last preamble was received (and the last time the RSSI was measured)
RHGenericSPI_spi
 Reference to the RHGenericSPI instance to use to trasnfer data with teh SPI device.
DigitalOut _slaveSelectPin
 The pin number of the Slave Selct pin that is used to select the desired device.
volatile RHMode _mode
 The current transport operating mode.
uint8_t _thisAddress
 This node id.
bool _promiscuous
 Whether the transport is in promiscuous mode.
volatile uint8_t _rxHeaderTo
 TO header in the last received mesasge.
volatile uint8_t _rxHeaderFrom
 FROM header in the last received mesasge.
volatile uint8_t _rxHeaderId
 ID header in the last received mesasge.
volatile uint8_t _rxHeaderFlags
 FLAGS header in the last received mesasge.
uint8_t _txHeaderTo
 TO header to send in all messages.
uint8_t _txHeaderFrom
 FROM header to send in all messages.
uint8_t _txHeaderId
 ID header to send in all messages.
uint8_t _txHeaderFlags
 FLAGS header to send in all messages.
volatile int8_t _lastRssi
 The value of the last received RSSI value, in some transport specific units.
volatile uint16_t _rxBad
 Count of the number of bad messages (eg bad checksum etc) received.
volatile uint16_t _rxGood
 Count of the number of successfully transmitted messaged.
volatile uint16_t _txGood
 Count of the number of bad messages (correct checksum etc) received.

Static Protected Attributes

static RH_RF69_deviceForInterrupt [] = {0, 0, 0}
 Array of instances connected to interrupts 0 and 1.
static uint8_t _interruptCount = 0
 Index of next interrupt number to use in _deviceForInterrupt.

Detailed Description

Driver to send and receive unaddressed, unreliable datagrams via an RF69 and compatible radio transceiver.

Works with

Overview

This class provides basic functions for sending and receiving unaddressed, unreliable datagrams of arbitrary length to 64 octets per packet.

Manager classes may use this class to implement reliable, addressed datagrams and streams, mesh routers, repeaters, translators etc.

Naturally, for any 2 radios to communicate that must be configured to use the same frequency and modulation scheme.

This Driver provides an object-oriented interface for sending and receiving data messages with Hope-RF RF69B and compatible radio modules, such as the RFM69 module.

The Hope-RF (http://www.hoperf.com) RF69 is a low-cost ISM transceiver chip. It supports FSK, GFSK, OOK over a wide range of frequencies and programmable data rates. It also suports AES encryption of up to 64 octets of payload It is available prepackaged on modules such as the RFM69W. And such modules can be prepacked on processor boards such as the Moteino from LowPowerLabs (which is what we used to develop the RH_RF69 driver)

This Driver provides functions for sending and receiving messages of up to 60 octets on any frequency supported by the RF69, in a range of predefined data rates and frequency deviations. Frequency can be set with 61Hz precision to any frequency from 240.0MHz to 960.0MHz. Caution: most modules only support a more limited range of frequencies due to antenna tuning.

Up to 2 RF69B modules can be connected to an Arduino (3 on a Mega), permitting the construction of translators and frequency changers, etc.

The following modulation types are suppported with a range of modem configurations for common data rates and frequency deviations:

  • GFSK Gaussian Frequency Shift Keying
  • FSK Frequency Shift Keying

Support for other RF69 features such as on-chip temperature measurement, transmitter power control etc is also provided.

Tested on USB-Moteino with arduino-1.0.5 on OpenSuSE 13.1

Packet Format

All messages sent and received by this RH_RF69 Driver conform to this packet format:

  • 4 octets PREAMBLE
  • 2 octets SYNC 0x2d, 0xd4 (configurable, so you can use this as a network filter)
  • 1 octet RH_RF69 payload length
  • 4 octets HEADER: (TO, FROM, ID, FLAGS)
  • 0 to 60 octets DATA
  • 2 octets CRC computed with CRC16(IBM), computed on HEADER and DATA

For technical reasons, the message format is not protocol compatible with the 'HopeRF Radio Transceiver Message Library for Arduino' http://www.airspayce.com/mikem/arduino/HopeRF from the same author. Nor is it compatible with messages sent by 'Virtual Wire' http://www.airspayce.com/mikem/arduino/VirtualWire.pdf also from the same author. Nor is it compatible with messages sent by 'RF22' http://www.airspayce.com/mikem/arduino/RF22 also from the same author.

Connecting RFM-69 to Arduino

We tested with Moteino, which is an Arduino Uno compatible with the RFM69W module on-board. Therefore it needs no connections other than the USB programming connection and an antenna to make it work.

If you have a bare RFM69W that you want to connect to an Arduino, you might use these connections (untested): CAUTION: you must use a 3.3V type Arduino, otherwise you will also need voltage level shifters between the Arduino and the RFM69. CAUTION, you must also ensure you connect an antenna

                 Arduino      RFM69W
                 GND----------GND   (ground in)
                 3V3----------3.3V  (3.3V in)
 interrupt 0 pin D2-----------DIO0  (interrupt request out)
          SS pin D10----------NSS   (chip select in)
         SCK pin D13----------SCK   (SPI clock in)
        MOSI pin D11----------MOSI  (SPI Data in)
        MISO pin D12----------MISO  (SPI Data out)

With these connections, you can then use the default constructor RH_RF69(). You can override the default settings for the SS pin and the interrupt in the RH_RF69 constructor if you wish to connect the slave select SS to other than the normal one for your Arduino (D10 for Diecimila, Uno etc and D53 for Mega) or the interrupt request to other than pin D2 (Caution, different processors have different constraints as to the pins available for interrupts).

If you have a Teensy 3.1 and a compatible RFM69 breakout board, you will need to construct the RH_RF69 instance like this:

 RH_RF69 driver(15, 16);

If you have a MoteinoMEGA https://lowpowerlab.com/shop/moteinomega with RFM69 on board, you dont need to make any wiring connections (the RFM69 module is soldered onto the MotienoMEGA), but you must initialise the RH_RF69 constructor like this:

 RH_RF69 driver(4, 2);

Make sure you have the MoteinoMEGA core installed in your Arduino hardware folder as described in the documentation for the MoteinoMEGA.

It is possible to have 2 or more radios connected to one Arduino, provided each radio has its own SS and interrupt line (SCK, SDI and SDO are common to all radios)

Caution: on some Arduinos such as the Mega 2560, if you set the slave select pin to be other than the usual SS pin (D53 on Mega 2560), you may need to set the usual SS pin to be an output to force the Arduino into SPI master mode.

Caution: Power supply requirements of the RF69 module may be relevant in some circumstances: RF69 modules are capable of pulling 45mA+ at full power, where Arduino's 3.3V line can give 50mA. You may need to make provision for alternate power supply for the RF69, especially if you wish to use full transmit power, and/or you have other shields demanding power. Inadequate power for the RF69 is likely to cause symptoms such as: -reset's/bootups terminate with "init failed" messages -random termination of communication after 5-30 packets sent/received -"fake ok" state, where initialization passes fluently, but communication doesn't happen -shields hang Arduino boards, especially during the flashing

Interrupts

The RH_RF69 driver uses interrupts to react to events in the RF69 module, such as the reception of a new packet, or the completion of transmission of a packet. The RH_RF69 driver interrupt service routine reads status from and writes data to the the RF69 module via the SPI interface. It is very important therefore, that if you are using the RH_RF69 driver with another SPI based deviced, that you disable interrupts while you transfer data to and from that other device. Use cli() to disable interrupts and sei() to reenable them.

Memory

The RH_RF69 driver requires non-trivial amounts of memory. The sample programs above all compile to about 8kbytes each, which will fit in the flash proram memory of most Arduinos. However, the RAM requirements are more critical. Therefore, you should be vary sparing with RAM use in programs that use the RH_RF69 driver.

It is often hard to accurately identify when you are hitting RAM limits on Arduino. The symptoms can include:

  • Mysterious crashes and restarts
  • Changes in behaviour when seemingly unrelated changes are made (such as adding print() statements)
  • Hanging
  • Output from Serial.print() not appearing
Automatic Frequency Control (AFC)

The RF69 module is configured by the RH_RF69 driver to always use AFC.

Transmitter Power

You can control the transmitter power on the RF69 transceiver with the RH_RF69::setTxPower() function. The argument can be any of -18 to +13 (for RF69W) or -14 to 20 (for RF69HW) The default is 13. Eg:

 driver.setTxPower(-5);

We have made some actual power measurements against programmed power for Moteino (with RF69W)

  • Moteino (with RF69W), USB power
  • 10cm RG58C/U soldered direct to RFM69 module ANT and GND
  • bnc connecteor
  • 12dB attenuator
  • BNC-SMA adapter
  • MiniKits AD8307 HF/VHF Power Head (calibrated against Rohde&Schwartz 806.2020 test set)
  • Tektronix TDS220 scope to measure the Vout from power head
     Program power           Measured Power
        dBm                         dBm
        -18                         -17
        -16                         -16
        -14                         -14
        -12                         -12
        -10                         -9
        -8                          -7
        -6                          -4
        -4                          -3
        -2                          -2
        0                           0.2
        2                           3
        4                           5
        6                           7
        8                           10
        10                          13
        12                          14
        13                          15
        14                         -51
        20                         -51
    
    We have also made some actual power measurements against programmed power for Anarduino MiniWireless with RFM69-HW Anarduino MiniWireless (with RFM69-HW), USB power
  • 10cm RG58C/U soldered direct to RFM69 module ANT and GND
  • bnc connecteor
  • 2x12dB attenuators
  • BNC-SMA adapter
  • MiniKits AD8307 HF/VHF Power Head (calibrated against Rohde&Schwartz 806.2020 test set)
  • Tektronix TDS220 scope to measure the Vout from power head
     Program power           Measured Power
        dBm                         dBm
        -18                         no measurable output
        0                           no measurable output
        13                          no measurable output
        14                          11
        15                          12
        16                          12.4
        17                          14
        18                          15
        19                          15.8
        20                          17
    
    (Caution: we dont claim laboratory accuracy for these measurements) You would not expect to get anywhere near these powers to air with a simple 1/4 wavelength wire antenna. Caution: although the RFM69 appears to have a PC antenna on board, you will get much better power and range even with just a 1/4 wave wire antenna.
Performance

Some simple speed performance tests have been conducted. In general packet transmission rate will be limited by the modulation scheme. Also, if your code does any slow operations like Serial printing it will also limit performance. We disabled any printing in the tests below. We tested with RH_RF69::GFSK_Rb250Fd250, which is probably the fastest scheme available. We tested with a 13 octet message length, over a very short distance of 10cm.

Transmission (no reply) tests with modulation RH_RF69::GFSK_Rb250Fd250 and a 13 octet message show about 152 messages per second transmitted and received.

Transmit-and-wait-for-a-reply tests with modulation RH_RF69::GFSK_Rb250Fd250 and a 13 octet message (send and receive) show about 68 round trips per second.

Definition at line 543 of file RH_RF69.h.


Member Enumeration Documentation

Choices for setModemConfig() for a selected subset of common modulation types, and data rates.

If you need another configuration, use the register calculator. and call setModemRegisters() with your desired settings. These are indexes into MODEM_CONFIG_TABLE. We strongly recommend you use these symbolic definitions and not their integer equivalents: its possible that new values will be introduced in later versions (though we will try to avoid it). CAUTION: some of these configurations do not work corectly and are marked as such.

Enumerator:
FSK_Rb2Fd5 

FSK, Whitening, Rb = 2kbs, Fd = 5kHz.

FSK_Rb2_4Fd4_8 

FSK, Whitening, Rb = 2.4kbs, Fd = 4.8kHz.

FSK_Rb4_8Fd9_6 

FSK, Whitening, Rb = 4.8kbs, Fd = 9.6kHz.

FSK_Rb9_6Fd19_2 

FSK, Whitening, Rb = 9.6kbs, Fd = 19.2kHz.

FSK_Rb19_2Fd38_4 

FSK, Whitening, Rb = 19.2kbs, Fd = 38.4kHz.

FSK_Rb38_4Fd76_8 

FSK, Whitening, Rb = 38.4kbs, Fd = 76.8kHz.

FSK_Rb57_6Fd120 

FSK, Whitening, Rb = 57.6kbs, Fd = 120kHz.

FSK_Rb125Fd125 

FSK, Whitening, Rb = 125kbs, Fd = 125kHz.

FSK_Rb250Fd250 

FSK, Whitening, Rb = 250kbs, Fd = 250kHz.

FSK_Rb55555Fd50 

FSK, Whitening, Rb = 55555kbs,Fd = 50kHz for RFM69 lib compatibility.

GFSK_Rb2Fd5 

GFSK, Whitening, Rb = 2kbs, Fd = 5kHz.

GFSK_Rb2_4Fd4_8 

GFSK, Whitening, Rb = 2.4kbs, Fd = 4.8kHz.

GFSK_Rb4_8Fd9_6 

GFSK, Whitening, Rb = 4.8kbs, Fd = 9.6kHz.

GFSK_Rb9_6Fd19_2 

GFSK, Whitening, Rb = 9.6kbs, Fd = 19.2kHz.

GFSK_Rb19_2Fd38_4 

GFSK, Whitening, Rb = 19.2kbs, Fd = 38.4kHz.

GFSK_Rb38_4Fd76_8 

GFSK, Whitening, Rb = 38.4kbs, Fd = 76.8kHz.

GFSK_Rb57_6Fd120 

GFSK, Whitening, Rb = 57.6kbs, Fd = 120kHz.

GFSK_Rb125Fd125 

GFSK, Whitening, Rb = 125kbs, Fd = 125kHz.

GFSK_Rb250Fd250 

GFSK, Whitening, Rb = 250kbs, Fd = 250kHz.

GFSK_Rb55555Fd50 

GFSK, Whitening, Rb = 55555kbs,Fd = 50kHz.

OOK_Rb1Bw1 

OOK, Whitening, Rb = 1kbs, Rx Bandwidth = 1kHz.

OOK_Rb1_2Bw75 

OOK, Whitening, Rb = 1.2kbs, Rx Bandwidth = 75kHz.

OOK_Rb2_4Bw4_8 

OOK, Whitening, Rb = 2.4kbs, Rx Bandwidth = 4.8kHz.

OOK_Rb4_8Bw9_6 

OOK, Whitening, Rb = 4.8kbs, Rx Bandwidth = 9.6kHz.

OOK_Rb9_6Bw19_2 

OOK, Whitening, Rb = 9.6kbs, Rx Bandwidth = 19.2kHz.

OOK_Rb19_2Bw38_4 

OOK, Whitening, Rb = 19.2kbs, Rx Bandwidth = 38.4kHz.

OOK_Rb32Bw64 

OOK, Whitening, Rb = 32kbs, Rx Bandwidth = 64kHz.

Definition at line 574 of file RH_RF69.h.

enum RHMode [inherited]

Defines different operating modes for the transport hardware.

These are the different values that can be adopted by the _mode variable and returned by the mode() member function,

Enumerator:
RHModeInitialising 

Transport is initialising. Initial default value until init() is called..

RHModeSleep 

Transport hardware is in low power sleep mode (if supported)

RHModeIdle 

Transport is idle.

RHModeTx 

Transport is in the process of transmitting a message.

RHModeRx 

Transport is in the process of receiving a message.

Definition at line 45 of file RHGenericDriver.h.


Constructor & Destructor Documentation

RH_RF69 ( PINS  slaveSelectPin,
PINS  interruptPin,
RHGenericSPI spi = hardware_spi 
)

Constructor.

You can have multiple instances, but each instance must have its own interrupt and slave select pin. After constructing, you must call init() to initialise the interface and the radio module. A maximum of 3 instances can co-exist on one processor, provided there are sufficient distinct interrupt lines, one for each instance.

Parameters:
[in]slaveSelectPinthe Arduino pin number of the output to use to select the RF69 before accessing it. Defaults to the normal SS pin for your Arduino (D10 for Diecimila, Uno etc, D53 for Mega, D10 for Maple)
[in]interruptPinThe interrupt Pin number that is connected to the RF69 DIO0 interrupt line. Defaults to pin 2. Caution: You must specify an interrupt capable pin. On many Arduino boards, there are limitations as to which pins may be used as interrupts. On Leonardo pins 0, 1, 2 or 3. On Mega2560 pins 2, 3, 18, 19, 20, 21. On Due and Teensy, any digital pin. On other Arduinos pins 2 or 3. See http://arduino.cc/en/Reference/attachInterrupt for more details. On Chipkit Uno32, pins 38, 2, 7, 8, 35. On other boards, any digital pin may be used.
[in]spiPointer to the SPI interface object to use. Defaults to the standard Arduino hardware SPI interface

Definition at line 86 of file RH_RF69.cpp.


Member Function Documentation

bool available (  ) [virtual]

Starts the receiver and checks whether a received message is available.

This can be called multiple times in a timeout loop

Returns:
true if a complete, valid message has been received and is able to be retrieved by recv()

Implements RHGenericDriver.

Definition at line 483 of file RH_RF69.cpp.

uint32_t getLastPreambleTime (  )

Returns the time in millis since the most recent preamble was received, and when the most recent RSSI measurement was made.

void handleInterrupt (  ) [protected]

This is a low level function to handle the interrupts for one instance of RF69.

Called automatically by isr*() Should not need to be called by user code.

Definition at line 212 of file RH_RF69.cpp.

uint8_t headerFlags (  ) [virtual, inherited]

Returns the FLAGS header of the last received message.

Returns:
The FLAGS header

Definition at line 119 of file RHGenericDriver.cpp.

uint8_t headerFrom (  ) [virtual, inherited]

Returns the FROM header of the last received message.

Returns:
The FROM header

Definition at line 109 of file RHGenericDriver.cpp.

uint8_t headerId (  ) [virtual, inherited]

Returns the ID header of the last received message.

Returns:
The ID header

Definition at line 114 of file RHGenericDriver.cpp.

uint8_t headerTo (  ) [virtual, inherited]

Returns the TO header of the last received message.

Returns:
The TO header

Definition at line 104 of file RHGenericDriver.cpp.

bool init (  ) [virtual]

Initialises this instance and the radio module connected to it.

The following steps are taken:

  • Initialise the slave select pin and the SPI interface library
  • Checks the connected RF69 module can be communicated
  • Attaches an interrupt handler
  • Configures the RF69 module
  • Sets the frequency to 434.0 MHz
  • Sets the modem data rate to FSK_Rb2Fd5
    Returns:
    true if everything was successful

Reimplemented from RHSPIDriver.

Definition at line 100 of file RH_RF69.cpp.

void isr0 (  ) [static, protected]

Low level interrupt service routine for RF69 connected to interrupt 0.

Definition at line 276 of file RH_RF69.cpp.

void isr1 (  ) [static, protected]

Low level interrupt service routine for RF69 connected to interrupt 1.

Definition at line 281 of file RH_RF69.cpp.

void isr2 (  ) [static, protected]

Low level interrupt service routine for RF69 connected to interrupt 1.

Definition at line 286 of file RH_RF69.cpp.

int8_t lastRssi (  ) [inherited]

Returns the most recent RSSI (Receiver Signal Strength Indicator).

Usually it is the RSSI of the last received message, which is measured when the preamble is received. If you called readRssi() more recently, it will return that more recent value.

Returns:
The most recent RSSI measurement in dBm.

Definition at line 124 of file RHGenericDriver.cpp.

uint8_t maxMessageLength (  ) [virtual]

The maximum message length supported by this driver.

Returns:
The maximum message length supported by this driver

Implements RHGenericDriver.

Definition at line 536 of file RH_RF69.cpp.

RHGenericDriver::RHMode mode (  ) [inherited]

Returns the operating mode of the library.

Returns:
the current mode, one of RF69_MODE_*

Definition at line 129 of file RHGenericDriver.cpp.

void printBuffer ( const char *  prompt,
const uint8_t *  buf,
uint8_t  len 
) [static, inherited]

Prints a data buffer in HEX.

For diagnostic use

Parameters:
[in]promptstring to preface the print
[in]bufLocation of the buffer to print
[in]lenLength of the buffer in octets.

Definition at line 145 of file RHGenericDriver.cpp.

bool printRegister ( uint8_t  reg )

Prints the value of a single register to the Serial device if RH_HAVE_SERIAL is defined for the current platform For debugging/testing only.

Returns:
true if successful

Definition at line 541 of file RH_RF69.cpp.

bool printRegisters (  )

Prints the value of all the RF69 registers to the Serial device if RH_HAVE_SERIAL is defined for the current platform For debugging/testing only.

Returns:
true if successful

Definition at line 551 of file RH_RF69.cpp.

void readFifo (  ) [protected]

Low level function to read the FIFO and put the received data into the receive buffer Should not need to be called by user code.

Definition at line 242 of file RH_RF69.cpp.

bool recv ( uint8_t *  buf,
uint8_t *  len 
) [virtual]

Turns the receiver on if it not already on.

If there is a valid message available, copy it to buf and return true else return false. If a message is copied, *len is set to the length (Caution, 0 length messages are permitted). You should be sure to call this function frequently enough to not miss any messages It is recommended that you call it in your main loop.

Parameters:
[in]bufLocation to copy the received message
[in,out]lenPointer to available space in buf. Set to the actual number of octets copied.
Returns:
true if a valid message was copied to buf

Implements RHGenericDriver.

Definition at line 491 of file RH_RF69.cpp.

int8_t rssiRead (  )

Reads and returns the current RSSI value.

Causes the current signal strength to be measured and returned If you want to find the RSSI of the last received message, use lastRssi() instead.

Returns:
The current RSSI value on units of 0.5dB.

Definition at line 314 of file RH_RF69.cpp.

uint16_t rxBad (  ) [inherited]

Returns the count of the number of bad received packets (ie packets with bad lengths, checksum etc) which were rejected and not delivered to the application.

Caution: not all drivers can correctly report this count. Some underlying hardware only report good packets.

Returns:
The number of bad packets received.

Definition at line 165 of file RHGenericDriver.cpp.

uint16_t rxGood (  ) [inherited]

Returns the count of the number of good received packets.

Returns:
The number of good packets received.

Definition at line 170 of file RHGenericDriver.cpp.

bool send ( const uint8_t *  data,
uint8_t  len 
) [virtual]

Waits until any previous transmit packet is finished being transmitted with waitPacketSent().

Then loads a message into the transmitter and starts the transmitter. Note that a message length of 0 is NOT permitted.

Parameters:
[in]dataArray of data to be sent
[in]lenNumber of bytes of data to send (> 0)
Returns:
true if the message length was valid and it was correctly queued for transmit

Implements RHGenericDriver.

Definition at line 509 of file RH_RF69.cpp.

void setEncryptionKey ( uint8_t *  key = NULL )

Enables AES encryption and sets the AES encryption key, used to encrypt and decrypt all messages.

The default is disabled.

Parameters:
[in]keyThe key to use. Must be 16 bytes long. The same key must be installed in other instances of RF69, otherwise communications will not work correctly. If key is NULL, encryption is disabled.

Definition at line 470 of file RH_RF69.cpp.

bool setFrequency ( float  centre,
float  afcPullInRange = 0.05 
)

Sets the transmitter and receiver centre frequency.

Parameters:
[in]centreFrequency in MHz. 240.0 to 960.0. Caution, RF69 comes in several different frequency ranges, and setting a frequency outside that range of your radio will probably not work
[in]afcPullInRangeNot used
Returns:
true if the selected frquency centre is within range

Definition at line 302 of file RH_RF69.cpp.

void setHeaderFlags ( uint8_t  set,
uint8_t  clear = RH_FLAGS_APPLICATION_SPECIFIC 
) [virtual, inherited]

Sets and clears bits in the FLAGS header to be sent in all subsequent messages First it clears he FLAGS according to the clear argument, then sets the flags according to the set argument.

The default for clear always clears the application specific flags.

Parameters:
[in]setbitmask of bits to be set. Flags are cleared with the clear mask before being set.
[in]clearbitmask of flags to clear. Defaults to RH_FLAGS_APPLICATION_SPECIFIC which clears the application specific flags, resultiung in new application specific flags identical to the set.

Definition at line 98 of file RHGenericDriver.cpp.

void setHeaderFrom ( uint8_t  from ) [virtual, inherited]

Sets the FROM header to be sent in all subsequent messages.

Parameters:
[in]fromThe new FROM header value

Definition at line 88 of file RHGenericDriver.cpp.

void setHeaderId ( uint8_t  id ) [virtual, inherited]

Sets the ID header to be sent in all subsequent messages.

Parameters:
[in]idThe new ID header value

Definition at line 93 of file RHGenericDriver.cpp.

void setHeaderTo ( uint8_t  to ) [virtual, inherited]

Sets the TO header to be sent in all subsequent messages.

Parameters:
[in]toThe new TO header value

Definition at line 83 of file RHGenericDriver.cpp.

void setIdleMode ( uint8_t  idleMode )

Sets the radio operating mode for the case when the driver is idle (ie not transmitting or receiving), allowing you to control the idle mode power requirements at the expense of slower transitions to transmit and receive modes.

By default, the idle mode is RH_RF69_OPMODE_MODE_STDBY, but eg setIdleMode(RH_RF69_OPMODE_MODE_SLEEP) will provide a much lower idle current but slower transitions. Call this function after init().

Parameters:
[in]idleModeThe chip operating mode to use when the driver is idle. One of RH_RF69_OPMODE_*

Definition at line 95 of file RH_RF69.cpp.

void setMode ( RHMode  mode ) [inherited]

Sets the operating mode of the transport.

Definition at line 134 of file RHGenericDriver.cpp.

void setModeIdle (  )

If current mode is Rx or Tx changes it to Idle.

If the transmitter or receiver is running, disables them.

Definition at line 338 of file RH_RF69.cpp.

bool setModemConfig ( ModemConfigChoice  index )

Select one of the predefined modem configurations.

If you need a modem configuration not provided here, use setModemRegisters() with your own ModemConfig. The default after init() is RH_RF69::GFSK_Rb250Fd250.

Parameters:
[in]indexThe configuration choice.
Returns:
true if index is a valid choice.

Definition at line 437 of file RH_RF69.cpp.

void setModemRegisters ( const ModemConfig config )

Sets all the registers required to configure the data modem in the RF69, including the data rate, bandwidths etc.

You can use this to configure the modem with custom configurations if none of the canned configurations in ModemConfigChoice suit you.

Parameters:
[in]configA ModemConfig structure containing values for the modem configuration registers.

Definition at line 428 of file RH_RF69.cpp.

void setModeRx (  )

If current mode is Tx or Idle, changes it to Rx.

Starts the receiver in the RF69.

Definition at line 363 of file RH_RF69.cpp.

void setModeTx (  )

If current mode is Rx or Idle, changes it to Rx.

F Starts the transmitter in the RF69.

Definition at line 379 of file RH_RF69.cpp.

void setOpMode ( uint8_t  mode )

Sets the parameters for the RF69 OPMODE.

This is a low level device access function, and should not normally ned to be used by user code. Instead can use stModeRx(), setModeTx(), setModeIdle()

Parameters:
[in]modeRF69 OPMODE to set, one of RH_RF69_OPMODE_MODE_*.

Definition at line 326 of file RH_RF69.cpp.

void setPreambleLength ( uint16_t  bytes )

Sets the length of the preamble in bytes.

Caution: this should be set to the same value on all nodes in your network. Default is 4. Sets the message preamble length in REG_0?_PREAMBLE?SB

Parameters:
[in]bytesPreamble length in bytes.

Definition at line 449 of file RH_RF69.cpp.

void setPromiscuous ( bool  promiscuous ) [virtual, inherited]

Tells the receiver to accept messages with any TO address, not just messages addressed to thisAddress or the broadcast address.

Parameters:
[in]promiscuoustrue if you wish to receive messages with any TO address

Reimplemented in RH_RF22.

Definition at line 73 of file RHGenericDriver.cpp.

void setSyncWords ( const uint8_t *  syncWords = NULL,
uint8_t  len = 0 
)

Sets the sync words for transmit and receive Caution: SyncWords should be set to the same value on all nodes in your network.

Nodes with different SyncWords set will never receive each others messages, so different SyncWords can be used to isolate different networks from each other. Default is { 0x2d, 0xd4 }.

Parameters:
[in]syncWordsArray of sync words, 1 to 4 octets long. NULL if no sync words to be used.
[in]lenNumber of sync words to set, 1 to 4. 0 if no sync words to be used.

Definition at line 455 of file RH_RF69.cpp.

void setThisAddress ( uint8_t  thisAddress ) [virtual, inherited]

Sets the address of this node.

Defaults to 0xFF. Subclasses or the user may want to change this. This will be used to test the adddress in incoming messages. In non-promiscuous mode, only messages with a TO header the same as thisAddress or the broadcast addess (0xFF) will be accepted. In promiscuous mode, all messages will be accepted regardless of the TO header. In a conventional multinode system, all nodes will have a unique address (which you could store in EEPROM). You would normally set the header FROM address to be the same as thisAddress (though you dont have to, allowing the possibilty of address spoofing).

Parameters:
[in]thisAddressThe address of this node.

Reimplemented in RH_RF22, and RH_TCP.

Definition at line 78 of file RHGenericDriver.cpp.

void setTxPower ( int8_t  power )

Sets the transmitter power output level.

Be a good neighbour and set the lowest power level you need. Caution: legal power limits may apply in certain countries. After init(), the power will be set to 13dBm.

Parameters:
[in]powerTransmitter power level in dBm. For RF69W, valid values are from -18 to +13 (higher power settings disable the transmitter). For RF69HW, valid values are from +14 to +20. Caution: at +20dBm, duty cycle is limited to 1% and a maximum VSWR of 3:1 at the antenna port.

Definition at line 396 of file RH_RF69.cpp.

bool sleep (  ) [virtual]

Sets the radio into low-power sleep mode.

If successful, the transport will stay in sleep mode until woken by changing mode it idle, transmit or receive (eg by calling send(), recv(), available() etc) Caution: there is a time penalty as the radio takes a finite time to wake from sleep mode.

Returns:
true if sleep mode was successfully entered.

Reimplemented from RHGenericDriver.

Definition at line 353 of file RH_RF69.cpp.

uint8_t spiBurstRead ( uint8_t  reg,
uint8_t *  dest,
uint8_t  len 
) [inherited]

Reads a number of consecutive registers from the SPI device using burst read mode.

Parameters:
[in]regRegister number of the first register
[in]destArray to write the register values to. Must be at least len bytes
[in]lenNumber of bytes to read
Returns:
Some devices return a status byte during the first data transfer. This byte is returned. it may or may not be meaningfule depending on the the type of device being accessed.

Definition at line 56 of file RHSPIDriver.cpp.

uint8_t spiBurstWrite ( uint8_t  reg,
const uint8_t *  src,
uint8_t  len 
) [inherited]

Write a number of consecutive registers using burst write mode.

Parameters:
[in]regRegister number of the first register
[in]srcArray of new register values to write. Must be at least len bytes
[in]lenNumber of bytes to write
Returns:
Some devices return a status byte during the first data transfer. This byte is returned. it may or may not be meaningfule depending on the the type of device being accessed.

Definition at line 69 of file RHSPIDriver.cpp.

uint8_t spiRead ( uint8_t  reg ) [inherited]

Reads a single register from the SPI device.

Parameters:
[in]regRegister number
Returns:
The value of the register

Definition at line 32 of file RHSPIDriver.cpp.

uint8_t spiWrite ( uint8_t  reg,
uint8_t  val 
) [inherited]

Writes a single byte to the SPI device.

Parameters:
[in]regRegister number
[in]valThe value to write
Returns:
Some devices return a status byte during the first data transfer. This byte is returned. it may or may not be meaningfule depending on the the type of device being accessed.

Definition at line 44 of file RHSPIDriver.cpp.

int8_t temperatureRead (  )

Reads the on-chip temperature sensor.

The RF69 must be in Idle mode (= RF69 Standby) to measure temperature. The measurement is uncalibrated and without calibration, you can expect it to be far from correct.

Returns:
The measured temperature, in degrees C from -40 to 85 (uncalibrated)

Definition at line 292 of file RH_RF69.cpp.

uint16_t txGood (  ) [inherited]

Returns the count of the number of packets successfully transmitted (though not necessarily received by the destination)

Returns:
The number of packets successfully transmitted

Definition at line 175 of file RHGenericDriver.cpp.

void waitAvailable (  ) [virtual, inherited]

Starts the receiver and blocks until a valid received message is available.

Reimplemented in RH_TCP.

Definition at line 33 of file RHGenericDriver.cpp.

bool waitAvailableTimeout ( uint16_t  timeout ) [virtual, inherited]

Starts the receiver and blocks until a received message is available or a timeout.

Parameters:
[in]timeoutMaximum time to wait in milliseconds.
Returns:
true if a message is available

Reimplemented in RH_TCP.

Definition at line 42 of file RHGenericDriver.cpp.

bool waitPacketSent (  ) [virtual, inherited]

Blocks until the transmitter is no longer transmitting.

Reimplemented in RH_NRF24, RH_NRF51, and RH_NRF905.

Definition at line 54 of file RHGenericDriver.cpp.

bool waitPacketSent ( uint16_t  timeout ) [virtual, inherited]

Blocks until the transmitter is no longer transmitting.

or until the timeout occuers, whichever happens first

Parameters:
[in]timeoutMaximum time to wait in milliseconds.
Returns:
true if the RF22 completed transmission within the timeout period. False if it timed out.

Definition at line 61 of file RHGenericDriver.cpp.


Field Documentation

uint8_t _buf[RH_RF69_MAX_MESSAGE_LEN] [protected]

Array of octets of teh last received message or the next to transmit message.

Definition at line 837 of file RH_RF69.h.

volatile uint8_t _bufLen [protected]

The message length in _buf.

Definition at line 834 of file RH_RF69.h.

RH_RF69 * _deviceForInterrupt = {0, 0, 0} [static, protected]

Array of instances connected to interrupts 0 and 1.

Definition at line 807 of file RH_RF69.h.

uint8_t _deviceType [protected]

The reported device type.

Definition at line 828 of file RH_RF69.h.

uint8_t _idleMode [protected]

The radio OP mode to use when mode is RHModeIdle.

Definition at line 825 of file RH_RF69.h.

uint8_t _interruptCount = 0 [static, protected]

Index of next interrupt number to use in _deviceForInterrupt.

Definition at line 810 of file RH_RF69.h.

uint8_t _interruptPin [protected]

The configured interrupt pin connected to this instance.

Definition at line 817 of file RH_RF69.h.

InterruptIn _interruptPin [protected]

The configured interrupt pin connected to this instance.

Definition at line 814 of file RH_RF69.h.

uint32_t _lastPreambleTime [protected]

Time in millis since the last preamble was received (and the last time the RSSI was measured)

Definition at line 843 of file RH_RF69.h.

volatile int8_t _lastRssi [protected, inherited]

The value of the last received RSSI value, in some transport specific units.

Definition at line 249 of file RHGenericDriver.h.

volatile RHMode _mode [protected, inherited]

The current transport operating mode.

Definition at line 216 of file RHGenericDriver.h.

uint8_t _myInterruptIndex [protected]

The index into _deviceForInterrupt[] for this device (if an interrupt is already allocated) else 0xff.

Definition at line 822 of file RH_RF69.h.

int8_t _power [protected]

The selected output power in dBm.

Definition at line 831 of file RH_RF69.h.

bool _promiscuous [protected, inherited]

Whether the transport is in promiscuous mode.

Definition at line 222 of file RHGenericDriver.h.

volatile uint16_t _rxBad [protected, inherited]

Count of the number of bad messages (eg bad checksum etc) received.

Definition at line 252 of file RHGenericDriver.h.

volatile bool _rxBufValid [protected]

True when there is a valid message in the Rx buffer.

Definition at line 840 of file RH_RF69.h.

volatile uint16_t _rxGood [protected, inherited]

Count of the number of successfully transmitted messaged.

Definition at line 255 of file RHGenericDriver.h.

volatile uint8_t _rxHeaderFlags [protected, inherited]

FLAGS header in the last received mesasge.

Definition at line 234 of file RHGenericDriver.h.

volatile uint8_t _rxHeaderFrom [protected, inherited]

FROM header in the last received mesasge.

Definition at line 228 of file RHGenericDriver.h.

volatile uint8_t _rxHeaderId [protected, inherited]

ID header in the last received mesasge.

Definition at line 231 of file RHGenericDriver.h.

volatile uint8_t _rxHeaderTo [protected, inherited]

TO header in the last received mesasge.

Definition at line 225 of file RHGenericDriver.h.

DigitalOut _slaveSelectPin [protected, inherited]

The pin number of the Slave Selct pin that is used to select the desired device.

Definition at line 86 of file RHSPIDriver.h.

RHGenericSPI& _spi [protected, inherited]

Reference to the RHGenericSPI instance to use to trasnfer data with teh SPI device.

Definition at line 82 of file RHSPIDriver.h.

uint8_t _thisAddress [protected, inherited]

This node id.

Definition at line 219 of file RHGenericDriver.h.

volatile uint16_t _txGood [protected, inherited]

Count of the number of bad messages (correct checksum etc) received.

Definition at line 258 of file RHGenericDriver.h.

uint8_t _txHeaderFlags [protected, inherited]

FLAGS header to send in all messages.

Definition at line 246 of file RHGenericDriver.h.

uint8_t _txHeaderFrom [protected, inherited]

FROM header to send in all messages.

Definition at line 240 of file RHGenericDriver.h.

uint8_t _txHeaderId [protected, inherited]

ID header to send in all messages.

Definition at line 243 of file RHGenericDriver.h.

uint8_t _txHeaderTo [protected, inherited]

TO header to send in all messages.

Definition at line 237 of file RHGenericDriver.h.