RadioHead
|
Send and receive unaddressed, unreliable datagrams by nRF51 and nRF52 compatible transceivers. More...
#include <RH_NRF51.h>
Public Types | |
enum | DataRate { DataRate1Mbps = 0 , DataRate2Mbps , DataRate250kbps } |
Defines convenient values for setting data rates in setRF() More... | |
enum | TransmitPower { TransmitPower4dBm = 0 , TransmitPower0dBm , TransmitPowerm4dBm , TransmitPowerm8dBm , TransmitPowerm12dBm , TransmitPowerm16dBm , TransmitPowerm20dBm , TransmitPowerm30dBm } |
Convenient values for setting transmitter power in setRF() More... | |
Public Types inherited from RHGenericDriver | |
enum | RHMode { RHModeInitialising = 0 , RHModeSleep , RHModeIdle , RHModeTx , RHModeRx , RHModeCad } |
Defines different operating modes for the transport hardware. More... | |
Public Member Functions | |
RH_NRF51 () | |
bool | init () |
bool | setChannel (uint8_t channel) |
bool | setNetworkAddress (uint8_t *address, uint8_t len) |
bool | setRF (DataRate data_rate, TransmitPower power) |
void | setModeIdle () |
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) |
virtual bool | waitPacketSent () |
bool | isSending () |
bool | printRegisters () |
bool | available () |
bool | recv (uint8_t *buf, uint8_t *len) |
void | setEncryptionKey (uint8_t *key=NULL) |
uint8_t | maxMessageLength () |
float | get_temperature () |
Public Member Functions inherited from RHGenericDriver | |
RHGenericDriver () | |
Constructor. | |
virtual | ~RHGenericDriver () |
Generic destructor to prevent warnings when objects are dynamically allocated. | |
virtual void | waitAvailable (uint16_t polldelay=0) |
virtual bool | waitPacketSent (uint16_t timeout) |
virtual bool | waitAvailableTimeout (uint16_t timeout, uint16_t polldelay=0) |
virtual bool | waitCAD () |
void | setCADTimeout (unsigned long cad_timeout) |
virtual bool | isChannelActive () |
virtual void | setThisAddress (uint8_t thisAddress) |
virtual void | setHeaderTo (uint8_t to) |
virtual void | setHeaderFrom (uint8_t from) |
virtual void | setHeaderId (uint8_t id) |
virtual void | setHeaderFlags (uint8_t set, uint8_t clear=RH_FLAGS_APPLICATION_SPECIFIC) |
virtual void | setPromiscuous (bool promiscuous) |
virtual uint8_t | headerTo () |
virtual uint8_t | headerFrom () |
virtual uint8_t | headerId () |
virtual uint8_t | headerFlags () |
virtual int16_t | lastRssi () |
virtual RHMode | mode () |
virtual void | setMode (RHMode mode) |
Sets the operating mode of the transport. | |
virtual bool | sleep () |
virtual uint16_t | rxBad () |
virtual uint16_t | rxGood () |
virtual uint16_t | txGood () |
Protected Member Functions | |
void | validateRxBuf () |
Examine the receive buffer to determine whether the message is for this node. | |
void | clearRxBuf () |
Clear our local receive buffer. | |
Additional Inherited Members | |
Static Public Member Functions inherited from RHGenericDriver | |
static void | printBuffer (const char *prompt, const uint8_t *buf, uint8_t len) |
Protected Attributes inherited from RHGenericDriver | |
volatile RHMode | _mode |
The current transport operating mode. | |
uint8_t | _thisAddress |
This node id. | |
bool | _promiscuous |
Whether the transport is in promiscuous mode. | |
volatile uint8_t | _rxHeaderTo |
TO header in the last received mesasge. | |
volatile uint8_t | _rxHeaderFrom |
FROM header in the last received mesasge. | |
volatile uint8_t | _rxHeaderId |
ID header in the last received mesasge. | |
volatile uint8_t | _rxHeaderFlags |
FLAGS header in the last received mesasge. | |
uint8_t | _txHeaderTo |
TO header to send in all messages. | |
uint8_t | _txHeaderFrom |
FROM header to send in all messages. | |
uint8_t | _txHeaderId |
ID header to send in all messages. | |
uint8_t | _txHeaderFlags |
FLAGS header to send in all messages. | |
volatile int16_t | _lastRssi |
The value of the last received RSSI value, in some transport specific units. | |
volatile uint16_t | _rxBad |
Count of the number of bad messages (eg bad checksum etc) received. | |
volatile uint16_t | _rxGood |
Count of the number of successfully transmitted messaged. | |
volatile uint16_t | _txGood |
Count of the number of bad messages (correct checksum etc) received. | |
volatile bool | _cad |
Channel activity detected. | |
unsigned int | _cad_timeout |
Channel activity timeout in ms. | |
Send and receive unaddressed, unreliable datagrams by nRF51 and nRF52 compatible transceivers.
Supported transceivers include:
This base class provides basic functions for sending and receiving unaddressed, unreliable datagrams of arbitrary length to 254 octets per packet. Use one of the Manager classes to get addressing and acknowledgement reliability, routing, meshes etc.
The nRF51822 (https://www.nordicsemi.com/eng/Products/Bluetooth-Smart-Bluetooth-low-energy/nRF51822) and nRF52832 (https://learn.sparkfun.com/tutorials/nrf52832-breakout-board-hookup-guide) is a complete SoC (system on a chip) with ARM microprocessor and 2.4 GHz radio, which supports a range of channels and transmission bit rates. Chip antenna is on-board.
This library provides functions for sending and receiving messages of up to 254 octets on any frequency supported by the nRF51822/nRF52832, at a selected data rate.
The nRF51 transceiver is configured to use Enhanced Shockburst with no acknowledgement and no retransmits. TXADDRESS and RXADDRESSES:RXADDR0 (ie pipe 0) are the logical address used. The on-air network address is set in BASE0 and PREFIX0. SHORTS is used to automatically transition the radio between Ready, Start and Disable. No interrupts are used.
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 programs are included to show the main modes of use.
All messages sent and received by this class conform to this packet format. It is NOT compatible with the one used by RH_NRF24 and the nRF24L01 product specification, mainly because the nRF24 only supports 6 bits of message length.
Several example programs are provided.
The sample programs are designed to be built using Arduino 1.6.4 or later using the procedures outlined in http://redbearlab.com/getting-started-nrf51822/ or with Sparkfun nRF52832 breakout board, with Arduino 1.6.13 and Sparkfun nRF52 boards manager 0.2.3 using the procedures outlined in https://learn.sparkfun.com/tutorials/nrf52832-breakout-board-hookup-guide
At DataRate2Mbps (2Mb/s), payload length vs airtime: 0 bytes takes about 70us, 128 bytes takes 520us, 254 bytes take 1020us. You can extrapolate linearly to slower data rates.
The RF powers claimed by the chip manufacturer have not been independently verified here.
The compiled client and server sketches are about 42k bytes on Arduino. The reliable client and server sketches compile to about 43k bytes on Arduino. Unfortunately the Arduino build environmnet does not drop unused clsses and code, so the resulting programs include all the unused classes ad code. This needs to be revisited. RAM requirements are minimal.
enum RH_NRF51::DataRate |
Defines convenient values for setting data rates in setRF()
Enumerator | |
---|---|
DataRate1Mbps | 1 Mbps |
DataRate2Mbps | 2 Mbps |
DataRate250kbps | 250 kbps |
Convenient values for setting transmitter power in setRF()
RH_NRF51::RH_NRF51 | ( | ) |
Constructor. After constructing, you must call init() to initialise the interface and the radio module
|
virtual |
Checks whether a received message is available. This can be called multiple times in a timeout loop
Implements RHGenericDriver.
float RH_NRF51::get_temperature | ( | ) |
Reeads the current die temperature using the built in TEMP peripheral. Blocks while the temperature is measured, which takes about 30 microseconds.
|
virtual |
Initialises this instance and the radio module connected to it. The following steps are taken:
Reimplemented from RHGenericDriver.
bool RH_NRF51::isSending | ( | ) |
Indicates if the chip is in transmit mode and there is a packet currently being transmitted
|
virtual |
The maximum message length supported by this driver
Implements RHGenericDriver.
bool RH_NRF51::printRegisters | ( | ) |
Prints the value of all NRF_RADIO registers. to the Serial device if RH_HAVE_SERIAL is defined for the current platform For debugging purposes only. Caution: there are 1024 of them (many reserved and set to 0).
|
virtual |
Turns the receiver on if it not already on. Once a message with CRC correct is received, the receiver will be returned to Idle mode. 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.
[in] | buf | Location to copy the received message |
[in,out] | len | Pointer to the number of octets available in buf. The number be reset to the actual number of octets copied. |
Implements RHGenericDriver.
|
virtual |
Sends data to the address set by setTransmitAddress() Sets the radio to TX mode. Caution: when encryption is enabled, the maximum message length is reduced to 23 octets.
[in] | data | Data bytes to send. |
[in] | len | Number of data bytes to send |
Implements RHGenericDriver.
bool RH_NRF51::setChannel | ( | uint8_t | channel | ) |
Sets the transmit and receive channel number. The frequency used is (2400 + channel) MHz
void RH_NRF51::setEncryptionKey | ( | uint8_t * | key = NULL | ) |
Enables AES encryption and sets the AES encryption key, used to encrypt and decrypt all messages using the on-chip AES CCM mode encryption engine. The default is disabled. In the AES configuration, the message counter and IV is always set to 0, which means the same keystream is used for every message with a given key. Caution: when encryption is enabled, the maximum message length is reduced to 23 octets.
[in] | key | The key to use. Must be 16 bytes long. The same key must be installed in other instances of RH_RF51, otherwise communications will not work correctly. If key is NULL, encryption is disabled, which is the default. |
void RH_NRF51::setModeIdle | ( | ) |
Sets the radio in power down mode, with the configuration set to the last value from setOpMode(). Sets chip enable to LOW.
bool RH_NRF51::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 nRF51 BASE0 and PREFIX0 to be the given network address. The first octet of the address is used for PREFIX0 and the rest is used for BASE0. BALEN is set to the approprtae base length. The default network address is 0xE7E7E7E7E7.
[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). |
bool RH_NRF51::setRF | ( | DataRate | data_rate, |
TransmitPower | power | ||
) |
Sets the data rate and transmitter power to use.
[in] | data_rate | The data rate to use for all packets transmitted and received. One of RH_NRF51::DataRate. |
[in] | power | Transmitter power. One of RH_NRF51::TransmitPower. |
|
virtual |
Blocks until the current message (if any) has been transmitted
Reimplemented from RHGenericDriver.