RadioLib
Universal wireless communication library for Arduino
nRF24 Class Reference

Control class for nRF24 module. More...

#include <nRF24.h>

Inheritance diagram for nRF24:
PhysicalLayer

Public Member Functions

 nRF24 (Module *mod)
 Default constructor. More...
 
int16_t begin (int16_t freq=2400, int16_t dataRate=1000, int8_t power=-12, uint8_t addrWidth=5)
 Initialization method. More...
 
int16_t sleep ()
 Sets the module to sleep mode. More...
 
int16_t standby () override
 Sets the module to standby mode. More...
 
int16_t transmit (uint8_t *data, size_t len, uint8_t addr) override
 Blocking binary transmit method. Overloads for string-based transmissions are implemented in PhysicalLayer. More...
 
int16_t receive (uint8_t *data, size_t len) override
 Blocking binary receive method. Overloads for string-based transmissions are implemented in PhysicalLayer. More...
 
int16_t transmitDirect (uint32_t frf=0) override
 Starts direct mode transmission. More...
 
int16_t receiveDirect () override
 Dummy direct mode reception method, to ensure PhysicalLayer compatibility. More...
 
void setIrqAction (void(*func)(void))
 Sets interrupt service routine to call when IRQ activates. More...
 
int16_t startTransmit (uint8_t *data, size_t len, uint8_t addr) override
 Interrupt-driven binary transmit method. IRQ will be activated when full packet is transmitted. Overloads for string-based transmissions are implemented in PhysicalLayer. More...
 
int16_t startReceive ()
 Interrupt-driven receive method. IRQ will be activated when full packet is received. More...
 
int16_t readData (uint8_t *data, size_t len) override
 Reads data received after calling startReceive method. More...
 
int16_t setFrequency (int16_t freq)
 Sets carrier frequency. Allowed values range from 2400 MHz to 2525 MHz. More...
 
int16_t setDataRate (int16_t dataRate)
 Sets data rate. Allowed values are 2000, 1000 or 250 kbps. More...
 
int16_t setOutputPower (int8_t power)
 Sets output power. Allowed values are -18, -12, -6 or 0 dBm. More...
 
int16_t setAddressWidth (uint8_t addrWidth)
 Sets address width of transmit and receive pipes in bytes. Allowed values are 3, 4 or 5 bytes. More...
 
int16_t setTransmitPipe (uint8_t *addr)
 Sets address of transmit pipe. The address width must be the same as the same as the configured in setAddressWidth. More...
 
int16_t setReceivePipe (uint8_t pipeNum, uint8_t *addr)
 Sets address of receive pipes 0 or 1. The address width must be the same as the same as the configured in setAddressWidth. More...
 
int16_t setReceivePipe (uint8_t pipeNum, uint8_t addrByte)
 Sets address of receive pipes 2 - 5. The first 2 - 4 address bytes for these pipes are the same as for address pipe 1, only the last byte can be set. More...
 
int16_t disablePipe (uint8_t pipeNum)
 Disables specified receive pipe. More...
 
int16_t getStatus (uint8_t mask=0xFF)
 Gets nRF24 status register. More...
 
bool isCarrierDetected ()
 Checks if carrier was detected during last RX. More...
 
int16_t setFrequencyDeviation (float freqDev) override
 Dummy configuration method, to ensure PhysicalLayer compatibility. More...
 
size_t getPacketLength (bool update=true) override
 Query modem for the packet length of received payload. More...
 
int16_t setCrcFiltering (bool crcOn=true)
 Enable CRC filtering and generation. More...
 
int16_t setAutoAck (bool autoAckOn=true)
 Enable or disable auto-acknowledge packets on all pipes. More...
 
int16_t setAutoAck (uint8_t pipeNum, bool autoAckOn)
 Enable or disable auto-acknowledge packets on given pipe. More...
 
int16_t setDataShaping (uint8_t sh) override
 Dummy data shaping configuration method, to ensure PhysicalLayer compatibility. More...
 
int16_t setEncoding (uint8_t encoding) override
 Dummy encoding configuration method, to ensure PhysicalLayer compatibility. More...
 
uint8_t random ()
 Dummy random method, to ensure PhysicalLayer compatibility. More...
 
- Public Member Functions inherited from PhysicalLayer
 PhysicalLayer (float freqStep, size_t maxPacketLength)
 Default constructor. More...
 
int16_t transmit (__FlashStringHelper *fstr, uint8_t addr=0)
 Arduino Flash String transmit method. More...
 
int16_t transmit (String &str, uint8_t addr=0)
 Arduino String transmit method. More...
 
int16_t transmit (const char *str, uint8_t addr=0)
 C-string transmit method. More...
 
int16_t receive (String &str, size_t len=0)
 Arduino String receive method. More...
 
int16_t startTransmit (String &str, uint8_t addr=0)
 Interrupt-driven Arduino String transmit method. Unlike the standard transmit method, this one is non-blocking. Interrupt pin will be activated when transmission finishes. More...
 
int16_t startTransmit (const char *str, uint8_t addr=0)
 Interrupt-driven Arduino String transmit method. Unlike the standard transmit method, this one is non-blocking. Interrupt pin will be activated when transmission finishes. More...
 
int16_t readData (String &str, size_t len=0)
 Reads data that was received after calling startReceive method. More...
 
float getFreqStep () const
 Gets the module frequency step size that was set in constructor. More...
 
int32_t random (int32_t max)
 Get truly random number in range 0 - max. More...
 
int32_t random (int32_t min, int32_t max)
 Get truly random number in range min - max. More...
 
int16_t startDirect ()
 Configure module parameters for direct modes. Must be called prior to "ham" modes like RTTY or AX.25. Only available in FSK mode. More...
 

Detailed Description

Control class for nRF24 module.

Constructor & Destructor Documentation

◆ nRF24()

nRF24::nRF24 ( Module mod)

Default constructor.

Parameters
modInstance of Module that will be used to communicate with the radio.

Member Function Documentation

◆ begin()

int16_t nRF24::begin ( int16_t  freq = 2400,
int16_t  dataRate = 1000,
int8_t  power = -12,
uint8_t  addrWidth = 5 
)

Initialization method.

Parameters
freqCarrier frequency in MHz. Defaults to 2400 MHz.
dataRateData rate to be used in kbps. Defaults to 1000 kbps.
powerOutput power in dBm. Defaults to -12 dBm.
addrWidthAddress width in bytes. Defaults to 5 bytes.
Returns
Status Codes

◆ disablePipe()

int16_t nRF24::disablePipe ( uint8_t  pipeNum)

Disables specified receive pipe.

Parameters
pipeNumReceive pipe to be disabled.
Returns
Status Codes

◆ getPacketLength()

size_t nRF24::getPacketLength ( bool  update = true)
overridevirtual

Query modem for the packet length of received payload.

Parameters
updateUpdate received packet length. Will return cached value when set to false.
Returns
Length of last received packet in bytes.

Implements PhysicalLayer.

◆ getStatus()

int16_t nRF24::getStatus ( uint8_t  mask = 0xFF)

Gets nRF24 status register.

Parameters
maskBit mask to be used on the returned register value.
Returns
Status register value or Status Codes

◆ isCarrierDetected()

bool nRF24::isCarrierDetected ( )

Checks if carrier was detected during last RX.

Returns
Whatever the carrier was above threshold.

◆ random()

uint8_t nRF24::random ( )
virtual

Dummy random method, to ensure PhysicalLayer compatibility.

Returns
Always returns 0.

Implements PhysicalLayer.

◆ readData()

int16_t nRF24::readData ( uint8_t *  data,
size_t  len 
)
overridevirtual

Reads data received after calling startReceive method.

Parameters
dataPointer to array to save the received binary data.
lenNumber of bytes that will be received. Must be known in advance for binary transmissions.
Returns
Status Codes

Implements PhysicalLayer.

◆ receive()

int16_t nRF24::receive ( uint8_t *  data,
size_t  len 
)
overridevirtual

Blocking binary receive method. Overloads for string-based transmissions are implemented in PhysicalLayer.

Parameters
dataBinary data to be sent.
lenNumber of bytes to send.
Returns
Status Codes

Implements PhysicalLayer.

◆ receiveDirect()

int16_t nRF24::receiveDirect ( )
overridevirtual

Dummy direct mode reception method, to ensure PhysicalLayer compatibility.

Returns
Status Codes

Implements PhysicalLayer.

◆ setAddressWidth()

int16_t nRF24::setAddressWidth ( uint8_t  addrWidth)

Sets address width of transmit and receive pipes in bytes. Allowed values are 3, 4 or 5 bytes.

Parameters
addrWidthAddress width to be set in bytes.
Returns
Status Codes

◆ setAutoAck() [1/2]

int16_t nRF24::setAutoAck ( bool  autoAckOn = true)

Enable or disable auto-acknowledge packets on all pipes.

Parameters
autoAckOnEnable (true) or disable (false) auto-acks.
Returns
Status Codes

◆ setAutoAck() [2/2]

int16_t nRF24::setAutoAck ( uint8_t  pipeNum,
bool  autoAckOn 
)

Enable or disable auto-acknowledge packets on given pipe.

Parameters
pipeNumNumber of pipe to which enable / disable auto-acks.
autoAckOnEnable (true) or disable (false) auto-acks.
Returns
Status Codes

◆ setCrcFiltering()

int16_t nRF24::setCrcFiltering ( bool  crcOn = true)

Enable CRC filtering and generation.

Parameters
crcOnSet or unset CRC check.
Returns
Status Codes

◆ setDataRate()

int16_t nRF24::setDataRate ( int16_t  dataRate)

Sets data rate. Allowed values are 2000, 1000 or 250 kbps.

Parameters
dataRateData rate to be set in kbps.
Returns
Status Codes

◆ setDataShaping()

int16_t nRF24::setDataShaping ( uint8_t  sh)
overridevirtual

Dummy data shaping configuration method, to ensure PhysicalLayer compatibility.

Parameters
shIgnored.
Returns
Status Codes

Implements PhysicalLayer.

◆ setEncoding()

int16_t nRF24::setEncoding ( uint8_t  encoding)
overridevirtual

Dummy encoding configuration method, to ensure PhysicalLayer compatibility.

Parameters
shIgnored.
Returns
Status Codes

Implements PhysicalLayer.

◆ setFrequency()

int16_t nRF24::setFrequency ( int16_t  freq)

Sets carrier frequency. Allowed values range from 2400 MHz to 2525 MHz.

Parameters
freqCarrier frequency to be set in MHz.
Returns
Status Codes

◆ setFrequencyDeviation()

int16_t nRF24::setFrequencyDeviation ( float  freqDev)
overridevirtual

Dummy configuration method, to ensure PhysicalLayer compatibility.

Parameters
freqDevDummy frequency deviation parameter, no configuration will be changed.
Returns
Status Codes

Implements PhysicalLayer.

◆ setIrqAction()

void nRF24::setIrqAction ( void(*)(void)  func)

Sets interrupt service routine to call when IRQ activates.

Parameters
funcISR to call.

◆ setOutputPower()

int16_t nRF24::setOutputPower ( int8_t  power)

Sets output power. Allowed values are -18, -12, -6 or 0 dBm.

Parameters
powerOutput power to be set in dBm.
Returns
Status Codes

◆ setReceivePipe() [1/2]

int16_t nRF24::setReceivePipe ( uint8_t  pipeNum,
uint8_t *  addr 
)

Sets address of receive pipes 0 or 1. The address width must be the same as the same as the configured in setAddressWidth.

Parameters
pipeNumNumber of pipe to which the address shall be set. Either 0 or 1, other pipes are handled using overloaded method.
addrAddress from which nRF24 shall receive new packets on the specified pipe.
Returns
Status Codes

◆ setReceivePipe() [2/2]

int16_t nRF24::setReceivePipe ( uint8_t  pipeNum,
uint8_t  addrByte 
)

Sets address of receive pipes 2 - 5. The first 2 - 4 address bytes for these pipes are the same as for address pipe 1, only the last byte can be set.

Parameters
pipeNumNumber of pipe to which the address shall be set. Allowed values range from 2 to 5.
addrByteLSB of address from which nRF24 shall receive new packets on the specified pipe.
Returns
Status Codes

◆ setTransmitPipe()

int16_t nRF24::setTransmitPipe ( uint8_t *  addr)

Sets address of transmit pipe. The address width must be the same as the same as the configured in setAddressWidth.

Parameters
addrAddress to which the next packet shall be transmitted.
Returns
Status Codes

◆ sleep()

int16_t nRF24::sleep ( )

Sets the module to sleep mode.

Returns
Status Codes

◆ standby()

int16_t nRF24::standby ( )
overridevirtual

Sets the module to standby mode.

Returns
Status Codes

Implements PhysicalLayer.

◆ startReceive()

int16_t nRF24::startReceive ( )

Interrupt-driven receive method. IRQ will be activated when full packet is received.

Returns
Status Codes

◆ startTransmit()

int16_t nRF24::startTransmit ( uint8_t *  data,
size_t  len,
uint8_t  addr 
)
overridevirtual

Interrupt-driven binary transmit method. IRQ will be activated when full packet is transmitted. Overloads for string-based transmissions are implemented in PhysicalLayer.

Parameters
dataBinary data to be sent.
lenNumber of bytes to send.
addrDummy address parameter, to ensure PhysicalLayer compatibility.
Returns
Status Codes

Implements PhysicalLayer.

◆ transmit()

int16_t nRF24::transmit ( uint8_t *  data,
size_t  len,
uint8_t  addr 
)
overridevirtual

Blocking binary transmit method. Overloads for string-based transmissions are implemented in PhysicalLayer.

Parameters
dataBinary data to be sent.
lenNumber of bytes to send.
addrDummy address parameter, to ensure PhysicalLayer compatibility.
Returns
Status Codes

Implements PhysicalLayer.

◆ transmitDirect()

int16_t nRF24::transmitDirect ( uint32_t  frf = 0)
overridevirtual

Starts direct mode transmission.

Parameters
frfRaw RF frequency value. Defaults to 0, required for quick frequency shifts in RTTY.
Returns
Status Codes

Implements PhysicalLayer.


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