nrf_to_nrf - NRF52 Radio Driver v1.2.2
TMRh20 2023 - OSI Layer 2 radio driver using RF24 API
|
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 | stopListening (const uint8_t *txAddress, 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 |
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 () |
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]) |
Driver class for nRF52840 2.4GHz Wireless Transceiver.
Definition at line 116 of file nrf_to_nrf.h.
nrf_to_nrf::nrf_to_nrf | ( | ) |
bool nrf_to_nrf::begin | ( | ) |
Call this before operating the radio
Definition at line 89 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::available | ( | ) |
Same as NRF24 radio.available();
Definition at line 164 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::available | ( | uint8_t * | pipe_num | ) |
Same as NRF24 radio.available();
Definition at line 172 of file nrf_to_nrf.cpp.
void nrf_to_nrf::read | ( | void * | buf, |
uint8_t | len ) |
Same as NRF24 radio.read();
Definition at line 339 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::write | ( | void * | buf, |
uint8_t | len, | ||
bool | multicast = false, | ||
bool | doEncryption = true ) |
Same as NRF24 radio.write();
Definition at line 348 of file nrf_to_nrf.cpp.
void nrf_to_nrf::startListening | ( | bool | resetAddresses = true | ) |
Same as NRF24
resetAddresses | Used internally to reset addresses |
Definition at line 666 of file nrf_to_nrf.cpp.
void nrf_to_nrf::stopListening | ( | bool | setWritingPipe = true, |
bool | resetAddresses = true ) |
Same as NRF24
setWritingPipe | Used internally |
resetAddresses | Used internally to reset addresses |
Definition at line 695 of file nrf_to_nrf.cpp.
void nrf_to_nrf::stopListening | ( | const uint8_t * | txAddress, |
bool | setWritingPipe = true, | ||
bool | resetAddresses = true ) |
Definition at line 727 of file nrf_to_nrf.cpp.
void nrf_to_nrf::openReadingPipe | ( | uint8_t | child, |
const uint8_t * | address ) |
Same as NRF24 except the 52840 has 8 pipes
Definition at line 880 of file nrf_to_nrf.cpp.
void nrf_to_nrf::openWritingPipe | ( | const uint8_t * | address | ) |
Same as NRF24
Definition at line 919 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::isChipConnected | ( | ) |
Same as NRF24
Definition at line 975 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::writeFast | ( | void * | buf, |
uint8_t | len, | ||
bool | multicast = 0 ) |
Not currently fully functional, calls the regular write();
Definition at line 956 of file nrf_to_nrf.cpp.
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 527 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::writeAckPayload | ( | uint8_t | pipe, |
void * | buf, | ||
uint8_t | len ) |
Same as NRF24
Definition at line 615 of file nrf_to_nrf.cpp.
void nrf_to_nrf::enableAckPayload | ( | ) |
Same as NRF24
Definition at line 658 of file nrf_to_nrf.cpp.
void nrf_to_nrf::disableAckPayload | ( | ) |
Same as NRF24
Definition at line 662 of file nrf_to_nrf.cpp.
void nrf_to_nrf::enableDynamicAck | ( | ) |
Same as NRF24
uint8_t nrf_to_nrf::getDynamicPayloadSize | ( | ) |
Same as NRF24
Definition at line 735 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::isValid | ( | ) |
Same as NRF24
Definition at line 743 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setChannel | ( | uint8_t | channel, |
bool | map = 0 ) |
Same as NRF24, except we can map the channels lower
channel | Set 0 to 100 for 2400-2500Mhz if map == 0, 2360-2460Mhz if map == 1 |
map | 1 is low range (2360-2460Mhz), 0 is high range (2400-2500Mhz) |
Definition at line 757 of file nrf_to_nrf.cpp.
uint8_t nrf_to_nrf::getChannel | ( | ) |
Same as NRF24
Definition at line 761 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::setDataRate | ( | uint8_t | speed | ) |
Supported speeds: NRF_250KBPS NRF_1MBPS NRF_2MBPS
Definition at line 979 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setPALevel | ( | uint8_t | level, |
bool | lnaEnable = true ) |
Same as NRF24 except there is no LNA and the PA levels are as follows:
(0) represents -12dBm (1) represents 2dBm (2) represents 6dBm (3) represents 8dBm
Definition at line 1000 of file nrf_to_nrf.cpp.
uint8_t nrf_to_nrf::getPALevel | ( | ) |
Same as NRF24
Definition at line 1022 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setAutoAck | ( | bool | enable | ) |
Same as NRF24
Definition at line 765 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setAutoAck | ( | uint8_t | pipe, |
bool | enable ) |
Definition at line 778 of file nrf_to_nrf.cpp.
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.
radio.begin()
then radio.enableDynamicPayloads(123);
before initializing the network. This will enable maximum payload sizes and fragmentation/reassembly won't engage until this length is exceeded. payloadSize | Set the maximum payload size. Up to 125 with DPL enabled & CRC disabled or 123 with 16-bit CRC & DPL enabled |
Definition at line 789 of file nrf_to_nrf.cpp.
void nrf_to_nrf::disableDynamicPayloads | ( | ) |
Same as NRF24
Definition at line 811 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setPayloadSize | ( | uint8_t | size | ) |
NRF52840 will handle up to 127 byte payloads with CRC & DPL disabled, 125 with 16-bit CRC and DPL disabled
Definition at line 827 of file nrf_to_nrf.cpp.
uint8_t nrf_to_nrf::getPayloadSize | ( | ) |
Same as NRF24
Definition at line 844 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setCRCLength | ( | nrf_crclength_e | length | ) |
Set the CRCLength (in bits)
CRC cannot be disabled if auto-ack is enabled
length | Specify one of the values (as defined by nrf_crclength_e)
|
Definition at line 1053 of file nrf_to_nrf.cpp.
nrf_crclength_e nrf_to_nrf::getCRCLength | ( | ) |
Same as NRF24
Definition at line 1079 of file nrf_to_nrf.cpp.
void nrf_to_nrf::disableCRC | ( | ) |
Same as NRF24
void nrf_to_nrf::setRetries | ( | uint8_t | retryVar, |
uint8_t | attempts ) |
Same as NRF24
Definition at line 851 of file nrf_to_nrf.cpp.
void nrf_to_nrf::openReadingPipe | ( | uint8_t | child, |
uint64_t | address ) |
Same as NRF24
Definition at line 860 of file nrf_to_nrf.cpp.
void nrf_to_nrf::openWritingPipe | ( | uint64_t | address | ) |
Same as NRF24
Definition at line 870 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setAddressWidth | ( | uint8_t | a_width | ) |
Same as NRF24
Definition at line 1170 of file nrf_to_nrf.cpp.
void nrf_to_nrf::printDetails | ( | ) |
Same as NRF24
Definition at line 1178 of file nrf_to_nrf.cpp.
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 1137 of file nrf_to_nrf.cpp.
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 1158 of file nrf_to_nrf.cpp.
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 942 of file nrf_to_nrf.cpp.
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 949 of file nrf_to_nrf.cpp.
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
RSSI | The function will return 1 if a value better than -65dBm by default |
Definition at line 1097 of file nrf_to_nrf.cpp.
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
RSSI | The function will return 1 if a value better than -65dBm by default |
Definition at line 1112 of file nrf_to_nrf.cpp.
uint8_t nrf_to_nrf::getRSSI | ( | ) |
A new function specific to the NRF52x devices, not available on NRF24
Definition at line 1119 of file nrf_to_nrf.cpp.
uint8_t nrf_to_nrf::getARC | ( | ) |
Same as NRF24
Definition at line 1046 of file nrf_to_nrf.cpp.
uint8_t nrf_to_nrf::flush_rx | ( | ) |
Does nothing, added for backward compatibility
Definition at line 1130 of file nrf_to_nrf.cpp.
uint32_t nrf_to_nrf::addrConv32 | ( | uint32_t | addr | ) |
Used internally to convert addresses
Definition at line 48 of file nrf_to_nrf.cpp.
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 1273 of file nrf_to_nrf.cpp.
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 1305 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setKey | ( | uint8_t | key[CCM_KEY_SIZE] | ) |
Set our 16-byte (128-bit) encryption key
Definition at line 1344 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setCounter | ( | uint64_t | counter | ) |
Set the (default 3-byte) packet counter used for encryption
Definition at line 1360 of file nrf_to_nrf.cpp.
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 1368 of file nrf_to_nrf.cpp.
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 & DPL is disabled 125 bytes if using 16-bit CRC & DPL is disabled
Definition at line 208 of file nrf_to_nrf.h.
bool nrf_to_nrf::failureDetected |
Not implemented due to SOC
Definition at line 390 of file nrf_to_nrf.h.
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 445 of file nrf_to_nrf.h.
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 482 of file nrf_to_nrf.h.
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
Definition at line 515 of file nrf_to_nrf.h.