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 class for nRF52840 2.4GHz Wireless Transceiver. 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 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
 
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)
 
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 ()
 

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

nrf_to_nrf radio;
Driver class for nRF52840 2.4GHz Wireless Transceiver.
Definition nrf_to_nrf.h:115

Definition at line 62 of file nrf_to_nrf.cpp.

Member Function Documentation

◆ begin()

◆ available() [1/2]

◆ available() [2/2]

bool nrf_to_nrf::available ( uint8_t * pipe_num)

Same as NRF24 radio.available();

Definition at line 180 of file nrf_to_nrf.cpp.

◆ read()

◆ write()

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

◆ startListening()

void nrf_to_nrf::startListening ( bool resetAddresses = true)

◆ stopListening()

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

Same as NRF24

Parameters
setWritingPipeUsed internally
resetAddressesUsed internally to reset addresses
Examples
examples/RF24/AcknowledgementPayloads/AcknowledgementPayloads.ino, examples/RF24/GettingStarted/GettingStarted.ino, examples/RF24/GettingStartedEncryption/GettingStartedEncryption.ino, and examples/RF24/scanner/scanner.ino.

Definition at line 737 of file nrf_to_nrf.cpp.

◆ openReadingPipe() [1/2]

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

◆ openWritingPipe() [1/2]

◆ isChipConnected()

◆ writeFast()

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

Not currently fully functional, calls the regular write();

Definition at line 1046 of file nrf_to_nrf.cpp.

◆ startWrite()

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

Writes a payload to the radio without waiting for completion.

This function will not wait for the radio to finish transmitting or for an ACK

Call txStandBy() to take the radio out of TX state or call startListening() to go into RX mode

Definition at line 565 of file nrf_to_nrf.cpp.

◆ writeAckPayload()

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

Same as NRF24

Examples
examples/RF24/AcknowledgementPayloads/AcknowledgementPayloads.ino.

Definition at line 663 of file nrf_to_nrf.cpp.

◆ enableAckPayload()

void nrf_to_nrf::enableAckPayload ( )

Same as NRF24

Examples
examples/RF24/AcknowledgementPayloads/AcknowledgementPayloads.ino.

Definition at line 706 of file nrf_to_nrf.cpp.

◆ disableAckPayload()

void nrf_to_nrf::disableAckPayload ( )

Same as NRF24

Definition at line 710 of file nrf_to_nrf.cpp.

◆ enableDynamicAck()

void nrf_to_nrf::enableDynamicAck ( )

Same as NRF24

◆ getDynamicPayloadSize()

uint8_t nrf_to_nrf::getDynamicPayloadSize ( )

Same as NRF24

Examples
examples/RF24/AcknowledgementPayloads/AcknowledgementPayloads.ino.

Definition at line 761 of file nrf_to_nrf.cpp.

◆ isValid()

bool nrf_to_nrf::isValid ( )

Same as NRF24

Definition at line 769 of file nrf_to_nrf.cpp.

◆ setChannel()

◆ getChannel()

uint8_t nrf_to_nrf::getChannel ( )

Same as NRF24

Definition at line 787 of file nrf_to_nrf.cpp.

◆ setDataRate()

bool nrf_to_nrf::setDataRate ( uint8_t speed)

Supported speeds: NRF_1MBPS NRF_2MBPS

Definition at line 1069 of file nrf_to_nrf.cpp.

◆ setPALevel()

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

◆ getPALevel()

uint8_t nrf_to_nrf::getPALevel ( )

Same as NRF24

Definition at line 1112 of file nrf_to_nrf.cpp.

◆ setAutoAck() [1/2]

void nrf_to_nrf::setAutoAck ( bool enable)

Same as NRF24

Examples
examples/RF24/scanner/scanner.ino.

Definition at line 791 of file nrf_to_nrf.cpp.

◆ setAutoAck() [2/2]

void nrf_to_nrf::setAutoAck ( uint8_t pipe,
bool enable )
Note
If using static payloads, acks cannot be enabled & disabled on separate pipes, either ACKs are enabled or not

Definition at line 804 of file nrf_to_nrf.cpp.

◆ enableDynamicPayloads()

void nrf_to_nrf::enableDynamicPayloads ( uint8_t payloadSize = DEFAULT_MAX_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 edit RF24Network.h and set MAX_FRAME_SIZE to a maximum of 111 if encryption is enabled, 123 without encryption.
Parameters
payloadSizeSet the maximum payload size. Up to 125 with CRC disabled or 123 with 16-bit CRC
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 815 of file nrf_to_nrf.cpp.

◆ disableDynamicPayloads()

void nrf_to_nrf::disableDynamicPayloads ( )

Same as NRF24

Definition at line 835 of file nrf_to_nrf.cpp.

◆ setPayloadSize()

void nrf_to_nrf::setPayloadSize ( uint8_t size)

NRF52840 will handle up to 127 byte payloads with CRC disabled, 125 with 16-bit CRC

Examples
examples/RF24/GettingStarted/GettingStarted.ino, and examples/RF24/GettingStartedEncryption/GettingStartedEncryption.ino.

Definition at line 850 of file nrf_to_nrf.cpp.

◆ getPayloadSize()

uint8_t nrf_to_nrf::getPayloadSize ( )

Same as NRF24

Examples
examples/RF24/GettingStarted/GettingStarted.ino.

Definition at line 866 of file nrf_to_nrf.cpp.

◆ setCRCLength()

void nrf_to_nrf::setCRCLength ( nrf_crclength_e length)

Same as NRF24

Definition at line 1143 of file nrf_to_nrf.cpp.

◆ getCRCLength()

nrf_crclength_e nrf_to_nrf::getCRCLength ( )

Same as NRF24

Definition at line 1165 of file nrf_to_nrf.cpp.

◆ disableCRC()

void nrf_to_nrf::disableCRC ( )

Same as NRF24

◆ setRetries()

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

Same as NRF24

Definition at line 873 of file nrf_to_nrf.cpp.

◆ openReadingPipe() [2/2]

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

Same as NRF24

Definition at line 882 of file nrf_to_nrf.cpp.

◆ openWritingPipe() [2/2]

void nrf_to_nrf::openWritingPipe ( uint64_t address)

Same as NRF24

Definition at line 923 of file nrf_to_nrf.cpp.

◆ setAddressWidth()

void nrf_to_nrf::setAddressWidth ( uint8_t a_width)

Same as NRF24

Definition at line 1226 of file nrf_to_nrf.cpp.

◆ printDetails()

void nrf_to_nrf::printDetails ( )

Same as NRF24

Examples
examples/RF24Ethernet/mqtt_basic/mqtt_basic.ino.

Definition at line 1241 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

Definition at line 1213 of file nrf_to_nrf.cpp.

◆ powerDown()

void nrf_to_nrf::powerDown ( )

When called ALL radio settings will be reverted to default

Definition at line 1220 of file nrf_to_nrf.cpp.

◆ txStandBy() [1/2]

bool nrf_to_nrf::txStandBy ( )

Takes the radio out of TX state.

Can be called after any type of write to put the radio into a disabled state

Definition at line 1006 of file nrf_to_nrf.cpp.

◆ txStandBy() [2/2]

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

Takes the radio out of TX state

Can be called after any type of write to put the radio into a disabled state

Definition at line 1026 of file nrf_to_nrf.cpp.

◆ testCarrier()

bool nrf_to_nrf::testCarrier ( uint8_t RSSI = 65)

Similar to NRF24, but can be modified to look for signals better than specified RSSI value

Parameters
RSSIThe function will return 1 if a value better than -65dBm by default
Examples
examples/RF24/scanner/scanner.ino.

Definition at line 1180 of file nrf_to_nrf.cpp.

◆ testRPD()

bool nrf_to_nrf::testRPD ( uint8_t RSSI = 65)

Similar to NRF24, but can be modified to look for signals better than specified RSSI value

Parameters
RSSIThe function will return 1 if a value better than -65dBm by default

Definition at line 1195 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

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 1202 of file nrf_to_nrf.cpp.

◆ getARC()

uint8_t nrf_to_nrf::getARC ( )

Same as NRF24

Definition at line 1136 of file nrf_to_nrf.cpp.

◆ addrConv32()

uint32_t nrf_to_nrf::addrConv32 ( uint32_t addr)

Used internally to convert addresses

Definition at line 48 of file nrf_to_nrf.cpp.

◆ encrypt()

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

Function to encrypt data

Definition at line 1335 of file nrf_to_nrf.cpp.

◆ decrypt()

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

Function to decrypt data

Definition at line 1367 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 1408 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 1416 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 127 bytes if CRC is disabled 125 bytes if using 16-bit CRC

Definition at line 204 of file nrf_to_nrf.h.

◆ failureDetected

bool nrf_to_nrf::failureDetected

Not implemented due to SOC

Definition at line 366 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 437 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 470 of file nrf_to_nrf.h.


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