RadioHead
Public Types | Public Member Functions | Protected Member Functions | List of all members
RH_NRF24 Class Reference

Send and receive unaddressed, unreliable datagrams by nRF24L01 and compatible transceivers. More...

#include <RH_NRF24.h>

Inheritance diagram for RH_NRF24:
RHNRFSPIDriver RHGenericDriver

Public Types

enum  DataRate { DataRate1Mbps = 0 , DataRate2Mbps , DataRate250kbps }
 Defines convenient values for setting data rates in setRF() More...
 
enum  TransmitPower {
  TransmitPowerm18dBm = 0 , TransmitPowerm12dBm , TransmitPowerm6dBm , TransmitPower0dBm ,
  RFM73TransmitPowerm10dBm = 0 , RFM73TransmitPowerm5dBm , RFM73TransmitPowerm0dBm , RFM73TransmitPower5dBm
}
 Convenient values for setting transmitter power in setRF() These are designed to agree with the values for RF_PWR in RH_NRF24_REG_06_RF_SETUP To be passed to setRF();. 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_NRF24 (uint8_t chipEnablePin=8, uint8_t slaveSelectPin=SS, RHGenericSPI &spi=hardware_spi)
 
bool init ()
 
uint8_t spiReadRegister (uint8_t reg)
 
uint8_t spiWriteRegister (uint8_t reg, uint8_t val)
 
uint8_t spiBurstReadRegister (uint8_t reg, uint8_t *dest, uint8_t len)
 
uint8_t spiBurstWriteRegister (uint8_t reg, uint8_t *src, uint8_t len)
 
uint8_t statusRead ()
 
bool setChannel (uint8_t channel)
 
bool setOpMode (uint8_t mode)
 
bool setNetworkAddress (uint8_t *address, uint8_t len)
 
bool setRF (DataRate data_rate, TransmitPower power)
 
void setModeIdle ()
 
void setModeRx ()
 
void setModeTx ()
 
bool send (const uint8_t *data, uint8_t len)
 
virtual bool waitPacketSent ()
 
bool isSending ()
 
bool printRegisters ()
 
bool available ()
 
bool recv (uint8_t *buf, uint8_t *len)
 
uint8_t maxMessageLength ()
 
virtual bool sleep ()
 
- Public Member Functions inherited from RHNRFSPIDriver
 RHNRFSPIDriver (uint8_t slaveSelectPin=SS, RHGenericSPI &spi=hardware_spi)
 
bool init ()
 
uint8_t spiCommand (uint8_t command)
 
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 void waitAvailable (uint16_t polldelay=0)
 
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.
 
virtual uint16_t rxBad ()
 
virtual uint16_t rxGood ()
 
virtual uint16_t txGood ()
 

Protected Member Functions

uint8_t flushTx ()
 
uint8_t flushRx ()
 
void validateRxBuf ()
 Examine the receive buffer to determine whether the message is for this node.
 
void clearRxBuf ()
 Clear our local receive buffer.
 
- Protected Member Functions inherited from RHNRFSPIDriver
virtual void beginTransaction ()
 
virtual void endTransaction ()
 Signal the end of an SPI transaction.
 

Additional Inherited Members

- Static Public Member Functions inherited from RHGenericDriver
static void printBuffer (const char *prompt, const uint8_t *buf, uint8_t len)
 
- Protected Attributes inherited from RHNRFSPIDriver
RHGenericSPI_spi
 Reference to the RHGenericSPI instance to use to trasnfer data with teh 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.
 

Detailed Description

Send and receive unaddressed, unreliable datagrams by nRF24L01 and compatible transceivers.

Supported transceivers include:

This base class provides basic functions for sending and receiving unaddressed, unreliable datagrams of arbitrary length to 28 octets per packet. Use one of the Manager classes to get addressing and acknowledgement reliability, routing, meshes etc.

The nRF24L01 (http://www.sparkfun.com/datasheets/Wireless/Nordic/nRF24L01P_Product_Specification_1_0.pdf) is a low-cost 2.4GHz ISM transceiver module. It supports a number of channel frequencies in the 2.4GHz band and a range of data rates.

This library provides functions for sending and receiving messages of up to 28 octets on any frequency supported by the nRF24L01, at a selected data rate.

Several nRF24L01 modules can be connected to an Arduino, permitting the construction of translators and frequency changers, etc.

The nRF24 transceiver is configured to use Enhanced Shockburst with no acknowledgement and no retransmits. TX_ADDR and RX_ADDR_P0 are set to the network address. If you need the low level auto-acknowledgement feature supported by this chip, you can use our original NRF24 library at http://www.airspayce.com/mikem/arduino/NRF24

Naturally, for any 2 radios to communicate that must be configured to use the same frequency and data rate, and with identical network addresses.

Example Arduino programs are included to show the main modes of use.

Packet Format

All messages sent and received by this class conform to this packet format, as specified by the nRF24L01 product specification:

Connecting nRF24L01 to Arduino

The electrical connection between the nRF24L01 and the Arduino require 3.3V, the 3 x SPI pins (SCK, SDI, SDO), a Chip Enable pin and a Slave Select pin. If you are using the Sparkfun WRL-00691 module, it has a voltage regulator on board and can be should with 5V VCC if possible. The examples below assume the Sparkfun WRL-00691 module

Connect the nRF24L01 to most Arduino's like this (Caution, Arduino Mega has different pins for SPI, see below). Use these same connections for Teensy 3.1 (use 3.3V not 5V Vcc).

Arduino Sparkfun WRL-00691
5V-----------VCC (3.3V to 7V in)
pin D8-----------CE (chip enable in)
SS pin D10----------CSN (chip select in)
SCK pin D13----------SCK (SPI clock in)
MOSI pin D11----------SDI (SPI Data in)
MISO pin D12----------SDO (SPI data out)
IRQ (Interrupt output, not connected)
GND----------GND (ground in)

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

Leonardo Sparkfun WRL-00691
5V-----------VCC (3.3V to 7V in)
pin D8-----------CE (chip enable in)
SS pin D10----------CSN (chip select in)
SCK ICSP pin 3----------SCK (SPI clock in)
MOSI ICSP pin 4----------SDI (SPI Data in)
MISO ICSP pin 1----------SDO (SPI data out)
IRQ (Interrupt output, not connected)
GND----------GND (ground in)

and initialise the NRF24 object like this to explicitly set the SS pin NRF24 nrf24(8, 10);

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). Use the same connections for Yun with 5V or 3.3V.

Due Sparkfun WRL-00691
3.3V-----------VCC (3.3V to 7V in)
pin D8-----------CE (chip enable in)
SS pin D10----------CSN (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)
IRQ (Interrupt output, not connected)
GND----------GND (ground in)

and initialise the NRF24 object with the default constructor NRF24 nrf24;

For an Arduino Mega:

Mega Sparkfun WRL-00691
5V-----------VCC (3.3V to 7V in)
pin D8-----------CE (chip enable in)
SS pin D53----------CSN (chip select in)
SCK pin D52----------SCK (SPI clock in)
MOSI pin D51----------SDI (SPI Data in)
MISO pin D50----------SDO (SPI data out)
IRQ (Interrupt output, not connected)
GND----------GND (ground in)

and you can then use the constructor RH_NRF24(8, 53).

For an Itead Studio IBoard Pro http://imall.iteadstudio.com/iboard-pro.html, connected by hardware SPI to the ITDB02 Parallel LCD Module Interface pins:

IBoard Signal=ITDB02 pin Sparkfun WRL-00691
3.3V 37-----------VCC (3.3V to 7V in)
D2 28-----------CE (chip enable in)
D29 27----------CSN (chip select in)
SCK D52 32----------SCK (SPI clock in)
MOSI D51 34----------SDI (SPI Data in)
MISO D50 30----------SDO (SPI data out)
IRQ (Interrupt output, not connected)
GND 39----------GND (ground in)

And initialise like this:

RH_NRF24 nrf24(2, 29);
Send and receive unaddressed, unreliable datagrams by nRF24L01 and compatible transceivers.
Definition RH_NRF24.h:424

For an Itead Studio IBoard Pro http://imall.iteadstudio.com/iboard-pro.html, connected by software SPI to the nRF24L01+ Module Interface pins. CAUTION: performance of software SPI is very slow and is not compatible with other modules running hardware SPI.

IBoard Signal=Module pin Sparkfun WRL-00691
3.3V 2----------VCC (3.3V to 7V in)
D12 3-----------CE (chip enable in)
D29 4----------CSN (chip select in)
D9 5----------SCK (SPI clock in)
D8 6----------SDI (SPI Data in)
D7 7----------SDO (SPI data out)
IRQ (Interrupt output, not connected)
GND 1----------GND (ground in)

And initialise like this:

#include <SPI.h>
#include <RH_NRF24.h>
#include <RHSoftwareSPI.h>
Singleton instance of the radio driver
RH_NRF24 nrf24(12, 11, spi);
void setup() {
spi.setPins(7, 8, 9);
....
Encapsulate a software SPI interface.
Definition RHSoftwareSPI.h:38

For Raspberry Pi with Sparkfun WRL-00691

Raspberry Pi P1 pin Sparkfun WRL-00691
5V 2-----------VCC (3.3V to 7V in)
GPIO25 22-----------CE (chip enable in)
GPIO8 24----------CSN (chip select in)
GPIO11 23----------SCK (SPI clock in)
GPIO10 19----------SDI (SPI Data in)
GPIO9 21----------SDO (SPI data out)
IRQ (Interrupt output, not connected)
GND 6----------GND (ground in)

and initialise like this:

RH_NRF24 nrf24(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_24);

See the example program and Makefile in examples/raspi. Requires bcm2835 library to be previously installed.

cd examples/raspi
make
sudo ./RasPiRH
You can override the default settings for the CSN and CE pins
in the NRF24() constructor if you wish to connect the slave select CSN to other than the normal one for your
Caution: on the Raspberry Pi Zero, the hardware SPI, is only connected to the
ICSP-header. So in order to use the RF, one must either connect it to the SPI-pins
of the ICSP-header or use the software SPI provided by RHSoftwareSPI.
the mapping of the SPI-Pins for each board here:
https://www.arduino.cc/en/Reference/SPI
Arduino (D10 for Diecimila, Uno etc and D53 for Mega)
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: this module has not been proved to work with Leonardo, at least without level
shifters between the nRF24 and the Leonardo. Tests seem to indicate that such level shifters would be required
with Leonardo to make it work.
It is possible to have 2 radios conected to one arduino, provided each radio has its own
CSN and CE line (SCK, SDI and SDO are common to both radios)
\par SPI Interface
You can interface to nRF24L01 with with hardware or software SPI. Use of software SPI with the RHSoftwareSPI
class depends on a fast enough processor and digitalOut() functions to achieve a high enough SPI bus frequency.
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
\code
#include <RH_NRF24.h>
RH_NRF24 driver;
RHReliableDatagram manager(driver, CLIENT_ADDRESS);
virtual RHMode mode()
Definition RHGenericDriver.cpp:165
Encapsulate a hardware SPI bus interface.
Definition RHHardwareSPI.h:21
RHDatagram subclass for sending addressed, acknowledged, retransmitted datagrams.
Definition RHReliableDatagram.h:96

Initialisation example with software SPI

#include <RH_NRF24.h>
#include <RHSoftwareSPI.h>
RH_NRF24 driver(8, 10, spi);
RHReliableDatagram manager(driver, CLIENT_ADDRESS);
Example programs

Several example programs are provided.

Radio Performance

Frequency accuracy may be debatable. For nominal frequency of 2401.000 MHz (ie channel 1), my Yaesu VR-5000 receiver indicated the center frequency for my test radios was 2401.121 MHz. Its not clear to me if the Yaesu is the source of the error, but I tend to believe it, which would make the nRF24l01 frequency out by 121kHz.

The measured power output for a nRF24L01p with PA and LNA set to 0dBm output is about 18dBm.

Radio operating strategy and defaults

The radio is enabled all the time, and switched between TX and RX modes depending on whether there is any data to send. Sending data sets the radio to TX mode. After data is sent, the radio automatically returns to Standby II mode. Calling waitAvailable() or waitAvailableTimeout() starts the radio in RX mode.

The radio is configured by default to Channel 2, 2Mbps, 0dBm power, 5 bytes address, payload width 1, CRC enabled 2 byte CRC, No Auto-Ack mode. Enhanced shockburst is used. TX and P0 are set to the Network address. Node addresses and decoding are handled with the RH_NRF24 module.

Memory

Memory usage of this class is minimal. The compiled client and server sketches are about 6000 bytes on Arduino. The reliable client and server sketches compile to about 8500 bytes on Arduino. RAM requirements are minimal.

Examples
RasPiRH.cpp.

Member Enumeration Documentation

◆ DataRate

Defines convenient values for setting data rates in setRF()

Enumerator
DataRate1Mbps 

1 Mbps

DataRate2Mbps 

2 Mbps

DataRate250kbps 

250 kbps

◆ TransmitPower

Convenient values for setting transmitter power in setRF() These are designed to agree with the values for RF_PWR in RH_NRF24_REG_06_RF_SETUP To be passed to setRF();.

Enumerator
TransmitPowerm18dBm 

On nRF24, -18 dBm.

TransmitPowerm12dBm 

On nRF24, -12 dBm.

TransmitPowerm6dBm 

On nRF24, -6 dBm.

TransmitPower0dBm 

On nRF24, 0 dBm.

RFM73TransmitPowerm10dBm 

On RFM73, -10 dBm.

RFM73TransmitPowerm5dBm 

On RFM73, -5 dBm.

RFM73TransmitPowerm0dBm 

On RFM73, 0 dBm.

RFM73TransmitPower5dBm 

On RFM73, 5 dBm. 20dBm on RFM73P-S2 ?

Constructor & Destructor Documentation

◆ RH_NRF24()

RH_NRF24::RH_NRF24 ( uint8_t  chipEnablePin = 8,
uint8_t  slaveSelectPin = SS,
RHGenericSPI spi = hardware_spi 
)

Constructor. You can have multiple instances, but each instance must have its own chip enable and slave select pin. After constructing, you must call init() to initialise the interface and the radio module

Parameters
[in]chipEnablePinthe Arduino pin to use to enable the chip for transmit/receive
[in]slaveSelectPinthe Arduino pin number of the output to use to select the NRF24 before accessing it. Defaults to the normal SS pin for your Arduino (D10 for Diecimila, Uno etc, D53 for Mega, D10 for Maple)
[in]spiPointer to the SPI interface object to use. Defaults to the standard Arduino hardware SPI interface

Member Function Documentation

◆ available()

bool RH_NRF24::available ( )
virtual

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, clearRxBuf(), flushRx(), RHGenericDriver::RHModeTx, setModeIdle(), setModeRx(), RHNRFSPIDriver::spiBurstRead(), RHNRFSPIDriver::spiRead(), spiReadRegister(), spiWriteRegister(), and validateRxBuf().

Referenced by recv().

◆ flushRx()

uint8_t RH_NRF24::flushRx ( )
protected

Flush the RX FIFOs

Returns
the value of the device status register

References RHNRFSPIDriver::spiCommand().

Referenced by available(), and init().

◆ flushTx()

uint8_t RH_NRF24::flushTx ( )
protected

Flush the TX FIFOs

Returns
the value of the device status register

References RHNRFSPIDriver::spiCommand().

Referenced by init(), and waitPacketSent().

◆ init()

bool RH_NRF24::init ( )
virtual

Initialises this instance and the radio module connected to it. The following steps are taken:g

  • Set the chip enable and chip select pins to output LOW, HIGH respectively.
  • Initialise the SPI output pins
  • Initialise the SPI interface library to 8MHz (Hint, if you want to lower the SPI frequency (perhaps where you have other SPI shields, low voltages etc), call SPI.setClockDivider() after init()). -Flush the receiver and transmitter buffers
  • Set the radio to receive with powerUpRx();
    Returns
    true if everything was successful

Reimplemented from RHGenericDriver.

References RHNRFSPIDriver::_spi, clearRxBuf(), DataRate2Mbps, flushRx(), flushTx(), RHGenericSPI::Frequency1MHz, RHNRFSPIDriver::init(), setChannel(), RHGenericSPI::setFrequency(), setModeIdle(), setRF(), spiReadRegister(), RHNRFSPIDriver::spiWrite(), spiWriteRegister(), and TransmitPower0dBm.

◆ isSending()

bool RH_NRF24::isSending ( )

Indicates if the chip is in transmit mode and there is a packet currently being transmitted

Returns
true if the chip is in transmit mode and there is a transmission in progress

References spiReadRegister(), and statusRead().

◆ maxMessageLength()

uint8_t RH_NRF24::maxMessageLength ( )
virtual

The maximum message length supported by this driver

Returns
The maximum message length supported by this driver

Implements RHGenericDriver.

◆ printRegisters()

bool RH_NRF24::printRegisters ( )

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

Returns
true on success

References spiBurstReadRegister().

◆ recv()

bool RH_NRF24::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 available(), and clearRxBuf().

◆ send()

bool RH_NRF24::send ( const uint8_t *  data,
uint8_t  len 
)
virtual

Sends data to the address set by setTransmitAddress() Sets the radio to TX mode

Parameters
[in]dataData bytes to send.
[in]lenNumber of data bytes to send
Returns
true on success (which does not necessarily mean the receiver got the message, only that the message was successfully transmitted).

Implements RHGenericDriver.

References RHGenericDriver::_txGood, RHGenericDriver::_txHeaderFlags, RHGenericDriver::_txHeaderFrom, RHGenericDriver::_txHeaderId, RHGenericDriver::_txHeaderTo, setModeTx(), RHNRFSPIDriver::spiBurstWrite(), and RHGenericDriver::waitCAD().

◆ setChannel()

bool RH_NRF24::setChannel ( uint8_t  channel)

Sets the transmit and receive channel number. The frequency used is (2400 + channel) MHz

Returns
true on success

References spiWriteRegister().

Referenced by init().

◆ setModeIdle()

void RH_NRF24::setModeIdle ( )

Sets the radio in power down mode, with the configuration set to the last value from setOpMode(). Sets chip enable to LOW.

References RHGenericDriver::_mode, RHGenericDriver::RHModeIdle, and spiWriteRegister().

Referenced by available(), init(), and waitPacketSent().

◆ setModeRx()

void RH_NRF24::setModeRx ( )

Sets the radio in RX mode. Sets chip enable to HIGH to enable the chip in RX mode.

References RHGenericDriver::_mode, RHGenericDriver::RHModeRx, and spiWriteRegister().

Referenced by available().

◆ setModeTx()

void RH_NRF24::setModeTx ( )

Sets the radio in TX mode. Pulses the chip enable LOW then HIGH to enable the chip in TX mode.

References RHGenericDriver::_mode, RHGenericDriver::RHModeTx, and spiWriteRegister().

Referenced by send().

◆ setNetworkAddress()

bool RH_NRF24::setNetworkAddress ( uint8_t *  address,
uint8_t  len 
)

Sets the Network address. Only nodes with the same network address can communicate with each other. You can set different network addresses in different sets of nodes to isolate them from each other. Internally, this sets the nRF24 TX_ADDR and RX_ADDR_P0 to be the given network address. The default network address is 0xE7E7E7E7E7

Parameters
[in]addressThe new network address. Must match the network address of any receiving node(s).
[in]lenNumber of bytes of address to set (3 to 5).
Returns
true on success, false if len is not in the range 3-5 inclusive.

References spiBurstWriteRegister(), and spiWriteRegister().

◆ setOpMode()

bool RH_NRF24::setOpMode ( uint8_t  mode)

Sets the chip configuration that will be used to set the NRF24 NRF24_REG_00_CONFIG register when in Idle mode. This allows you to change some chip configuration for compatibility with libraries other than this one. You should not normally need to call this. Defaults to NRF24_EN_CRC| RH_NRF24_CRCO, which is the standard configuration for this library (2 byte CRC enabled).

Parameters
[in]modeThe chip configuration to be used whe in Idle mode.
Returns
true on success

References RHGenericDriver::mode().

◆ setRF()

bool RH_NRF24::setRF ( DataRate  data_rate,
TransmitPower  power 
)

Sets the data rate and transmitter power to use. Note that the nRF24 and the RFM73 have different available power levels, and for convenience, 2 different sets of values are available in the RH_NRF24::TransmitPower enum. The ones with the RFM73 only have meaning on the RFM73 and compatible devces. The others are for the nRF24.

Parameters
[in]data_rateThe data rate to use for all packets transmitted and received. One of RH_NRF24::DataRate.
[in]powerTransmitter power. One of RH_NRF24::TransmitPower.
Returns
true on success

References DataRate250kbps, DataRate2Mbps, and spiWriteRegister().

Referenced by init().

◆ sleep()

bool RH_NRF24::sleep ( )
virtual

Sets the radio into Power Down mode. If successful, the radio will stay in Power Down 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 spiWriteRegister().

◆ spiBurstReadRegister()

uint8_t RH_NRF24::spiBurstReadRegister ( uint8_t  reg,
uint8_t *  dest,
uint8_t  len 
)

Reads a number of consecutive registers from the NRF24 using burst read mode

Parameters
[in]regRegister number of the first register, one of RH_NRF24_REG_*
[in]destArray to write the register values to. Must be at least len bytes
[in]lenNumber of bytes to read
Returns
the current STATUS (read while the command is sent)

References RHNRFSPIDriver::spiBurstRead().

Referenced by printRegisters().

◆ spiBurstWriteRegister()

uint8_t RH_NRF24::spiBurstWriteRegister ( uint8_t  reg,
uint8_t *  src,
uint8_t  len 
)

Write a number of consecutive registers using burst write mode

Parameters
[in]regRegister number of the first register, one of RH_NRF24_REG_*
[in]srcArray of new register values to write. Must be at least len bytes
[in]lenNumber of bytes to write
Returns
the current STATUS (read while the command is sent)

References RHNRFSPIDriver::spiBurstWrite().

Referenced by setNetworkAddress().

◆ spiReadRegister()

uint8_t RH_NRF24::spiReadRegister ( uint8_t  reg)

Reads a single register from the NRF24

Parameters
[in]regRegister number, one of RH_NRF24_REG_*
Returns
The value of the register

References RHNRFSPIDriver::spiRead().

Referenced by available(), init(), and isSending().

◆ spiWriteRegister()

uint8_t RH_NRF24::spiWriteRegister ( uint8_t  reg,
uint8_t  val 
)

Writes a single byte to the NRF24, and at the same time reads the current STATUS register

Parameters
[in]regRegister number, one of RH_NRF24_REG_*
[in]valThe value to write
Returns
the current STATUS (read while the command is sent)

References RHNRFSPIDriver::spiWrite().

Referenced by available(), init(), setChannel(), setModeIdle(), setModeRx(), setModeTx(), setNetworkAddress(), setRF(), sleep(), and waitPacketSent().

◆ statusRead()

uint8_t RH_NRF24::statusRead ( )

Reads and returns the device status register NRF24_REG_02_DEVICE_STATUS

Returns
The value of the device status register

References RHNRFSPIDriver::spiCommand().

Referenced by isSending(), and waitPacketSent().

◆ waitPacketSent()

bool RH_NRF24::waitPacketSent ( )
virtual

Blocks until the current message (if any) has been transmitted

Returns
true on success, false if the chip is not in transmit mode or other transmit failure

Reimplemented from RHGenericDriver.

References RHGenericDriver::_mode, flushTx(), RHGenericDriver::RHModeTx, setModeIdle(), spiWriteRegister(), and statusRead().


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