RadioHead
Classes | Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
RH_RF22 Class Reference

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

#include <RH_RF22.h>

Inheritance diagram for RH_RF22:
RHSPIDriver RHGenericDriver

Classes

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

Public Types

enum  ModemConfigChoice {
  UnmodulatedCarrier = 0 , FSK_PN9_Rb2Fd5 , FSK_Rb2Fd5 , FSK_Rb2_4Fd36 ,
  FSK_Rb4_8Fd45 , FSK_Rb9_6Fd45 , FSK_Rb19_2Fd9_6 , FSK_Rb38_4Fd19_6 ,
  FSK_Rb57_6Fd28_8 , FSK_Rb125Fd125 , FSK_Rb_512Fd2_5 , FSK_Rb_512Fd4_5 ,
  GFSK_Rb2Fd5 , GFSK_Rb2_4Fd36 , GFSK_Rb4_8Fd45 , GFSK_Rb9_6Fd45 ,
  GFSK_Rb19_2Fd9_6 , GFSK_Rb38_4Fd19_6 , GFSK_Rb57_6Fd28_8 , GFSK_Rb125Fd125 ,
  OOK_Rb1_2Bw75 , OOK_Rb2_4Bw335 , OOK_Rb4_8Bw335 , OOK_Rb9_6Bw335 ,
  OOK_Rb19_2Bw335 , OOK_Rb38_4Bw335 , OOK_Rb40Bw335
}
 
enum  CRCPolynomial { CRC_CCITT = 0 , CRC_16_IBM = 1 , CRC_IEC_16 = 2 , CRC_Biacheva = 3 }
 Defines the available choices for CRC Types of permitted CRC polynomials, to be passed to setCRCPolynomial() They deliberately have the same numeric values as the crc[1:0] field of Register RH_RF22_REG_30_DATA_ACCESS_CONTROL. More...
 
- Public Types inherited from RHGenericDriver
enum  RHMode {
  RHModeInitialising = 0 , RHModeSleep , RHModeIdle , RHModeTx ,
  RHModeRx , RHModeCad
}
 Defines different operating modes for the transport hardware. More...
 

Public Member Functions

 RH_RF22 (uint8_t slaveSelectPin=SS, uint8_t interruptPin=2, RHGenericSPI &spi=hardware_spi)
 
bool init ()
 
void reset ()
 
uint8_t statusRead ()
 
uint8_t adcRead (uint8_t adcsel=RH_RF22_ADCSEL_INTERNAL_TEMPERATURE_SENSOR, uint8_t adcref=RH_RF22_ADCREF_BANDGAP_VOLTAGE, uint8_t adcgain=0, uint8_t adcoffs=0)
 
uint8_t temperatureRead (uint8_t tsrange=RH_RF22_TSRANGE_M64_64C, uint8_t tvoffs=0)
 
uint16_t wutRead ()
 
void setWutPeriod (uint16_t wtm, uint8_t wtr=0, uint8_t wtd=0)
 
bool setFrequency (float centre, float afcPullInRange=0.05)
 
bool setFHStepSize (uint8_t fhs)
 
bool setFHChannel (uint8_t fhch)
 
uint8_t rssiRead ()
 
uint8_t ezmacStatusRead ()
 
void setOpMode (uint8_t mode)
 
void setModeIdle ()
 
void setModeRx ()
 
void setModeTx ()
 
void setTxPower (uint8_t power)
 
void setModemRegisters (const ModemConfig *config)
 
bool setModemConfig (ModemConfigChoice index)
 
bool available ()
 
bool recv (uint8_t *buf, uint8_t *len)
 
bool send (const uint8_t *data, uint8_t len)
 
void setPreambleLength (uint8_t nibbles)
 
void setSyncWords (const uint8_t *syncWords, uint8_t len)
 
virtual void setPromiscuous (bool promiscuous)
 
bool setCRCPolynomial (CRCPolynomial polynomial)
 
void setGpioReversed (bool gpioReversed=false)
 
uint32_t getLastPreambleTime ()
 
uint8_t maxMessageLength ()
 
virtual bool sleep ()
 
- Public Member Functions inherited from RHSPIDriver
 RHSPIDriver (uint8_t slaveSelectPin=SS, RHGenericSPI &spi=hardware_spi)
 
bool init ()
 
uint8_t spiRead (uint8_t reg)
 
uint8_t spiWrite (uint8_t reg, uint8_t val)
 
uint8_t spiBurstRead (uint8_t reg, uint8_t *dest, uint8_t len)
 
uint8_t spiBurstWrite (uint8_t reg, const uint8_t *src, uint8_t len)
 
void setSlaveSelectPin (uint8_t slaveSelectPin)
 
void spiUsingInterrupt (uint8_t interruptNumber)
 
- Public Member Functions inherited from RHGenericDriver
 RHGenericDriver ()
 Constructor.
 
virtual ~RHGenericDriver ()
 Generic destructor to prevent warnings when objects are dynamically allocated.
 
virtual bool init ()
 
virtual bool available ()=0
 
virtual bool recv (uint8_t *buf, uint8_t *len)=0
 
virtual bool send (const uint8_t *data, uint8_t len)=0
 
virtual uint8_t maxMessageLength ()=0
 
virtual void waitAvailable (uint16_t polldelay=0)
 
virtual bool waitPacketSent ()
 
virtual bool waitPacketSent (uint16_t timeout)
 
virtual bool waitAvailableTimeout (uint16_t timeout, uint16_t polldelay=0)
 
virtual bool waitCAD ()
 
void setCADTimeout (unsigned long cad_timeout)
 
virtual bool isChannelActive ()
 
virtual void setThisAddress (uint8_t thisAddress)
 
virtual void setHeaderTo (uint8_t to)
 
virtual void setHeaderFrom (uint8_t from)
 
virtual void setHeaderId (uint8_t id)
 
virtual void setHeaderFlags (uint8_t set, uint8_t clear=RH_FLAGS_APPLICATION_SPECIFIC)
 
virtual void setPromiscuous (bool promiscuous)
 
virtual uint8_t headerTo ()
 
virtual uint8_t headerFrom ()
 
virtual uint8_t headerId ()
 
virtual uint8_t headerFlags ()
 
virtual int16_t lastRssi ()
 
virtual RHMode mode ()
 
virtual void setMode (RHMode mode)
 Sets the operating mode of the transport. More...
 
virtual bool sleep ()
 
virtual uint16_t rxBad ()
 
virtual uint16_t rxGood ()
 
virtual uint16_t txGood ()
 

Protected Member Functions

void handleInterrupt ()
 
void clearRxBuf ()
 
void clearTxBuf ()
 
bool fillTxBuf (const uint8_t *data, uint8_t len)
 
bool appendTxBuf (const uint8_t *data, uint8_t len)
 
void sendNextFragment ()
 
void readNextFragment ()
 
void resetFifos ()
 
void resetRxFifo ()
 
void resetTxFifo ()
 
virtual void handleExternalInterrupt ()
 
virtual void handleWakeupTimerInterrupt ()
 
void startTransmit ()
 
void restartTransmit ()
 
void setThisAddress (uint8_t thisAddress)
 
void setIdleMode (uint8_t idleMode)
 
- Protected Member Functions inherited from RHSPIDriver
virtual void beginTransaction ()
 
virtual void endTransaction ()
 
virtual void selectSlave ()
 
virtual void deselectSlave ()
 

Static Protected Member Functions

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

Protected Attributes

uint8_t _interruptPin
 The configured interrupt pin connected to this instance.
 
uint8_t _myInterruptIndex
 
uint8_t _idleMode
 The radio mode to use when mode is idle.
 
uint8_t _deviceType
 The device type reported by the RF22.
 
CRCPolynomial _polynomial
 The selected CRC polynomial.
 
volatile uint8_t _bufLen
 Number of octets in the receiver buffer.
 
uint8_t _buf [RH_RF22_MAX_MESSAGE_LEN]
 The receiver buffer.
 
volatile bool _rxBufValid
 True when there is a valid message in the Rx buffer.
 
volatile uint8_t _txBufSentIndex
 Index into TX buffer of the next to send chunk.
 
uint32_t _lastPreambleTime
 Time in millis since the last preamble was received (and the last time the RSSI was measured)
 
- Protected Attributes inherited from RHSPIDriver
RHGenericSPI_spi
 Reference to the RHGenericSPI instance to use to transfer data with the SPI device.
 
uint8_t _slaveSelectPin
 The pin number of the Slave Select pin that is used to select the desired device.
 
- Protected Attributes inherited from RHGenericDriver
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 int16_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.
 
volatile bool _cad
 Channel activity detected.
 
unsigned int _cad_timeout
 Channel activity timeout in ms.
 

Static Protected Attributes

static RH_RF22_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.
 

Additional Inherited Members

- Static Public Member Functions inherited from RHGenericDriver
static void printBuffer (const char *prompt, const uint8_t *buf, uint8_t len)
 

Detailed Description

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

If you have an Arduino Zero, you should note that you cannot use Pin 2 for the interrupt line (Pin 2 is for the NMI only), instead you can use any other pin (we use Pin 3) and initialise RH_RF69 like this:

// Slave Select is pin 10, interrupt is Pin 3
RH_RF22 driver(10, 3);
Driver to send and receive unaddressed, unreliable datagrams via an RF22 and compatible radio transce...
Definition: RH_RF22.h:954

If you have an ESP32 (we tested with the Geekworm EASY-KIT ESP32-B1 which has a ESP-WROOM-32 chip)

ESP32 RFM-22B
GND----------GND-\ (ground in)
SDN-/ (shutdown in)
3V3----------VCC (3.3V in)
interrupt pin GPIO15-------NIRQ (interrupt request out)
SS pin GPIO13-------NSEL (chip select in)
SCK pin GPIO18-------SCK (SPI clock in)
MOSI pin GPIO23-------SDI (SPI Data in)
MISO pin GPIO19-------SDO (SPI data out)
/--GPIO0 (GPIO0 out to control transmitter antenna TX_ANT)
\--TX_ANT (TX antenna control in) RFM22B only
/--GPIO1 (GPIO1 out to control receiver antenna RX_ANT)
\--RX_ANT (RX antenna control in) RFM22B only

and initialise like this:

RH_RF22 driver(13, 15);

You can of course use other pins for NSEL and NIRQ if you prefer.

To connect an STM32 F4 Discovery board to RF22 using Arduino and Arduino_STM32 connect the pins like this:

STM32 RFM-22B
GND----------GND-\ (ground in)
SDN-/ (shutdown in)
VDD----------VCC (3.3V in)
interrupt pin PB1----------NIRQ (interrupt request out)
SS pin PB0----------NSEL (chip select in)
SCK pin PB3----------SCK (SPI clock in)
MOSI pin PB5----------SDI (SPI Data in)
MISO pin PB4----------SDO (SPI data out)
/--GPIO0 (GPIO0 out to control transmitter antenna TX_ANT)
\--TX_ANT (TX antenna control in) RFM22B only
/--GPIO1 (GPIO1 out to control receiver antenna RX_ANT)
\--RX_ANT (RX antenna control in) RFM22B only

and initialise like this:

RH_RF22 driver(PB0, PB1);

You can of use other pins for NSEL and NIRQ if you prefer.

To connect an ATTiny Mega x16 such as AtTiny 3216 etc (running at 5V) etc RF22 using Arduino using Spencer Kondes megaTinyCore https://github.com/SpenceKonde/megaTinyCore connect the pins like this: (pin numbering based on https://github.com/SpenceKonde/megaTinyCore/blob/master/megaavr/extras/ATtiny_x16.md)

AtTiny x16 RFM-22B
GND----------GND-\ (ground in)
SDN-/ (shutdown in)
VDD----------VCC (5V in)
interrupt pin PA6----------NIRQ (interrupt request out)
SS pin PC0----------NSEL (chip select in)
SCK pin PA3----------SCK (SPI clock in)
MOSI pin PA1----------SDI (SPI Data in)
MISO pin PA2----------SDO (SPI data out)
/--GPIO0 (GPIO0 out to control transmitter antenna TX_ANT)
\--TX_ANT (TX antenna control in) RFM22B only
/--GPIO1 (GPIO1 out to control receiver antenna RX_ANT)
\--RX_ANT (RX antenna control in) RFM22B only

and initialise like this:

RH_RF22 driver(10, 2);

You can of use other pins for NSEL and NIRQ if you prefer.

For ESP8266-based ESP-12 modules. Caution: on some breakout boards we have seen labels for D4 and D5 reversed.

ESP-12 RFM-22B
GND----------GND-\ (ground in)
SDN-/ (shutdown in)
3V3----------VCC (3.3V in)
interrupt 0 pin D4-----------NIRQ (interrupt request out)
SS pin D5-----------NSEL (chip select in)
SCK pin D14----------SCK (SPI clock in)
MOSI pin D13----------SDI (SPI Data in)
MISO pin D12----------SDO (SPI data out)
/--GPIO0 (GPIO0 out to control transmitter antenna TX_ANT)
\--TX_ANT (TX antenna control in) RFM22B only
/--GPIO1 (GPIO1 out to control receiver antenna RX_ANT)
\--RX_ANT (RX antenna control in) RFM22B only

and initialise like this:

RH_RF22 driver(5, 4);

Note: It is possible to have 2 radios connected to one Arduino, provided each radio has its own SS and interrupt line (SCK, SDI and SDO are common to both 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 RF22 module may be relevant in some circumstances: RF22 modules are capable of pulling 80mA+ at full power, where Arduino's 3.3V line can give 50mA. You may need to make provision for alternate power supply for the RF22, especially if you wish to use full transmit power, and/or you have other shields demanding power. Inadequate power for the RF22 is reported to cause symptoms such as:

Caution: some RF22 breakout boards (such as the HAB-RFM22B-BOA HAB-RFM22B-BO) reportedly have the TX_ANT and RX_ANT pre-connected to GPIO0 and GPIO1 round the wrong way. You can work with this if you use setGpioReversed().

Caution: If you are using a bare RF22 module without IO level shifters, you may have difficulty connecting to a 5V arduino. The RF22 module is 3.3V and its IO pins are 3.3V not 5V. Some Arduinos (Diecimila and Uno) seem to work OK with this, and some (Mega) do not always work reliably. Your Mileage May Vary. For best result, use level shifters, or use a RF22 shield or board with level shifters built in, such as the Sparkfun RFM22 shield http://www.sparkfun.com/products/11018. You could also use a 3.3V IO Arduino such as a Pro. It is recognised that it is difficult to connect the Sparkfun RFM22 shield to a Mega, since the SPI pins on the Mega are different to other Arduinos, But it is possible, by bending the SPI pins (D10, D11, D12, D13) on the shield out of the way before plugging it in to the Mega and jumpering the shield pins to the Mega like this:

RF22 Shield Mega
D10 D53
D13 D52
D11 D51
D12 D50
Interrupts

The Driver uses interrupts to react to events in the RF22 module, such as the reception of a new packet, or the completion of transmission of a packet. The RH_RF22 interrupt service routine reads status from and writes data to the the RF22 module via the SPI interface. It is very important therefore, that if you are using the RF22 library 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.

SPI Interface

The RF22 module uses the SPI bus to communicate with the Arduino. Arduino IDE includes a hardware SPI class to communicate with SPI devices using the SPI facilities built into the Atmel chips, over the standard designated SPI pins MOSI, MISO, SCK, which are usually on Arduino pins 11, 12 and 13 respectively (or 51, 50, 52 on a Mega).

By default, the RH_RF22 Driver uses the Hardware SPI interface to communicate with the RF22 module. However, if your RF22 SPI is connected to the Arduino through non-standard pins, or the standard Hardware SPI interface will not work for you, you can instead use a bit-banged Software SPI class RHSoftwareSPI, which can be configured to work on any Arduino digital IO pins. See the documentation of RHSoftwareSPI for details.

The advantages of the Software SPI interface are that it can be used on any Arduino pins, not just the usual dedicated hardware pins. The disadvantage is that it is significantly slower then hardware. If you observe reliable behaviour with the default hardware SPI RHHardwareSPI, but unreliable behaviour with Software SPI RHSoftwareSPI, it may be due to slow CPU performance.

Initialisation example with hardware SPI

#include <RH_RF22.h>
RH_RF22 driver;
RHReliableDatagram manager(driver, CLIENT_ADDRESS);
RHDatagram subclass for sending addressed, acknowledged, retransmitted datagrams.
Definition: RHReliableDatagram.h:96

Initialisation example with software SPI

#include <RH_RF22.h>
#include <RHSoftwareSPI.h>
RH_RF22 driver(10, 2, spi);
RHReliableDatagram manager(driver, CLIENT_ADDRESS);
Encapsulate a software SPI interface.
Definition: RHSoftwareSPI.h:38
Memory

The RH_RF22 Driver requires non-trivial amounts of memory. The sample programs all compile to about 9 to 14kbytes each on Arduino, which will fit in the flash proram memory of most Arduinos. However, the RAM requirements are more critical. Most sample programs above will run on Duemilanova, but not on Diecimila. Even on Duemilanova, the RAM requirements are very close to the available memory of 2kbytes. Therefore, you should be vary sparing with RAM use in programs that use the RH_RF22 Driver on Duemilanova.

The sample RHRouter and RHMesh programs compile to about 14kbytes, and require more RAM than the others. They will not run on Duemilanova or Diecimila, but will run on Arduino Mega.

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

With an Arduino Mega, with 8 kbytes of SRAM, there is much more RAM headroom for your own elaborate programs. This library is reported to work with Arduino Pro Mini, but that has not been tested by me.

The RF22M modules use an inexpensive crystal to control the frequency synthesizer, and therfore you can expect the transmitter and receiver frequencies to be subject to the usual inaccuracies of such crystals. The RF22 contains an AFC circuit to compensate for differences in transmitter and receiver frequencies. It does this by altering the receiver frequency during reception by up to the pull-in frequency range. This RF22 library enables the AFC and by default sets the pull-in frequency range to 0.05MHz, which should be sufficient to handle most situations. However, if you observe unexplained packet losses or failure to operate correctly all the time it may be because your modules have a wider frequency difference, and you may need to set the afcPullInRange to a different value, using setFrequency();

Transmitter Power

You can control the transmitter power on the RF22 and RF23 transceivers with the RH_RF22::setTxPower() function. The argument can be any of the RH_RF22_TXPOW_* (for RFM22) or RH_RF22_RF23B_TXPOW_* (for RFM23) values. The default is RH_RF22_TXPOW_8DBM/RH_RF22_RF23B_TXPOW_1DBM . Eg:

driver.setTxPower(RH_RF22_TXPOW_2DBM);
void setTxPower(uint8_t power)
Definition: RH_RF22.cpp:541

The RF23BP has higher power capability, there are several power settings that are specific to the RF23BP only:

CAUTION: the high power settings available on the RFM23BP require significant power supply current. For example at +30dBm, the typical chip supply current is 550mA. This will overwhelm some small CPU board power regulators and USB supplies. If you use this chip at high power make sure you have an adequate supply current providing full 5V to the RFM23BP (and the CPU if required), otherwise you can expect strange behaviour like hanging, stopping, incorrect power levels, RF power amp overheating etc. You must also ensure that the RFM23BP GPIO pins are connected to the antenna switch control pins like so:

GPIO0 <-> RXON
GPIO1 <-> TXON

The RF output impedance of the RFM22BP module is 50 ohms. In our experiments we found that the most critical issue (besides a suitable power supply) is to ensure that the antenna impedance is also near 50 ohms. Connecting a simple 1/4 wavelength (ie a 17.3cm single wire) directly to the antenna output will not work at full 30dBm power, and will result in the transmitter hanging and/or the power amp overheating. Connect a proper 50 ohm impedance transmission line or antenna, and prevent RF radiation into the radio and arduino modules, in order to get full, reliable power. Our tests show that a 433MHz RFM23BP feeding a 50 ohm transmission line with a VHF discone antenna at the end results in full power output and the power amp transistor on the RFM22BP module runnning slightly warm but not hot. We recommend you use the services of a competent RF engineer when trying to use this high power module.

Note: with RFM23BP, the reported maximum possible power when operating on 3.3V is 27dBm. The BP version is an RFM23 with a PA external to the Silicon Labs radio chip.
The RFM23BP only supports the top three power settings because those three output levels from the RFM23 provide enough drive to the PA to make it saturate. Less drive and the PA will dissipate more heat. However, those three levels don't change the output power from the PA.

We have made some actual power measurements against programmed power for Sparkfun RFM22 wireless module under the following conditions:

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_RF22::GFSK_Rb125Fd125, 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_RF22::GFSK_Rb125Fd125 and a 13 octet message show about 330 messages per second transmitted.

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

Compatibility with RF22 library
The RH_RF22 driver is based on our earlier RF22 library http://www.airspayce.com/mikem/arduino/RF22 We have tried hard to be as compatible as possible with the earlier RF22 library, but there are some differences:
  • Different constructor.
  • Indexes for some modem configurations have changed (we recommend you use the symbolic names, not integer indexes).

The major difference is that under RadioHead, you are required to create 2 objects (ie RH_RF22 and a manager) instead of just one object under RF22 (ie RHMesh, RHRouter, RHReliableDatagram or RHDatagram). It may be sufficient or you to change for example:

RF22ReliableDatagram rf22(CLIENT_ADDRESS);

to:

RH_RF22 driver;
RHReliableDatagram rf22(driver, CLIENT_ADDRESS);

and any instance of RF22_MAX_MESSAGE_LEN to RH_RF22_MAX_MESSAGE_LEN

RadioHead version 1.6 changed the way the interrupt pin number is specified on Arduino and Uno32 platforms. If your code previously specifed a non-default interrupt pin number in the RH_RF22 constructor, you may need to review your code to specify the correct interrrupt pin (and not the interrupt number as before).

Works with RF22, RF23 based radio modules, and compatible chips and modules, including:

Data based on https://www.sparkfun.com/datasheets/Wireless/General/RFM22B.pdf

Overview

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

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

On transmission, the TO and FROM addresses default to 0x00, unless changed by a subclass. On reception the TO addressed is checked against the node address (defaults to 0x00) or the broadcast address (which is 0xff). The ID and FLAGS are set to 0, and not checked by this class. This permits use of the this base RH_RF22 class as an unaddressed, unreliable datagram service without the use of one the RadioHead Manager classes.

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

Details

This Driver provides an object-oriented interface for sending and receiving data messages with Hope-RF RF22 and RF23 based radio modules, and compatible chips and modules, including the RFM22B transceiver module such as this bare module: http://www.sparkfun.com/products/10153 and this shield: http://www.sparkfun.com/products/11018 and this module: http://www.hoperfusa.com/details.jsp?pid=131 and this integrated board: http://www.anarduino.com/miniwireless and RF23BP modules such as this http://www.anarduino.com/details.jsp?pid=130

The Hope-RF (http://www.hoperf.com) RFM22B (http://www.hoperf.com/rf_fsk/fsk/RFM22B.htm) is a low-cost ISM transceiver module. It supports FSK, GFSK, OOK over a wide range of frequencies and programmable data rates. Manual can be found at https://www.sparkfun.com/datasheets/Wireless/General/RFM22.PDF

This library provides functions for sending and receiving messages of up to 255 octets on any frequency supported by the RF22B, in a range of predefined data rates and frequency deviations. Frequency can be set with 312Hz precision to any frequency from 240.0MHz to 960.0MHz.

Up to 3 RF22B modules can be connected to an Arduino, 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:

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

Tested on Arduino Diecimila, Uno and Mega with arduino-0021, 1.0.5 on OpenSuSE 13.1 and avr-libc-1.6.1-1.15, cross-avr-binutils-2.19-9.1, cross-avr-gcc-4.1.3_20080612-26.5. With HopeRF RFM22 modules that appear to have RF22B chips on board:

Packet Format

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

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 'Virtual Wire' http://www.airspayce.com/mikem/arduino/VirtualWire.pdf also from the same author.

Connecting RFM-22 to Arduino

If you have the Sparkfun RFM22 Shield (https://www.sparkfun.com/products/11018) the connections described below are done for you on the shield, no changes required, just add headers and plug it in to an Arduino (but not and Arduino Mega, see below)

The physical connection between the RF22B and the Arduino requires 3.3V, the 3 x SPI pins (SCK, SDI, SDO), a Slave Select pin and an interrupt pin.

Note: some devices may need a pullup resister on the SDO line.

Note also that on the RFM22B (but not the RFM23B), it is required to control the TX_ANT and RX_ANT pins of the RFM22 in order to control the antenna connection properly. The RH_RF22 driver is configured by default so that GPIO0 and GPIO1 outputs can control TX_ANT and RX_ANT input pins respectively automatically. On RFM22, you must connect GPIO0 to TX_ANT and GPIO1 to RX_ANT for this automatic antenna switching to occur. See setGpioReversed() for more details. These connections are not required on RFM23B.

If you are using the Sparkfun RF22 shield, it will work with any 5V arduino without modification. Connect the RFM-22 module to most Arduino's like this (Caution, Arduino Mega has different pins for SPI, see below).

Arduino RFM-22B
GND----------GND-\ (ground in)
SDN-/ (shutdown in)
3V3----------VCC (3.3V in)
interrupt 0 pin D2-----------NIRQ (interrupt request out)
SS pin D10----------NSEL (chip select in)
SCK pin D13----------SCK (SPI clock in)
MOSI pin D11----------SDI (SPI Data in)
MISO pin D12----------SDO (SPI data out)
/--GPIO0 (GPIO0 out to control transmitter antenna TX_ANT)
\--TX_ANT (TX antenna control in) RFM22B only
/--GPIO1 (GPIO1 out to control receiver antenna RX_ANT)
\--RX_ANT (RX antenna control in) RFM22B only

For an Arduino Mega:

Mega RFM-22B
GND----------GND-\ (ground in)
SDN-/ (shutdown in)
3V3----------VCC (3.3V in)
interrupt 0 pin D2-----------NIRQ (interrupt request out)
SS pin D10----------NSEL (chip select in)
SCK pin D52----------SCK (SPI clock in)
MOSI pin D51----------SDI (SPI Data in)
MISO pin D50----------SDO (SPI data out)
/--GPIO0 (GPIO0 out to control transmitter antenna TX_ANT)
\--TX_ANT (TX antenna control in) RFM22B only
/--GPIO1 (GPIO1 out to control receiver antenna RX_ANT)
\--RX_ANT (RX antenna control in) RFM22B only

For Chipkit Uno32. Caution: you must also ensure jumper JP4 on the Uno32 is set to RD4

Arduino RFM-22B
GND----------GND-\ (ground in)
SDN-/ (shutdown in)
3V3----------VCC (3.3V in)
interrupt 0 pin D38----------NIRQ (interrupt request out)
SS pin D10----------NSEL (chip select in)
SCK pin D13----------SCK (SPI clock in)
MOSI pin D11----------SDI (SPI Data in)
MISO pin D12----------SDO (SPI data out)
/--GPIO0 (GPIO0 out to control transmitter antenna TX_ANT)
\--TX_ANT (TX antenna control in) RFM22B only
/--GPIO1 (GPIO1 out to control receiver antenna RX_ANT)
\--RX_ANT (RX antenna control in) RFM22B only

For Teensy 3.1

Teensy RFM-22B
GND----------GND-\ (ground in)
SDN-/ (shutdown in)
3V3----------VCC (3.3V in)
interrupt 2 pin D2-----------NIRQ (interrupt request out)
SS pin D10----------NSEL (chip select in)
SCK pin D13----------SCK (SPI clock in)
MOSI pin D11----------SDI (SPI Data in)
MISO pin D12----------SDO (SPI data out)
/--GPIO0 (GPIO0 out to control transmitter antenna TX_ANT)
\--TX_ANT (TX antenna control in) RFM22B only
/--GPIO1 (GPIO1 out to control receiver antenna RX_ANT)
\--RX_ANT (RX antenna control in) RFM22B only

For an Arduino Due (the SPI pins do not come out on the Digital pins as for normal Arduino, but only appear on the SPI header)

Due RFM-22B
GND----------GND-\ (ground in)
SDN-/ (shutdown in)
5V-----------VCC (5V in)
interrupt 0 pin D2-----------NIRQ (interrupt request out)
SS pin D10----------NSEL (chip select in)
SCK SPI pin 3----------SCK (SPI clock in)
MOSI SPI pin 4----------SDI (SPI Data in)
MISO SPI pin 1----------SDO (SPI data out)
/--GPIO0 (GPIO0 out to control transmitter antenna TX_ANT)
\--TX_ANT (TX antenna control in) RFM22B only
/--GPIO1 (GPIO1 out to control receiver antenna RX_ANT)
\--RX_ANT (RX antenna control in) RFM22B only

and use the default constructor: RH_RF22 driver; For connecting an Arduino to an RFM23BP module. Note that the antenna control pins are reversed compared to the RF22.

Arduino RFM-23BP
GND----------GND-\ (ground in)
SDN-/ (shutdown in)
5V-----------VCC (5V in)
interrupt 0 pin D2-----------NIRQ (interrupt request out)
SS pin D10----------NSEL (chip select in)
SCK pin D13----------SCK (SPI clock in)
MOSI pin D11----------SDI (SPI Data in)
MISO pin D12----------SDO (SPI data out)
/--GPIO0 (GPIO0 out to control receiver antenna RXON)
\--RXON (RX antenna control in)
/--GPIO1 (GPIO1 out to control transmitter antenna TXON)
\--TXON (TX antenna control in)

and you can then use the default constructor RH_RF22(). You can override the default settings for the SS pin and the interrupt in the RH_RF22 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).

Caution: some people have had problems with some batches of RFM23BP chips burning out their nIRQ outputs for unknown reasons when run at 5V. Some users assert that running RFM23BP with voltage dividers at 3.3V is to be preferred. We have not tested or verified either the cause or the supposed cure.

Member Enumeration Documentation

◆ CRCPolynomial

Defines the available choices for CRC Types of permitted CRC polynomials, to be passed to setCRCPolynomial() They deliberately have the same numeric values as the crc[1:0] field of Register RH_RF22_REG_30_DATA_ACCESS_CONTROL.

Enumerator
CRC_CCITT 

CCITT.

CRC_16_IBM 

CRC-16 (IBM) The default used by RH_RF22 driver.

CRC_IEC_16 

IEC-16.

CRC_Biacheva 

Biacheva.

◆ ModemConfigChoice

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).

Enumerator
UnmodulatedCarrier 

Unmodulated carrier for testing.

FSK_PN9_Rb2Fd5 

FSK, No Manchester, Rb = 2kbs, Fd = 5kHz, PN9 random modulation for testing.

FSK_Rb2Fd5 

FSK, No Manchester, Rb = 2kbs, Fd = 5kHz.

FSK_Rb2_4Fd36 

FSK, No Manchester, Rb = 2.4kbs, Fd = 36kHz.

FSK_Rb4_8Fd45 

FSK, No Manchester, Rb = 4.8kbs, Fd = 45kHz.

FSK_Rb9_6Fd45 

FSK, No Manchester, Rb = 9.6kbs, Fd = 45kHz.

FSK_Rb19_2Fd9_6 

FSK, No Manchester, Rb = 19.2kbs, Fd = 9.6kHz.

FSK_Rb38_4Fd19_6 

FSK, No Manchester, Rb = 38.4kbs, Fd = 19.6kHz.

FSK_Rb57_6Fd28_8 

FSK, No Manchester, Rb = 57.6kbs, Fd = 28.8kHz.

FSK_Rb125Fd125 

FSK, No Manchester, Rb = 125kbs, Fd = 125kHz.

FSK_Rb_512Fd2_5 

FSK, No Manchester, Rb = 512bs, Fd = 2.5kHz, for POCSAG compatibility.

FSK_Rb_512Fd4_5 

FSK, No Manchester, Rb = 512bs, Fd = 4.5kHz, for POCSAG compatibility.

GFSK_Rb2Fd5 

GFSK, No Manchester, Rb = 2kbs, Fd = 5kHz.

GFSK_Rb2_4Fd36 

GFSK, No Manchester, Rb = 2.4kbs, Fd = 36kHz.

GFSK_Rb4_8Fd45 

GFSK, No Manchester, Rb = 4.8kbs, Fd = 45kHz.

GFSK_Rb9_6Fd45 

GFSK, No Manchester, Rb = 9.6kbs, Fd = 45kHz.

GFSK_Rb19_2Fd9_6 

GFSK, No Manchester, Rb = 19.2kbs, Fd = 9.6kHz.

GFSK_Rb38_4Fd19_6 

GFSK, No Manchester, Rb = 38.4kbs, Fd = 19.6kHz.

GFSK_Rb57_6Fd28_8 

GFSK, No Manchester, Rb = 57.6kbs, Fd = 28.8kHz.

GFSK_Rb125Fd125 

GFSK, No Manchester, Rb = 125kbs, Fd = 125kHz.

OOK_Rb1_2Bw75 

OOK, No Manchester, Rb = 1.2kbs, Rx Bandwidth = 75kHz.

OOK_Rb2_4Bw335 

OOK, No Manchester, Rb = 2.4kbs, Rx Bandwidth = 335kHz.

OOK_Rb4_8Bw335 

OOK, No Manchester, Rb = 4.8kbs, Rx Bandwidth = 335kHz.

OOK_Rb9_6Bw335 

OOK, No Manchester, Rb = 9.6kbs, Rx Bandwidth = 335kHz.

OOK_Rb19_2Bw335 

OOK, No Manchester, Rb = 19.2kbs, Rx Bandwidth = 335kHz.

OOK_Rb38_4Bw335 

OOK, No Manchester, Rb = 38.4kbs, Rx Bandwidth = 335kHz.

OOK_Rb40Bw335 

OOK, No Manchester, Rb = 40kbs, Rx Bandwidth = 335kHz.

Constructor & Destructor Documentation

◆ RH_RF22()

RH_RF22::RH_RF22 ( uint8_t  slaveSelectPin = SS,
uint8_t  interruptPin = 2,
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 RH_RF22 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 RF22 NIRQ interrupt line. Defaults to pin 2, as required by sparkfun RFM22 module shields. 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

References _idleMode, _interruptPin, _myInterruptIndex, _polynomial, and CRC_16_IBM.

Member Function Documentation

◆ adcRead()

uint8_t RH_RF22::adcRead ( uint8_t  adcsel = RH_RF22_ADCSEL_INTERNAL_TEMPERATURE_SENSOR,
uint8_t  adcref = RH_RF22_ADCREF_BANDGAP_VOLTAGE,
uint8_t  adcgain = 0,
uint8_t  adcoffs = 0 
)

Reads a value from the on-chip analog-digital converter

Parameters
[in]adcselSelects the ADC input to measure. One of RH_RF22_ADCSEL_*. Defaults to the internal temperature sensor
[in]adcrefSpecifies the refernce voltage to use. One of RH_RF22_ADCREF_*. Defaults to the internal bandgap voltage.
[in]adcgainAmplifier gain selection.
[in]adcoffsAmplifier offseet (0 to 15).
Returns
The analog value. 0 to 255.

References RHSPIDriver::spiRead(), and RHSPIDriver::spiWrite().

Referenced by temperatureRead().

◆ appendTxBuf()

bool RH_RF22::appendTxBuf ( const uint8_t *  data,
uint8_t  len 
)
protected

Appends the transmitter buffer with the data of a mesage to be sent

Parameters
[in]dataArray of data bytes to be sent (0 to 255)
[in]lenNumber of data bytes in data
Returns
false if the resulting message would exceed RH_RF22_MAX_MESSAGE_LEN, else true

References _buf, and _bufLen.

Referenced by fillTxBuf().

◆ available()

bool RH_RF22::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.

References RHGenericDriver::_mode, _rxBufValid, RHGenericDriver::RHModeTx, and setModeRx().

Referenced by recv().

◆ clearRxBuf()

void RH_RF22::clearRxBuf ( )
protected

Clears the receiver buffer. Internal use only

References _bufLen, and _rxBufValid.

Referenced by handleInterrupt(), init(), and recv().

◆ clearTxBuf()

void RH_RF22::clearTxBuf ( )
protected

Clears the transmitter buffer Internal use only

References _bufLen, and _txBufSentIndex.

Referenced by fillTxBuf(), and init().

◆ ezmacStatusRead()

uint8_t RH_RF22::ezmacStatusRead ( )

Reads and returns the current EZMAC value from register RH_RF22_REG_31_EZMAC_STATUS

Returns
The current EZMAC value

References RHSPIDriver::spiRead().

◆ fillTxBuf()

bool RH_RF22::fillTxBuf ( const uint8_t *  data,
uint8_t  len 
)
protected

Fills the transmitter buffer with the data of a mesage to be sent

Parameters
[in]dataArray of data bytes to be sent (1 to 255)
[in]lenNumber of data bytes in data (> 0)
Returns
true if the message length is valid

References appendTxBuf(), and clearTxBuf().

Referenced by send().

◆ getLastPreambleTime()

uint32_t RH_RF22::getLastPreambleTime ( )

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

References _lastPreambleTime.

◆ handleExternalInterrupt()

void RH_RF22::handleExternalInterrupt ( )
protectedvirtual

This function will be called by handleInterrupt() if an RF22 external interrupt occurs. This can only happen if external interrupts are enabled in the RF22 (which they are not by default). Subclasses may override this function to get control when an RF22 external interrupt occurs.

Referenced by handleInterrupt().

◆ handleInterrupt()

void RH_RF22::handleInterrupt ( )
protected

◆ handleWakeupTimerInterrupt()

void RH_RF22::handleWakeupTimerInterrupt ( )
protectedvirtual

This function will be called by handleInterrupt() if an RF22 wakeup timer interrupt occurs. This can only happen if wakeup timer interrupts are enabled in theRF22 (which they are not by default). Subclasses may override this function to get control when an RF22 wakeup timer interrupt occurs.

Referenced by handleInterrupt().

◆ init()

bool RH_RF22::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
  • Software reset the RH_RF22 module
  • Checks the connected RH_RF22 module is either a RH_RF22_DEVICE_TYPE_RX_TRX or a RH_RF22_DEVICE_TYPE_TX
  • Attaches an interrupt handler
  • Configures the RH_RF22 module
  • Sets the frequency to 434.0 MHz
  • Sets the modem data rate to FSK_Rb2_4Fd36
    Returns
    true if everything was successful

Reimplemented from RHGenericDriver.

References _deviceForInterrupt, _deviceType, _interruptCount, _interruptPin, _myInterruptIndex, _polynomial, clearRxBuf(), clearTxBuf(), FSK_Rb2_4Fd36, RHSPIDriver::init(), isr0(), isr1(), isr2(), reset(), setFrequency(), setGpioReversed(), setModeIdle(), setModemConfig(), setPreambleLength(), setPromiscuous(), setSyncWords(), setTxPower(), RHSPIDriver::spiRead(), RHSPIDriver::spiUsingInterrupt(), and RHSPIDriver::spiWrite().

◆ maxMessageLength()

uint8_t RH_RF22::maxMessageLength ( )
virtual

The maximum message length supported by this driver

Returns
The maximum message length supported by this driver

Implements RHGenericDriver.

◆ readNextFragment()

void RH_RF22::readNextFragment ( )
protected

function to copy the next fragment from the receiver FIF) into the receiver buffer

References _buf, _bufLen, and RHSPIDriver::spiBurstRead().

Referenced by handleInterrupt().

◆ recv()

bool RH_RF22::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 the number of octets available in buf. The number be reset to the actual number of octets copied.
Returns
true if a valid message was copied to buf

Implements RHGenericDriver.

References _buf, _bufLen, available(), and clearRxBuf().

◆ reset()

void RH_RF22::reset ( )

Issues a software reset to the RH_RF22 module. Blocks for 1ms to ensure the reset is complete.

References RHSPIDriver::spiWrite().

Referenced by init().

◆ resetFifos()

void RH_RF22::resetFifos ( )
protected

Clears the RF22 Rx and Tx FIFOs Internal use only

References RHSPIDriver::spiWrite().

Referenced by handleInterrupt().

◆ resetRxFifo()

void RH_RF22::resetRxFifo ( )
protected

Clears the RF22 Rx FIFO Internal use only

References _rxBufValid, and RHSPIDriver::spiWrite().

Referenced by handleInterrupt(), and setModeTx().

◆ resetTxFifo()

void RH_RF22::resetTxFifo ( )
protected

Clears the RF22 Tx FIFO Internal use only

References RHSPIDriver::spiWrite().

◆ restartTransmit()

void RH_RF22::restartTransmit ( )
protected

ReStart the transmission of the contents of the Tx buffer after a atransmission failure

References RHGenericDriver::_mode, _txBufSentIndex, RHGenericDriver::RHModeIdle, and startTransmit().

Referenced by handleInterrupt().

◆ rssiRead()

uint8_t RH_RF22::rssiRead ( )

Reads and returns the current RSSI value from register RH_RF22_REG_26_RSSI. Caution: this is in internal units (see figure 31 of RFM22B/23B documentation), not in dBm. If you want to find the RSSI in dBm of the last received message, use lastRssi() instead.

Returns
The current RSSI value

References RHSPIDriver::spiRead().

◆ send()

bool RH_RF22::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.

References RHGenericDriver::_txHeaderFlags, RHGenericDriver::_txHeaderFrom, RHGenericDriver::_txHeaderId, RHGenericDriver::_txHeaderTo, fillTxBuf(), RHSPIDriver::spiWrite(), startTransmit(), RHGenericDriver::waitCAD(), and RHGenericDriver::waitPacketSent().

◆ sendNextFragment()

void RH_RF22::sendNextFragment ( )
protected

Internal function to load the next fragment of the current message into the transmitter FIFO Internal use only

References _buf, _bufLen, _txBufSentIndex, and RHSPIDriver::spiBurstWrite().

Referenced by handleInterrupt(), and startTransmit().

◆ setCRCPolynomial()

bool RH_RF22::setCRCPolynomial ( CRCPolynomial  polynomial)

Sets the CRC polynomial to be used to generate the CRC for both receive and transmit otherwise the default of CRC_16_IBM will be used.

Parameters
[in]polynomialOne of RH_RF22::CRCPolynomial choices CRC_*
Returns
true if polynomial is a valid option for this radio.

References _polynomial, CRC_Biacheva, and CRC_CCITT.

◆ setFHChannel()

bool RH_RF22::setFHChannel ( uint8_t  fhch)

Sets the frequncy hopping channel. Adds fhch * fhs to centre frequency

Parameters
[in]fhchThe channel number
Returns
true if the selected frquency centre + (fhch * fhs) is within range

References RHSPIDriver::spiWrite(), and statusRead().

◆ setFHStepSize()

bool RH_RF22::setFHStepSize ( uint8_t  fhs)

Sets the frequency hopping step size.

Parameters
[in]fhsFrequency Hopping step size in 10kHz increments
Returns
true if centre + (fhch * fhs) is within limits

References RHSPIDriver::spiWrite(), and statusRead().

◆ setFrequency()

bool RH_RF22::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, some versions of RH_RF22 and derivatives implemented more restricted frequency ranges.
[in]afcPullInRangeSets the AF Pull In Range in MHz. Defaults to 0.05MHz (50kHz). Range is 0.0 to 0.159375 for frequencies 240.0 to 480MHz, and 0.0 to 0.318750MHz for frequencies 480.0 to 960MHz,
Returns
true if the selected frquency centre + (fhch * fhs) is within range and the afcPullInRange is within range

References RHSPIDriver::spiWrite(), and statusRead().

Referenced by init().

◆ setGpioReversed()

void RH_RF22::setGpioReversed ( bool  gpioReversed = false)

Configures GPIO pins for reversed GPIO connections to the antenna switch. Normally on RF22 modules, GPIO0(out) is connected to TX_ANT(in) to enable tx antenna during transmit and GPIO1(out) is connected to RX_ANT(in) to enable rx antenna during receive. The RH_RF22 driver configures the GPIO pins during init() so the antenna switch works as expected. However, some RF22 modules, such as HAB-RFM22B-BOA HAB-RFM22B-BO, also Si4432 sold by Dorji.com via Tindie.com have these GPIO pins reversed, so that GPIO0 is connected to RX_ANT. Call this function with a true argument after init() and before transmitting in order to configure the module for reversed GPIO pins.

Parameters
[in]gpioReversedSet to true if your RF22 module has reversed GPIO antenna switch connections.

References RHSPIDriver::spiWrite().

Referenced by init().

◆ setIdleMode()

void RH_RF22::setIdleMode ( uint8_t  idleMode)
protected

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_RF22_XTON, but eg setIdleMode(RH_RF22_PLL) 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 the valid definitions for RH_RF22_REG_07_OPERATING_MODE

References _idleMode.

◆ setModeIdle()

void RH_RF22::setModeIdle ( )

If current mode is Rx or Tx changes it to Idle. If the transmitter or receiver is running, disables them.

References _idleMode, RHGenericDriver::_mode, RHGenericDriver::RHModeIdle, and setOpMode().

Referenced by init().

◆ setModemConfig()

bool RH_RF22::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.

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

References setModemRegisters().

Referenced by init().

◆ setModemRegisters()

void RH_RF22::setModemRegisters ( const ModemConfig config)

Sets all the registered required to configure the data modem in the RH_RF22, including the data rate, bandwidths etc. You cas use this to configure the modem with custom configuraitons if none of the canned configurations in ModemConfigChoice suit you.

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

References RH_RF22::ModemConfig::reg_1c, RH_RF22::ModemConfig::reg_1f, RH_RF22::ModemConfig::reg_20, RH_RF22::ModemConfig::reg_2c, RH_RF22::ModemConfig::reg_58, RH_RF22::ModemConfig::reg_69, RH_RF22::ModemConfig::reg_6e, RHSPIDriver::spiBurstWrite(), and RHSPIDriver::spiWrite().

Referenced by setModemConfig().

◆ setModeRx()

void RH_RF22::setModeRx ( )

If current mode is Tx or Idle, changes it to Rx. Starts the receiver in the RH_RF22.

References _idleMode, RHGenericDriver::_mode, RHGenericDriver::RHModeRx, and setOpMode().

Referenced by available(), and handleInterrupt().

◆ setModeTx()

void RH_RF22::setModeTx ( )

If current mode is Rx or Idle, changes it to Rx. Starts the transmitter in the RH_RF22.

References _idleMode, RHGenericDriver::_mode, resetRxFifo(), RHGenericDriver::RHModeTx, and setOpMode().

Referenced by startTransmit().

◆ setOpMode()

void RH_RF22::setOpMode ( uint8_t  mode)

Sets the parameters for the RH_RF22 Idle mode in register RH_RF22_REG_07_OPERATING_MODE. Idle mode is the mode the RH_RF22 will be in when not transmitting or receiving. The default idle mode is RH_RF22_XTON ie READY mode.

Parameters
[in]modeMask of mode bits, using RH_RF22_SWRES, RH_RF22_ENLBD, RH_RF22_ENWT, RH_RF22_X32KSEL, RH_RF22_PLLON, RH_RF22_XTON.

References RHGenericDriver::mode(), and RHSPIDriver::spiWrite().

Referenced by setModeIdle(), setModeRx(), setModeTx(), and sleep().

◆ setPreambleLength()

void RH_RF22::setPreambleLength ( uint8_t  nibbles)

Sets the length of the preamble in 4-bit nibbles. Caution: this should be set to the same value on all nodes in your network. Default is 8. Sets the message preamble length in RH_RF22_REG_34_PREAMBLE_LENGTH

Parameters
[in]nibblesPreamble length in nibbles of 4 bits each.

References RHSPIDriver::spiWrite().

Referenced by init().

◆ setPromiscuous()

void RH_RF22::setPromiscuous ( bool  promiscuous)
virtual

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 from RHGenericDriver.

References RHGenericDriver::setPromiscuous(), and RHSPIDriver::spiWrite().

Referenced by init().

◆ setSyncWords()

void RH_RF22::setSyncWords ( const uint8_t *  syncWords,
uint8_t  len 
)

Sets the sync words for transmit and receive in registers RH_RF22_REG_36_SYNC_WORD3 to RH_RF22_REG_39_SYNC_WORD0 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
[in]lenNumber of sync words to set, 1 to 4.

References RHSPIDriver::spiBurstWrite().

Referenced by init().

◆ setThisAddress()

void RH_RF22::setThisAddress ( uint8_t  thisAddress)
protectedvirtual

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 from RHGenericDriver.

References RHGenericDriver::setThisAddress(), and RHSPIDriver::spiWrite().

◆ setTxPower()

void RH_RF22::setTxPower ( uint8_t  power)

Sets the transmitter power output level in register RH_RF22_REG_6D_TX_POWER. Be a good neighbour and set the lowest power level you need. After init(), the power will be set to RH_RF22::RH_RF22_TXPOW_8DBM on RF22B or RH_RF22_RF23B_TXPOW_1DBM on an RF23B. The highest power available on RF22B is RH_RF22::RH_RF22_TXPOW_20DBM (20dBm). The highest power available on RF23B is RH_RF22::RH_RF22_RF23B_TXPOW_13DBM (13dBm). Higher powers are available on RF23BP (using RH_RF22_RF23BP_TXPOW_*), and then only with an adequate power supply. See comments above. Caution: In some countries you may only select certain higher power levels if you are also using frequency hopping. Make sure you are aware of the legal limitations and regulations in your region.

Parameters
[in]powerTransmitter power level, one of RH_RF22_*TXPOW_*

References RHSPIDriver::spiWrite().

Referenced by init().

◆ setWutPeriod()

void RH_RF22::setWutPeriod ( uint16_t  wtm,
uint8_t  wtr = 0,
uint8_t  wtd = 0 
)

Sets the wakeup timer period registers RH_RF22_REG_14_WAKEUP_TIMER_PERIOD1, RH_RF22_REG_15_WAKEUP_TIMER_PERIOD2 and RH_RF22_R<EG_16_WAKEUP_TIMER_PERIOD3

Parameters
[in]wtmWakeup timer mantissa value
[in]wtrWakeup timer exponent R value
[in]wtdWakeup timer exponent D value

References RHSPIDriver::spiBurstWrite().

◆ sleep()

bool RH_RF22::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.

References RHGenericDriver::_mode, RHGenericDriver::RHModeSleep, and setOpMode().

◆ startTransmit()

void RH_RF22::startTransmit ( )
protected

Start the transmission of the contents of the Tx buffer

References _bufLen, sendNextFragment(), setModeTx(), and RHSPIDriver::spiWrite().

Referenced by restartTransmit(), and send().

◆ statusRead()

uint8_t RH_RF22::statusRead ( )

Reads and returns the device status register RH_RF22_REG_02_DEVICE_STATUS

Returns
The value of the device status register

References RHSPIDriver::spiRead().

Referenced by setFHChannel(), setFHStepSize(), and setFrequency().

◆ temperatureRead()

uint8_t RH_RF22::temperatureRead ( uint8_t  tsrange = RH_RF22_TSRANGE_M64_64C,
uint8_t  tvoffs = 0 
)

Reads the on-chip temperature sensor

Parameters
[in]tsrangeSpecifies the temperature range to use. One of RH_RF22_TSRANGE_*
[in]tvoffsSpecifies the temperature value offset. This is actually signed value added to the measured temperature value
Returns
The measured temperature.

References adcRead(), and RHSPIDriver::spiWrite().

◆ wutRead()

uint16_t RH_RF22::wutRead ( )

Reads the wakeup timer value in registers RH_RF22_REG_17_WAKEUP_TIMER_VALUE1 and RH_RF22_REG_18_WAKEUP_TIMER_VALUE2

Returns
The wakeup timer value

References RHSPIDriver::spiBurstRead().

Member Data Documentation

◆ _myInterruptIndex

uint8_t RH_RF22::_myInterruptIndex
protected

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

Referenced by init(), and RH_RF22().


The documentation for this class was generated from the following files: