Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
RH_NRF24 Class Reference
Send and receive addressed, reliable, acknowledged datagrams by nRF24L01 and compatible transceivers. More...
#include <RH_NRF24.h>
Inherits RHNRFSPIDriver.
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... | |
enum | RHMode { RHModeInitialising = 0, RHModeSleep, RHModeIdle, RHModeTx, RHModeRx } |
Defines different operating modes for the transport hardware. More... | |
Public Member Functions | |
RH_NRF24 (PINS chipEnablePin, PINS slaveSelectPin, RHGenericSPI &spi=hardware_spi) | |
Constructor. | |
bool | init () |
Initialises this instance and the radio module connected to it. | |
uint8_t | spiReadRegister (uint8_t reg) |
Reads a single register from the NRF24. | |
uint8_t | spiWriteRegister (uint8_t reg, uint8_t val) |
Writes a single byte to the NRF24, and at the ame time reads the current STATUS register. | |
uint8_t | spiBurstReadRegister (uint8_t reg, uint8_t *dest, uint8_t len) |
Reads a number of consecutive registers from the NRF24 using burst read mode. | |
uint8_t | spiBurstWriteRegister (uint8_t reg, uint8_t *src, uint8_t len) |
Write a number of consecutive registers using burst write mode. | |
uint8_t | statusRead () |
Reads and returns the device status register NRF24_REG_02_DEVICE_STATUS. | |
bool | setChannel (uint8_t channel) |
Sets the transmit and receive channel number. | |
bool | 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. | |
bool | setNetworkAddress (uint8_t *address, uint8_t len) |
Sets the Network address. | |
bool | setRF (DataRate data_rate, TransmitPower power) |
Sets the data rate and transmitter power to use. | |
void | setModeIdle () |
Sets the radio in power down mode, with the configuration set to the last value from setOpMode(). | |
void | setModeRx () |
Sets the radio in RX mode. | |
void | setModeTx () |
Sets the radio in TX mode. | |
bool | send (const uint8_t *data, uint8_t len) |
Sends data to the address set by setTransmitAddress() Sets the radio to TX mode. | |
virtual bool | waitPacketSent () |
Blocks until the current message (if any) has been transmitted. | |
bool | isSending () |
Indicates if the chip is in transmit mode and there is a packet currently being transmitted. | |
bool | 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. | |
bool | available () |
Checks whether a received message is available. | |
bool | recv (uint8_t *buf, uint8_t *len) |
Turns the receiver on if it not already on. | |
uint8_t | maxMessageLength () |
The maximum message length supported by this driver. | |
virtual bool | sleep () |
Sets the radio into Power Down mode. | |
uint8_t | spiCommand (uint8_t command) |
Sends a single command to the device. | |
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 (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 | |
uint8_t | flushTx () |
Flush the TX FIFOs. | |
uint8_t | flushRx () |
Flush the RX FIFOs. | |
void | validateRxBuf () |
Examine the receive buffer to determine whether the message is for this node. | |
void | clearRxBuf () |
Clear our local receive buffer. | |
Protected Attributes | |
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. |
Detailed Description
Send and receive addressed, reliable, acknowledged datagrams by nRF24L01 and compatible transceivers.
Supported transceivers include:
- Nordic nRF24 based 2.4GHz radio modules, such as nRF24L01 http://www.nordicsemi.com/eng/Products/2.4GHz-RF/nRF24L01 and other compatible transceivers.
- nRF24L01p with PA and LNA modules that produce a higher power output similar to this one: http://www.elecfreaks.com/wiki/index.php?title=2.4G_Wireless_nRF24L01p_with_PA_and_LNA
- Sparkfun WRL-00691 module with nRF24L01 https://www.sparkfun.com/products/691 or WRL-00705 https://www.sparkfun.com/products/705 etc.
- Hope-RF RFM73 http://www.hoperf.com/rf/2.4g_module/RFM73.htm and http://www.anarduino.com/details.jsp?pid=121 and compatible devices (such as BK2423). nRF24L01 and RFM73 can interoperate with each other.
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:
- 1 octets PREAMBLE
- 3 to 5 octets NETWORK ADDRESS
- 9 bits packet control field
- 0 to 32 octets PAYLOAD, consisting of:
- 1 octet TO header
- 1 octet FROM header
- 1 octet ID header
- 1 octet FLAGS header
- 0 to 28 octets of user message
- 2 octets CRC
- 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 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);
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 RHSoftwareSPI spi; RH_NRF24 nrf24(12, 11, spi); void setup() { spi.setPins(7, 8, 9); ....
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 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);
Initialisation example with software SPI
#include <RH_NRF24.h> #include <RHSoftwareSPI.h> RHSoftwareSPI spi; 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.
Definition at line 401 of file RH_NRF24.h.
Member Enumeration Documentation
enum DataRate |
Defines convenient values for setting data rates in setRF()
Definition at line 406 of file RH_NRF24.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.
enum 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:
Definition at line 416 of file RH_NRF24.h.
Constructor & Destructor Documentation
RH_NRF24 | ( | PINS | chipEnablePin, |
PINS | slaveSelectPin, | ||
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] chipEnablePin the Arduino pin to use to enable the chip for transmit/receive [in] slaveSelectPin the 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] spi Pointer to the SPI interface object to use. Defaults to the standard Arduino hardware SPI interface
Definition at line 8 of file RH_NRF24.cpp.
Member Function Documentation
bool 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.
Definition at line 283 of file RH_NRF24.cpp.
void clearRxBuf | ( | ) | [protected] |
Clear our local receive buffer.
Definition at line 314 of file RH_NRF24.cpp.
uint8_t flushRx | ( | ) | [protected] |
Flush the RX FIFOs.
- Returns:
- the value of the device status register
Definition at line 93 of file RH_NRF24.cpp.
uint8_t flushTx | ( | ) | [protected] |
Flush the TX FIFOs.
- Returns:
- the value of the device status register
Definition at line 88 of file RH_NRF24.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: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 RHNRFSPIDriver.
Definition at line 17 of file RH_NRF24.cpp.
bool 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
Definition at line 225 of file RH_NRF24.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 335 of file RH_NRF24.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] prompt string to preface the print [in] buf Location of the buffer to print [in] len Length of the buffer in octets.
Definition at line 145 of file RHGenericDriver.cpp.
bool 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
Definition at line 231 of file RH_NRF24.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] buf Location to copy the received message [in,out] len Pointer 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 320 of file RH_NRF24.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] |
Sends data to the address set by setTransmitAddress() Sets the radio to TX mode.
- Parameters:
-
[in] data Data bytes to send. [in] len Number 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.
Definition at line 186 of file RH_NRF24.cpp.
bool setChannel | ( | uint8_t | channel ) |
Sets the transmit and receive channel number.
The frequency used is (2400 + channel) MHz
- Returns:
- true on success
Definition at line 98 of file RH_NRF24.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] set bitmask of bits to be set. Flags are cleared with the clear mask before being set. [in] clear bitmask 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] from The 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] id The 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] to The new TO header value
Definition at line 83 of file RHGenericDriver.cpp.
void setMode | ( | RHMode | mode ) | [inherited] |
Sets the operating mode of the transport.
Definition at line 134 of file RHGenericDriver.cpp.
void setModeIdle | ( | ) |
Sets the radio in power down mode, with the configuration set to the last value from setOpMode().
Sets chip enable to LOW.
Definition at line 141 of file RH_NRF24.cpp.
void setModeRx | ( | ) |
Sets the radio in RX mode.
Sets chip enable to HIGH to enable the chip in RX mode.
Definition at line 161 of file RH_NRF24.cpp.
void setModeTx | ( | ) |
Sets the radio in TX mode.
Pulses the chip enable LOW then HIGH to enable the chip in TX mode.
Definition at line 171 of file RH_NRF24.cpp.
bool 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] address The new network address. Must match the network address of any receiving node(s). [in] len Number of bytes of address to set (3 to 5).
- Returns:
- true on success, false if len is not in the range 3-5 inclusive.
Definition at line 110 of file RH_NRF24.cpp.
bool 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] mode The chip configuration to be used whe in Idle mode.
- Returns:
- true on success
Definition at line 104 of file RH_NRF24.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] promiscuous true if you wish to receive messages with any TO address
Reimplemented in RH_RF22.
Definition at line 73 of file RHGenericDriver.cpp.
bool 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_rate The data rate to use for all packets transmitted and received. One of RH_NRF24::DataRate. [in] power Transmitter power. One of RH_NRF24::TransmitPower.
- Returns:
- true on success
Definition at line 122 of file RH_NRF24.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] thisAddress The address of this node.
Reimplemented in RH_RF22, and RH_TCP.
Definition at line 78 of file RHGenericDriver.cpp.
bool 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.
Definition at line 151 of file RH_NRF24.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] reg Register number of the first register [in] dest Array to write the register values to. Must be at least len bytes [in] len Number 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 68 of file RHNRFSPIDriver.cpp.
uint8_t 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] reg Register number of the first register, one of NRF24_REG_* [in] dest Array to write the register values to. Must be at least len bytes [in] len Number of bytes to read
- Returns:
- the current STATUS (read while the command is sent)
Definition at line 72 of file RH_NRF24.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] reg Register number of the first register [in] src Array of new register values to write. Must be at least len bytes [in] len Number 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 81 of file RHNRFSPIDriver.cpp.
uint8_t spiBurstWriteRegister | ( | uint8_t | reg, |
uint8_t * | src, | ||
uint8_t | len | ||
) |
Write a number of consecutive registers using burst write mode.
- Parameters:
-
[in] reg Register number of the first register, one of NRF24_REG_* [in] src Array of new register values to write. Must be at least len bytes [in] len Number of bytes to write
- Returns:
- the current STATUS (read while the command is sent)
Definition at line 77 of file RH_NRF24.cpp.
uint8_t spiCommand | ( | uint8_t | command ) | [inherited] |
Sends a single command to the device.
- Parameters:
-
[in] command The command code to send to the device.
- 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 33 of file RHNRFSPIDriver.cpp.
uint8_t spiRead | ( | uint8_t | reg ) | [inherited] |
Reads a single register from the SPI device.
- Parameters:
-
[in] reg Register number
- Returns:
- The value of the register
Definition at line 44 of file RHNRFSPIDriver.cpp.
uint8_t spiReadRegister | ( | uint8_t | reg ) |
Reads a single register from the NRF24.
- Parameters:
-
[in] reg Register number, one of NRF24_REG_*
- Returns:
- The value of the register
Definition at line 62 of file RH_NRF24.cpp.
uint8_t spiWrite | ( | uint8_t | reg, |
uint8_t | val | ||
) | [inherited] |
Writes a single byte to the SPI device.
- Parameters:
-
[in] reg Register number [in] val The 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 56 of file RHNRFSPIDriver.cpp.
uint8_t spiWriteRegister | ( | uint8_t | reg, |
uint8_t | val | ||
) |
Writes a single byte to the NRF24, and at the ame time reads the current STATUS register.
- Parameters:
-
[in] reg Register number, one of NRF24_REG_* [in] val The value to write
- Returns:
- the current STATUS (read while the command is sent)
Definition at line 67 of file RH_NRF24.cpp.
uint8_t statusRead | ( | ) |
Reads and returns the device status register NRF24_REG_02_DEVICE_STATUS.
- Returns:
- The value of the device status register
Definition at line 82 of file RH_NRF24.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 validateRxBuf | ( | ) | [protected] |
Examine the receive buffer to determine whether the message is for this node.
Definition at line 265 of file RH_NRF24.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] timeout Maximum 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 | ( | uint16_t | timeout ) | [virtual, inherited] |
Blocks until the transmitter is no longer transmitting.
or until the timeout occuers, whichever happens first
- Parameters:
-
[in] timeout Maximum 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.
bool 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.
Definition at line 203 of file RH_NRF24.cpp.
Field Documentation
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.
The current transport operating mode.
Definition at line 216 of file RHGenericDriver.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 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 87 of file RHNRFSPIDriver.h.
RHGenericSPI& _spi [protected, inherited] |
Reference to the RHGenericSPI instance to use to trasnfer data with teh SPI device.
Definition at line 83 of file RHNRFSPIDriver.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.
Generated on Tue Jul 12 2022 18:05:56 by
