nrf_to_nrf - NRF52 Radio Driver v1.2.2
TMRh20 2023 - OSI Layer 2 radio driver using RF24 API
Loading...
Searching...
No Matches
nrf_to_nrf Class Reference

Driver for the 2.4GHz radio in nRF52x and nRF54x chips, using the RF24 API. More...

#include <nrf_to_nrf.h>

Public Member Functions

Primary public interface

These are the main methods you need to operate the chip

 nrf_to_nrf ()
bool begin ()
bool available ()
bool available (uint8_t *pipe_num)
void read (void *buf, uint8_t len)
bool write (void *buf, uint8_t len, bool multicast=false, bool doEncryption=true)
void startListening (bool resetAddresses=true)
void stopListening (bool setWritingPipe=true, bool resetAddresses=true)
void stopListening (const uint8_t *txAddress, bool setWritingPipe=true, bool resetAddresses=true)
bool enableRxInterrupt (uint8_t depth=3)
void disableRxInterrupt ()
void handleInterrupt ()
void openReadingPipe (uint8_t child, const uint8_t *address)
void openWritingPipe (const uint8_t *address)
bool isChipConnected ()

Advanced Operation

Methods you can use to drive the chip in more advanced ways

uint8_t radioData [ACTUAL_MAX_PAYLOAD_SIZE+2]
bool failureDetected
uint16_t interframeSpacing
bool writeFast (void *buf, uint8_t len, bool multicast=0)
bool startWrite (void *buf, uint8_t len, bool multicast, bool doEncryption=true)
bool writeAckPayload (uint8_t pipe, void *buf, uint8_t len)
void enableAckPayload ()
void disableAckPayload ()
void enableDynamicAck ()
uint8_t getDynamicPayloadSize ()
bool isValid ()
void setChannel (uint8_t channel, bool map=0)
uint8_t getChannel ()
bool setDataRate (uint8_t speed)
void setPALevel (uint8_t level, bool lnaEnable=true)
uint8_t getPALevel ()
void setAutoAck (bool enable)
void setAutoAck (uint8_t pipe, bool enable)
void enableDynamicPayloads (uint8_t payloadSize=DEFAULT_MAX_PAYLOAD_SIZE)
void disableDynamicPayloads ()
void setPayloadSize (uint8_t size)
uint8_t getPayloadSize ()
void setCRCLength (nrf_crclength_e length)
nrf_crclength_e getCRCLength ()
void disableCRC ()
void setRetries (uint8_t retryVar, uint8_t attempts)
void openReadingPipe (uint8_t child, uint64_t address)
void openWritingPipe (uint64_t address)
void setAddressWidth (uint8_t a_width)
void printDetails ()
void powerUp ()
void powerDown ()
bool txStandBy ()
bool txStandBy (uint32_t timeout, bool startTx=0)
bool testCarrier (uint8_t RSSI=65)
bool testRPD (uint8_t RSSI=65)
uint8_t getRSSI ()
uint8_t getARC ()
uint8_t flush_rx ()
uint8_t flush_tx ()

Encryption

Methods you can use to enable encryption & authentication

uint8_t outBuffer [MAX_PACKET_SIZE+CCM_MIC_SIZE+CCM_START_SIZE]
bool enableEncryption
uint32_t addrConv32 (uint32_t addr)
uint8_t encrypt (void *bufferIn, uint8_t size)
uint8_t decrypt (void *bufferIn, uint8_t size)
void setKey (uint8_t key[CCM_KEY_SIZE])
void setCounter (uint64_t counter)
void setIV (uint8_t IV[CCM_IV_SIZE])

Detailed Description

Constructor & Destructor Documentation

◆ nrf_to_nrf()

nrf_to_nrf::nrf_to_nrf ( )

Constructor for nrf_to_nrf

Definition at line 153 of file nrf_to_nrf.cpp.

Member Function Documentation

◆ begin()

bool nrf_to_nrf::begin ( )

Begin operation of the radio

Call this in setup(), before calling any other methods. It starts the high and low frequency clocks and configures the radio with these defaults: channel 76 (2476 MHz), 1 Mbps, 16-bit CRC, maximum PA level, 5-byte addresses, 32-byte static payloads, auto-ack on all pipes, and 5 retries with a delay of 5. It also enables the RX interrupt with enableRxInterrupt().

if (!radio.begin()) {
Serial.println(F("radio hardware not responding!"));
while (1) {} // hold program in infinite loop to prevent subsequent errors
}
Returns
  • true if the radio was initialized
  • false if a clock failed to start
Examples
examples/RF24/AcknowledgementPayloads/AcknowledgementPayloads.ino, examples/RF24/GettingStarted/GettingStarted.ino, examples/RF24/GettingStartedEncryption/GettingStartedEncryption.ino, examples/RF24/GettingStartedMicros/GettingStartedMicros.ino, examples/RF24/scanner/scanner.ino, examples/RF24Mesh/RF24Mesh_ExampleEncryption/RF24Mesh_ExampleEncryption.ino, examples/RF24Mesh/RF24Mesh_Example_MasterEncryption/RF24Mesh_Example_MasterEncryption.ino, examples/RF24Network/helloworld_rx/helloworld_rx.ino, examples/RF24Network/helloworld_rxEncryption/helloworld_rxEncryption.ino, examples/RF24Network/helloworld_tx/helloworld_tx.ino, and examples/RF24Network/helloworld_txEncryption/helloworld_txEncryption.ino.

Definition at line 194 of file nrf_to_nrf.cpp.

◆ available() [1/2]

bool nrf_to_nrf::available ( )

Check whether there is a payload available to be read

if (radio.available()) {
radio.read(&data, sizeof(data));
}

With the RX interrupt enabled (the default), this checks the RX queue filled by the interrupt. In polling mode (disableRxInterrupt()), this checks the radio itself, so call it often: only one received payload is held until it is read.

After write() receives an ACK payload, this returns true for that payload until it is read.

See also
available(uint8_t*)
Returns
true if there is a payload available, false if there is none
Examples
examples/RF24/AcknowledgementPayloads/AcknowledgementPayloads.ino, examples/RF24/GettingStarted/GettingStarted.ino, examples/RF24/GettingStartedEncryption/GettingStartedEncryption.ino, and examples/RF24/GettingStartedMicros/GettingStartedMicros.ino.

Definition at line 289 of file nrf_to_nrf.cpp.

◆ available() [2/2]

bool nrf_to_nrf::available ( uint8_t * pipe_num)

Check whether there is a payload available to be read, and which pipe received it

Parameters
[out]pipe_numWhich pipe received the payload. For an ACK payload received by write(), this is pipe 0.
uint8_t pipeNum;
if (radio.available(&pipeNum)) {
radio.read(&data, sizeof(data));
Serial.print("Received data on pipe ");
Serial.println(pipeNum);
}
See also
available()
Returns
true if there is a payload available, false if there is none

Definition at line 443 of file nrf_to_nrf.cpp.

◆ read()

void nrf_to_nrf::read ( void * buf,
uint8_t len )

Read the next available payload

Call available() first. Each call removes one payload, however many bytes are read. This is different from RF24, where a payload stays in the RX FIFO until all of it has been read.

if (radio.available()) {
uint8_t length = radio.getDynamicPayloadSize(); // or getPayloadSize() for static payloads
radio.read(&data, length);
}
Parameters
bufPointer to a buffer where the data should be written
lenNumber of bytes to copy into buf. Use getDynamicPayloadSize() to get the payload's length. Bytes past the end of the payload are not meaningful.
Note
If nothing is available, the last payload received is copied again.
Examples
examples/RF24/AcknowledgementPayloads/AcknowledgementPayloads.ino, examples/RF24/GettingStarted/GettingStarted.ino, examples/RF24/GettingStartedEncryption/GettingStartedEncryption.ino, and examples/RF24/GettingStartedMicros/GettingStartedMicros.ino.

Definition at line 634 of file nrf_to_nrf.cpp.

◆ write()

bool nrf_to_nrf::write ( void * buf,
uint8_t len,
bool multicast = false,
bool doEncryption = true )

Transmit a payload to the address set with openWritingPipe()

Call stopListening() first. This blocks until an ACK is received or all retries have been used (see setRetries()). If the ACK carries an ACK payload, read it with available() and read() afterwards.

radio.stopListening();
radio.write(&data, sizeof(data));
Parameters
bufPointer to the data to be sent
lenNumber of bytes to be sent. With static payloads, a full getPayloadSize() packet is always sent, and the bytes after len are not zeroed. With dynamic payloads, len can be up to the size passed to enableDynamicPayloads(). With encryption, 12 more bytes (IV, counter and MIC) are added, and they must fit too.
multicasttrue sends the payload once without waiting for an ACK. enableDynamicAck() is not needed. The receiver still sends an ACK if auto-ack is enabled on its pipe.
doEncryptionfalse sends this payload unencrypted when encryption is enabled
Returns
  • true if an ACK was received. Also true, even if the payload was not received, if multicast is true or auto-ack is disabled on pipe 0.
  • false if no ACK was received after all retries
Examples
examples/RF24/AcknowledgementPayloads/AcknowledgementPayloads.ino, examples/RF24/GettingStarted/GettingStarted.ino, examples/RF24/GettingStartedEncryption/GettingStartedEncryption.ino, and examples/RF24/GettingStartedMicros/GettingStartedMicros.ino.

Definition at line 649 of file nrf_to_nrf.cpp.

◆ startListening()

void nrf_to_nrf::startListening ( bool resetAddresses = true)

Start listening on the pipes opened for reading

  1. Call openReadingPipe() first.
  2. Call stopListening() before calling write().
  3. Call available() to check for incoming payloads, and read() to get them.

Open reading pipe 1 using address 0xCCCECCCECC

uint8_t address[] = {0xCC, 0xCE, 0xCC, 0xCE, 0xCC};
radio.openReadingPipe(1, address);
radio.startListening();
Note
openWritingPipe() uses pipe 0's address for transmitting, so this restores the address last set for reading pipe 0 by openReadingPipe().
Parameters
resetAddressesUsed internally; leave as the default
Examples
examples/RF24/AcknowledgementPayloads/AcknowledgementPayloads.ino, examples/RF24/GettingStarted/GettingStarted.ino, examples/RF24/GettingStartedEncryption/GettingStartedEncryption.ino, examples/RF24/GettingStartedMicros/GettingStartedMicros.ino, and examples/RF24/scanner/scanner.ino.

Definition at line 1021 of file nrf_to_nrf.cpp.

◆ stopListening() [1/2]

void nrf_to_nrf::stopListening ( bool setWritingPipe = true,
bool resetAddresses = true )

Stop listening for incoming payloads, and switch to transmit mode

Do this before calling write(). This restores the TX address set by openWritingPipe(), and payloads already received can still be read.

radio.stopListening();
radio.write(&data, sizeof(data));
Note
Unlike RF24, ACK payloads loaded with writeAckPayload() are not discarded. Call flush_tx() to discard them.
Parameters
setWritingPipeUsed internally; leave as the default
resetAddressesUsed internally; leave as the default
Examples
examples/RF24/AcknowledgementPayloads/AcknowledgementPayloads.ino, examples/RF24/GettingStarted/GettingStarted.ino, examples/RF24/GettingStartedEncryption/GettingStartedEncryption.ino, examples/RF24/GettingStartedMicros/GettingStartedMicros.ino, and examples/RF24/scanner/scanner.ino.

Definition at line 1070 of file nrf_to_nrf.cpp.

◆ stopListening() [2/2]

void nrf_to_nrf::stopListening ( const uint8_t * txAddress,
bool setWritingPipe = true,
bool resetAddresses = true )

Same as stopListening(), but also sets the TX address, like calling openWritingPipe() afterwards

Parameters
txAddressThe new TX address
setWritingPipeUsed internally; leave as the default
resetAddressesUsed internally; leave as the default

Definition at line 1123 of file nrf_to_nrf.cpp.

◆ enableRxInterrupt()

bool nrf_to_nrf::enableRxInterrupt ( uint8_t depth = 3)

Receive packets from the radio interrupt, so a slow loop() doesn't leave the radio idle. available() and read() are used as normal. Don't use BLE in the same sketch.

Note
The library defines the radio interrupt handler, so a sketch can't define its own.

This is called automatically on begin(), so if you want to disable it, call disableRxInterrupt() after the radio and/or network/mesh has been configured.

Parameters
depthThe number of packets to queue, from 1 to 254. Uses (depth + 1) * (payload size + 2) bytes of RAM, plus depth * (payload size + 2) for the ACK payload queue if enableAckPayload() is called.
Returns
false if depth is invalid, there isn't enough memory, or this was already called

Definition at line 297 of file nrf_to_nrf.cpp.

◆ disableRxInterrupt()

void nrf_to_nrf::disableRxInterrupt ( )

Disable the RX interrupt and free the RX queue and the ACK payload queue

Payloads still in the RX queue are discarded. available() then checks the radio itself, so call it often: only one received payload is held until it is read. The newest ACK payload still queued is kept.

Definition at line 326 of file nrf_to_nrf.cpp.

◆ handleInterrupt()

void nrf_to_nrf::handleInterrupt ( )

Called by the library's radio interrupt handler

Definition at line 403 of file nrf_to_nrf.cpp.

◆ openReadingPipe() [1/2]

void nrf_to_nrf::openReadingPipe ( uint8_t child,
const uint8_t * address )

Open a pipe for reading

Up to 8 pipes (0-7) can be open for reading at once. Open all the required reading pipes, then call startListening().

Note
Pipe 0 stores a full address. Pipes 1-7 share every byte except the first, and each call for one of them sets the shared bytes for all of them. Pass the full address for each pipe, with only the first byte different:
uint8_t addresses[][6] = {"Prime", "2Node", "3Node", "4Node"};
radio.openReadingPipe(0, addresses[0]); // address used is "Prime"
radio.openReadingPipe(1, addresses[1]); // address used is "2Node"
radio.openReadingPipe(2, addresses[2]); // address used is "3Node"
radio.openReadingPipe(3, addresses[3]); // address used is "4Node"
Warning
openWritingPipe() uses pipe 0's address for transmitting. If pipe 0 is opened for reading, its address is restored by every startListening().
See also
Parameters
childWhich pipe to open, 0-7
addressThe address, using the number of bytes set with setAddressWidth()
Examples
examples/RF24/AcknowledgementPayloads/AcknowledgementPayloads.ino, examples/RF24/GettingStarted/GettingStarted.ino, examples/RF24/GettingStartedEncryption/GettingStartedEncryption.ino, and examples/RF24/GettingStartedMicros/GettingStartedMicros.ino.

Definition at line 1300 of file nrf_to_nrf.cpp.

◆ openWritingPipe() [1/2]

void nrf_to_nrf::openWritingPipe ( const uint8_t * address)

Open a pipe for writing

Only one writing pipe can be open at a time. This sets the address that write() transmits to. Call stopListening() first.

uint8_t addresses[][6] = {"1Node", "2Node"};
radio.openWritingPipe(addresses[0]);
Warning
This overwrites the address of reading pipe 0, which receives the ACKs. startListening() restores the reading pipe 0 address set with openReadingPipe().
See also
Parameters
addressThe address to transmit to, using the number of bytes set with setAddressWidth(). Coordinate it with the receiving nodes (the pipe numbers don't need to match).
Examples
examples/RF24/AcknowledgementPayloads/AcknowledgementPayloads.ino, examples/RF24/GettingStarted/GettingStarted.ino, examples/RF24/GettingStartedEncryption/GettingStartedEncryption.ino, and examples/RF24/GettingStartedMicros/GettingStartedMicros.ino.

Definition at line 1339 of file nrf_to_nrf.cpp.

◆ isChipConnected()

bool nrf_to_nrf::isChipConnected ( )

Check that the radio responds, the same as isValid()

The radio is part of the chip, so unlike RF24 this doesn't check an SPI connection.

Returns
true if the radio is usable
Examples
examples/RF24Mesh/RF24Mesh_Example/RF24Mesh_Example.ino, and examples/RF24Mesh/RF24Mesh_ExampleEncryption/RF24Mesh_ExampleEncryption.ino.

Definition at line 1395 of file nrf_to_nrf.cpp.

◆ writeFast()

bool nrf_to_nrf::writeFast ( void * buf,
uint8_t len,
bool multicast = 0 )

Same as write(), so it blocks until an ACK is received or all retries have been used

Provided for compatibility with RF24, where writeFast() queues up to 3 payloads in the TX FIFO.

Parameters
bufPointer to the data to be sent
lenNumber of bytes to be sent
multicasttrue sends the payload once without waiting for an ACK
Returns
Same as write()

Definition at line 1376 of file nrf_to_nrf.cpp.

◆ startWrite()

bool nrf_to_nrf::startWrite ( void * buf,
uint8_t len,
bool multicast,
bool doEncryption = true )

Start transmitting a payload without waiting for it to finish

Unlike write(), there are no retries and no ACK is received.

Parameters
bufPointer to the data to be sent
lenNumber of bytes to be sent
multicastNot used, since no ACK is waited for either way
doEncryptionfalse sends this payload unencrypted when encryption is enabled
Returns
Always true

Definition at line 840 of file nrf_to_nrf.cpp.

◆ writeAckPayload()

bool nrf_to_nrf::writeAckPayload ( uint8_t pipe,
void * buf,
uint8_t len )

Load a payload to send back in the ACK for the next packet received on pipe

With the RX interrupt enabled (the default), payloads are queued like the NRF24 TX FIFO. Up to the enableRxInterrupt() depth can be queued, so one can be loaded for each packet the RX queue holds. Each packet received takes the oldest payload queued for its pipe and sends it once; a retransmitted packet gets the same payload again. If none is queued for that pipe, a plain ACK is sent. Payloads can be at most getPayloadSize() bytes, including encryption overhead. Call enableAckPayload() first; it allocates the queue.

In polling mode (disableRxInterrupt()), one payload is stored. It is sent with the ACK for the next packet on pipe, re-sent if that packet is retransmitted, and discarded when the next new packet arrives.

This can be called before and after startListening().

Note
Use dynamic payloads (enableDynamicPayloads()) on both nodes. Unlike RF24, enableAckPayload() doesn't enable them.
See also
Parameters
pipeWhich pipe (0-7) will get this response
bufPointer to the data to send
lenLength of the data to send
Returns
false if the queue is full, the payload is too large, or with the RX interrupt, if ACK payloads aren't enabled or there wasn't enough memory for the queue
Examples
examples/RF24/AcknowledgementPayloads/AcknowledgementPayloads.ino.

Definition at line 925 of file nrf_to_nrf.cpp.

◆ enableAckPayload()

void nrf_to_nrf::enableAckPayload ( )

Enable custom payloads in the acknowledgement packets

ACK payloads are a handy way to return data to senders without changing the radio modes on both nodes. Call this on both the transmitting and receiving nodes.

With the RX interrupt, this also allocates the ACK payload queue used by writeAckPayload(): depth * (payload size + 2) bytes of RAM, where depth is the enableRxInterrupt() depth.

Note
Unlike RF24, this doesn't enable dynamic payloads. Call enableDynamicPayloads() on both nodes too.
Remarks
ACK payloads need auto-ack, which begin() enables on all pipes.
See also
Examples
examples/RF24/AcknowledgementPayloads/AcknowledgementPayloads.ino.

Definition at line 996 of file nrf_to_nrf.cpp.

◆ disableAckPayload()

void nrf_to_nrf::disableAckPayload ( )

Disable custom payloads in the acknowledgement packets

This also frees the ACK payload queue, discarding any payloads loaded with writeAckPayload().

See also
enableAckPayload()

Definition at line 1009 of file nrf_to_nrf.cpp.

◆ enableDynamicAck()

void nrf_to_nrf::enableDynamicAck ( )

Provided for compatibility with RF24. It isn't needed: the multicast parameter of write() works without it.

Definition at line 1005 of file nrf_to_nrf.cpp.

◆ getDynamicPayloadSize()

uint8_t nrf_to_nrf::getDynamicPayloadSize ( )

Get the length of the next available payload

if (radio.available()) {
uint8_t length = radio.getDynamicPayloadSize();
radio.read(&data, length);
}
Returns
The length of the payload that read() returns next. With static payloads, this is getPayloadSize().
Examples
examples/RF24/AcknowledgementPayloads/AcknowledgementPayloads.ino.

Definition at line 1131 of file nrf_to_nrf.cpp.

◆ isValid()

bool nrf_to_nrf::isValid ( )

Check that the radio responds, by writing and reading back the channel register

Returns
true if the radio is usable

Definition at line 1143 of file nrf_to_nrf.cpp.

◆ setChannel()

void nrf_to_nrf::setChannel ( uint8_t channel,
bool map = 0 )

Set the RF channel

The frequency used is 2400 MHz + channel, or 2360 MHz + channel if map is 1. With map set to 0, channels match the nRF24 channels. The default is channel 76 (2476 MHz).

Parameters
channelWhich RF channel to communicate on, 0-100
map0 for 2400-2500 MHz (default), 1 for 2360-2460 MHz
Examples
examples/RF24/scanner/scanner.ino, examples/RF24Network/helloworld_rx/helloworld_rx.ino, examples/RF24Network/helloworld_rxEncryption/helloworld_rxEncryption.ino, examples/RF24Network/helloworld_tx/helloworld_tx.ino, and examples/RF24Network/helloworld_txEncryption/helloworld_txEncryption.ino.

Definition at line 1157 of file nrf_to_nrf.cpp.

◆ getChannel()

uint8_t nrf_to_nrf::getChannel ( )

Get the RF channel

Returns
The channel set with setChannel(). The map setting is not included.

Definition at line 1161 of file nrf_to_nrf.cpp.

◆ setDataRate()

bool nrf_to_nrf::setDataRate ( uint8_t speed)

Set the transmission data rate. Both nodes must use the same rate.

Parameters
speedSpecify one of the following values (as defined by nrf_datarate_e):
speed (enum value) description
NRF_1MBPS (0) for 1 Mbps
NRF_2MBPS (1) for 2 Mbps
NRF_250KBPS (2) for 250 kbps. Deprecated by Nordic, might not work reliably
NRF_4MBPS_OBT4 (3) for 4 Mbps, nRF54L15 only
NRF_4MBPS_OBT6 (4) for 4 Mbps, nRF54L15 only
Returns
Always true

Definition at line 1399 of file nrf_to_nrf.cpp.

◆ setPALevel()

void nrf_to_nrf::setPALevel ( uint8_t level,
bool lnaEnable = true )

Set the Power Amplifier (PA) level

Parameters
levelOne of the values defined by nrf_pa_dbm_e. The output power depends on the chip:
level (enum value) nRF52840, nRF52833, nRF52820, nRF54L15 nRF52832, nRF52811, nRF52810, nRF52805
NRF_PA_MIN (0) -12 dBm -12 dBm
NRF_PA_LOW (1) 2 dBm -4 dBm
NRF_PA_HIGH (2) 6 dBm 0 dBm
NRF_PA_MAX (3) 8 dBm 4 dBm
lnaEnableNot used, since there is no LNA
Examples
examples/RF24/AcknowledgementPayloads/AcknowledgementPayloads.ino, examples/RF24/GettingStarted/GettingStarted.ino, examples/RF24/GettingStartedEncryption/GettingStartedEncryption.ino, examples/RF24/GettingStartedMicros/GettingStartedMicros.ino, examples/RF24Mesh/RF24Mesh_Example/RF24Mesh_Example.ino, and examples/RF24Mesh/RF24Mesh_ExampleEncryption/RF24Mesh_ExampleEncryption.ino.

Definition at line 1430 of file nrf_to_nrf.cpp.

◆ getPALevel()

uint8_t nrf_to_nrf::getPALevel ( )

Get the Power Amplifier (PA) level

Returns
One of the values defined by nrf_pa_dbm_e, or NRF_PA_ERROR if the TX power was set to something else. See the table in setPALevel()

Definition at line 1452 of file nrf_to_nrf.cpp.

◆ setAutoAck() [1/2]

void nrf_to_nrf::setAutoAck ( bool enable)

Enable or disable the auto-acknowledgement feature for all pipes

This is enabled by default. Auto-acknowledgement responds to every received payload with an ACK packet. To attach an ACK payload to an ACK packet, use writeAckPayload().

If this is disabled on a transmitting node, write() always reports that the payload was received, even if it wasn't. This setting needs to match on the transmitting and receiving nodes.

See also
Parameters
enableWhether to enable (true) or disable (false) auto-acknowledgement for all pipes
Examples
examples/RF24/GettingStartedMicros/GettingStartedMicros.ino, and examples/RF24/scanner/scanner.ino.

Definition at line 1165 of file nrf_to_nrf.cpp.

◆ setAutoAck() [2/2]

void nrf_to_nrf::setAutoAck ( uint8_t pipe,
bool enable )

Enable or disable the auto-acknowledgement feature for a specific pipe

This is enabled by default for all pipes. Pipe 0 is used for transmitting: if this is disabled on pipe 0 of a transmitting node, write() always reports that the payload was received, even if it wasn't. Enable this on any pipe listening to a transmitter that uses auto-ack.

Note
With static payloads, the packet format depends on whether auto-ack is enabled on pipe 0, so auto-ack can't be enabled on some pipes and disabled on others: either ACKs are enabled or not.
Parameters
pipeWhich pipe to configure, 0-7
enableWhether to enable (true) or disable (false) auto-acknowledgement for pipe

Definition at line 1178 of file nrf_to_nrf.cpp.

◆ enableDynamicPayloads()

void nrf_to_nrf::enableDynamicPayloads ( uint8_t payloadSize = DEFAULT_MAX_PAYLOAD_SIZE)

Enable dynamically-sized payloads on all pipes

Payloads are sent at the length passed to write(), instead of always using the static payload size.

Once this function has been called, users need to call disableDynamicPayloads if they want to call it again, else it has no effect.

Note
If using with RF24Network or RF24Mesh, users can call radio.begin() then radio.enableDynamicPayloads(254); before initializing the network. This will enable maximum payload sizes and fragmentation/reassembly won't engage until this length is exceeded.
Parameters
payloadSizeSet the maximum payload size. Up to 254 with DPL enabled
Examples
examples/RF24/AcknowledgementPayloads/AcknowledgementPayloads.ino, examples/RF24Mesh/RF24Mesh_ExampleEncryption/RF24Mesh_ExampleEncryption.ino, examples/RF24Mesh/RF24Mesh_Example_MasterEncryption/RF24Mesh_Example_MasterEncryption.ino, examples/RF24Network/helloworld_rxEncryption/helloworld_rxEncryption.ino, and examples/RF24Network/helloworld_txEncryption/helloworld_txEncryption.ino.

Definition at line 1189 of file nrf_to_nrf.cpp.

◆ disableDynamicPayloads()

void nrf_to_nrf::disableDynamicPayloads ( )

Disable dynamically-sized payloads on all pipes, and use the static payload size

Unlike RF24, this doesn't disable ACK payloads.

Definition at line 1212 of file nrf_to_nrf.cpp.

◆ setPayloadSize()

void nrf_to_nrf::setPayloadSize ( uint8_t size)

Set the static payload size

Every packet is sent at this size, however many bytes were passed to write(). If this is never called, the size is 32 bytes. This also disables dynamic payloads.

NRF52840 will handle up to 255 byte payloads with CRC & DPL disabled, 254 with 16-bit CRC and DPL NRF54L15 will do the same

Parameters
sizeThe number of bytes in each payload
Examples
examples/RF24/GettingStarted/GettingStarted.ino, examples/RF24/GettingStartedEncryption/GettingStartedEncryption.ino, and examples/RF24/GettingStartedMicros/GettingStartedMicros.ino.

Definition at line 1228 of file nrf_to_nrf.cpp.

◆ getPayloadSize()

uint8_t nrf_to_nrf::getPayloadSize ( )

Get the payload size

Returns
The static payload size, or with dynamic payloads, the maximum size passed to enableDynamicPayloads()
Examples
examples/RF24/GettingStarted/GettingStarted.ino, and examples/RF24/GettingStartedMicros/GettingStartedMicros.ino.

Definition at line 1264 of file nrf_to_nrf.cpp.

◆ setCRCLength()

void nrf_to_nrf::setCRCLength ( nrf_crclength_e length)

Set the CRCLength (in bits)

Both nodes must use the same setting. Disabling CRC is allowed with auto-ack enabled, but then corrupt packets aren't detected, and retransmitted packets aren't recognized as duplicates.

Parameters
lengthSpecify one of the values (as defined by nrf_crclength_e)
length (enum value) description
NRF_CRC_DISABLED (0) to disable using CRC checksums
NRF_CRC_8 (1) to use 8-bit checksums
NRF_CRC_16 (2) to use 16-bit checksums
NRF_CRC_24 (3) to use 24-bit checksums

Definition at line 1483 of file nrf_to_nrf.cpp.

◆ getCRCLength()

nrf_crclength_e nrf_to_nrf::getCRCLength ( )

Get the CRCLength (in bits)

Returns
One of the values defined by nrf_crclength_e. See the table in setCRCLength()

Definition at line 1513 of file nrf_to_nrf.cpp.

◆ disableCRC()

void nrf_to_nrf::disableCRC ( )

Disable CRC validation, the same as setCRCLength(NRF_CRC_DISABLED)

Definition at line 1509 of file nrf_to_nrf.cpp.

◆ setRetries()

void nrf_to_nrf::setRetries ( uint8_t retryVar,
uint8_t attempts )

Set the number of retries and the delay between them when transmitting with write()

After each attempt, write() waits for an ACK for a time that depends on the data rate and payload type, then waits for the delay before retrying.

Parameters
retryVarHow long to wait between retries, in multiples of about 258 us. The default is 5.
attemptsHow many retries before giving up, so write() makes up to attempts + 1 attempts. The default is 5. Use 0 to disable retries.

Definition at line 1271 of file nrf_to_nrf.cpp.

◆ openReadingPipe() [2/2]

void nrf_to_nrf::openReadingPipe ( uint8_t child,
uint64_t address )

Open a pipe for reading, using a 40-bit address

Kept for compatibility with older code. See openReadingPipe(uint8_t, const uint8_t*), which this works like. Pipes 1-7 share every byte except the least significant one, e.g.

radio.openReadingPipe(1, 0xF0F0F0F0AA);
radio.openReadingPipe(2, 0xF0F0F0F0BB);
Parameters
childWhich pipe to open, 0-7
addressThe 40-bit address of the pipe to open

Definition at line 1280 of file nrf_to_nrf.cpp.

◆ openWritingPipe() [2/2]

void nrf_to_nrf::openWritingPipe ( uint64_t address)

Open a pipe for writing, using a 40-bit address

Kept for compatibility with older code. See openWritingPipe(const uint8_t*), which this works like.

radio.openWritingPipe(0xF0F0F0F0F0);
Parameters
addressThe 40-bit address of the pipe to open

Definition at line 1290 of file nrf_to_nrf.cpp.

◆ setAddressWidth()

void nrf_to_nrf::setAddressWidth ( uint8_t a_width)

Set the address width from 3 to 5 bytes (24, 32 or 40 bit)

Both nodes must use the same width. The default is 5 bytes.

Parameters
a_widthThe address width (in bytes) to use; this can be 3, 4 or 5

Definition at line 1650 of file nrf_to_nrf.cpp.

◆ printDetails()

void nrf_to_nrf::printDetails ( )

Print a block of debugging information about the radio configuration to Serial

Examples
examples/RF24Ethernet/mqtt_basic/mqtt_basic.ino.

Definition at line 1658 of file nrf_to_nrf.cpp.

◆ powerUp()

void nrf_to_nrf::powerUp ( )

When powering up from powerdown ALL radio settings will need to be re-applied

Enables the Radio & HF Clock

If encryption is enabled, also enables RNG & CCM peripherals

Definition at line 1594 of file nrf_to_nrf.cpp.

◆ powerDown()

void nrf_to_nrf::powerDown ( )

When called ALL radio settings will be reverted to default

Disables the Radio & HF Clock

If encryption is enabled, also disables RNG & CCM peripherals

Definition at line 1627 of file nrf_to_nrf.cpp.

◆ txStandBy() [1/2]

bool nrf_to_nrf::txStandBy ( )

Get the result of the last write

Provided for compatibility with RF24. write() and writeFast() already wait until the transmission is done, so this doesn't wait or change the radio state.

Returns
true if the last write() or writeFast() succeeded, or after startWrite(); false if it failed

Definition at line 1362 of file nrf_to_nrf.cpp.

◆ txStandBy() [2/2]

bool nrf_to_nrf::txStandBy ( uint32_t timeout,
bool startTx = 0 )

Same as txStandBy()

Parameters
timeoutNot used
startTxNot used
Returns
Same as txStandBy()

Definition at line 1369 of file nrf_to_nrf.cpp.

◆ testCarrier()

bool nrf_to_nrf::testCarrier ( uint8_t RSSI = 65)

Test whether a signal stronger than -RSSI dBm is present on the channel

Useful to check for interference on the current channel and for channel hopping strategies. Unlike RF24, this samples the signal strength now, instead of reporting the last listening period. The radio must be listening. Always returns false on the nRF54L15.

if (radio.testCarrier()) {
Serial.println("Signal stronger than -65dBm");
}
Parameters
RSSIThe threshold in -dBm. The default of 65 means -65 dBm.
Returns
true if the signal is stronger than -RSSI dBm
Examples
examples/RF24/scanner/scanner.ino.

Definition at line 1531 of file nrf_to_nrf.cpp.

◆ testRPD()

bool nrf_to_nrf::testRPD ( uint8_t RSSI = 65)

Same as testCarrier()

Parameters
RSSIThe threshold in -dBm. The default of 65 means -65 dBm, close to the nRF24L01+ RPD threshold of -64 dBm.
Returns
true if the signal is stronger than -RSSI dBm

Definition at line 1549 of file nrf_to_nrf.cpp.

◆ getRSSI()

uint8_t nrf_to_nrf::getRSSI ( )

A new function specific to the NRF52x devices, not available on NRF24

The radio must be listening. Always returns 0 on the nRF54L15.

Returns
The function will return the RSSI, which is measured continuously and the value filtered using a single-pole IIR filter. This is a negative value: received signal strength = -A dBm

Definition at line 1556 of file nrf_to_nrf.cpp.

◆ getARC()

uint8_t nrf_to_nrf::getARC ( )

Get the number of retries used by the last write()

Allows roughly estimating signal quality.

Returns
From 0 (acknowledged on the first attempt) to the attempts value passed to setRetries()

Definition at line 1476 of file nrf_to_nrf.cpp.

◆ flush_rx()

uint8_t nrf_to_nrf::flush_rx ( )

Discard all received payloads that haven't been read, including an ACK payload received by write()

Returns
Always 0. RF24 returns the status register, which the nRF52 radio doesn't have.

Definition at line 1572 of file nrf_to_nrf.cpp.

◆ flush_tx()

uint8_t nrf_to_nrf::flush_tx ( )

Discard any ACK payloads loaded with writeAckPayload()

Unlike RF24, stopListening() doesn't call this, and there are no regular payloads to discard, since write() sends its payload immediately.

Returns
Always 0

Definition at line 1582 of file nrf_to_nrf.cpp.

◆ addrConv32()

uint32_t nrf_to_nrf::addrConv32 ( uint32_t addr)

Used internally to convert addresses

Definition at line 139 of file nrf_to_nrf.cpp.

◆ encrypt()

uint8_t nrf_to_nrf::encrypt ( void * bufferIn,
uint8_t size )

Function to encrypt data

Called automatically when a write is performed

Definition at line 1809 of file nrf_to_nrf.cpp.

◆ decrypt()

uint8_t nrf_to_nrf::decrypt ( void * bufferIn,
uint8_t size )

Function to decrypt data

Called automatically when incoming data is received

Definition at line 1841 of file nrf_to_nrf.cpp.

◆ setKey()

◆ setCounter()

void nrf_to_nrf::setCounter ( uint64_t counter)

Set the (default 3-byte) packet counter used for encryption

Examples
examples/RF24/GettingStartedEncryption/GettingStartedEncryption.ino.

Definition at line 1900 of file nrf_to_nrf.cpp.

◆ setIV()

void nrf_to_nrf::setIV ( uint8_t IV[CCM_IV_SIZE])

Set IV for encryption. This is only used for manual encryption, a random IV is generated using the on-board RNG for encryption during normal operation.

Definition at line 1908 of file nrf_to_nrf.cpp.

Member Data Documentation

◆ radioData

uint8_t nrf_to_nrf::radioData[ACTUAL_MAX_PAYLOAD_SIZE+2]

Data buffer for radio data The radio can handle packets up to 255 bytes if CRC & DPL is disabled 254 bytes if using 16-bit CRC & DPL is disabled

Definition at line 408 of file nrf_to_nrf.h.

◆ failureDetected

bool nrf_to_nrf::failureDetected

Not implemented due to SOC

Definition at line 732 of file nrf_to_nrf.h.

◆ interframeSpacing

uint16_t nrf_to_nrf::interframeSpacing

The IEEE 802.15.4 standard defines a specific time that is alotted for the MAC sublayer to process received data. Usage of this interframe spacing (IFS) comes into play to avoid that two frames are transmitted too close to each other in time.

This is the time period in uS the radio will wait between the last bit of the previous transmission, and the first bit of the next transmission.

This is configured for compatibility with nRF24L01 radios. Can be set lower if communicating between nRF52x devices.

Definition at line 816 of file nrf_to_nrf.h.

◆ outBuffer

uint8_t nrf_to_nrf::outBuffer[MAX_PACKET_SIZE+CCM_MIC_SIZE+CCM_START_SIZE]

The data buffer where encrypted data is placed. See the datasheet p115 for the CCM data structure

Definition at line 857 of file nrf_to_nrf.h.

◆ enableEncryption

bool nrf_to_nrf::enableEncryption

Enable use of the on-board AES CCM mode encryption

Cipher block chaining - message authentication code (CCM) mode is an authenticated encryption algorithm designed to provide both authentication and confidentiality during data transfer. CCM combines counter mode encryption and CBC-MAC authentication

Users need to take extra steps to prevent specific attacks, such as replay attacks, which can be prevented by transmitting a timestamp or counter value, and only accepting packets with a current timestamp/counter value, rejecting old data.

Encryption uses a 5-byte IV and 3-byte counter, the sizes of which can be configured in nrf_to_nrf.h Maximum: 8-byte IV, 4-byte counter, plus the MAC/MIC is 4-bytes

Examples
examples/RF24/GettingStartedEncryption/GettingStartedEncryption.ino, examples/RF24Mesh/RF24Mesh_ExampleEncryption/RF24Mesh_ExampleEncryption.ino, examples/RF24Mesh/RF24Mesh_Example_MasterEncryption/RF24Mesh_Example_MasterEncryption.ino, examples/RF24Network/helloworld_rxEncryption/helloworld_rxEncryption.ino, and examples/RF24Network/helloworld_txEncryption/helloworld_txEncryption.ino.

Definition at line 890 of file nrf_to_nrf.h.


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