# RadioLib: nRF24 Class Reference

nRF24 Class Reference

Control class for nRF24 module. More...

`#include <nRF24.h>`

Inheritance diagram for nRF24:

## Public Member Functions

| nRF24 (Module *mod)
| Default constructor. More...
int16_t | begin (int16_t freq=RADIOLIB_NRF24_DEFAULT_FREQ, int16_t dr=RADIOLIB_NRF24_DEFAULT_DR, int8_t pwr=RADIOLIB_NRF24_DEFAULT_POWER, uint8_t addrWidth=RADIOLIB_NRF24_DEFAULT_ADDRWIDTH)
| Initialization method. More...
int16_t | sleep () override
| Sets the module to sleep mode. More...
int16_t | standby () override
| Sets the module to standby mode. More...
int16_t | standby (uint8_t mode) override
| Sets the module to standby. 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...
void | clearIrqAction ()
| Clears interrupt service routine .
void | setPacketReceivedAction (void(*func)(void)) override
| Sets interrupt service routine to call when a packet is received. More...
void | clearPacketReceivedAction () override
| Clears interrupt service routine to call when a packet is received.
void | setPacketSentAction (void(*func)(void)) override
| Sets interrupt service routine to call when a packet is sent. More...
void | clearPacketSentAction () override
| Clears interrupt service routine to call when a packet is sent.
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 | finishTransmit () override
| Clean up after transmission is done. More...
int16_t | startReceive () override
| Interrupt-driven receive method. IRQ will be activated when full packet is received. More...
int16_t | startReceive (uint32_t timeout, uint32_t irqFlags, uint32_t irqMask, size_t len) override
| Interrupt-driven receive method, implemented for compatibility with PhysicalLayer. More...
int16_t | readData (uint8_t *data, size_t len) override
| Reads data received after calling startReceive method. When the packet length is not known in advance, getPacketLength method must be called BEFORE calling readData! More...
int16_t | setFrequency (float freq) override
| Sets carrier frequency. Allowed values range from 2400 MHz to 2525 MHz. More...
int16_t | setBitRate (float br) override
| Sets bit rate. Allowed values are 2000, 1000 or 250 kbps. More...
int16_t | setOutputPower (int8_t pwr) override
| 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...
int16_t | transmit (const char *str, uint8_t addr=0)
| C-string transmit method. More...
virtual int16_t | transmit (uint8_t *data, size_t len, uint8_t addr=0)
| Binary transmit method. Must be implemented in module class. More...
virtual int16_t | receive (uint8_t *data, size_t len)
| Binary receive method. Must be implemented in module class. 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...
virtual int16_t | startTransmit (uint8_t *data, size_t len, uint8_t addr=0)
| Interrupt-driven binary transmit method. More...
virtual int16_t | readData (uint8_t *data, size_t len)
| Reads data that was received after calling startReceive method. More...
Public Member Functions inherited from PhysicalLayer
| PhysicalLayer (float step, size_t maxLen)
| Default constructor. More...
int16_t | transmit (const char *str, uint8_t addr=0)
| C-string transmit method. 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...
virtual int16_t | invertIQ (bool enable)
| Set IQ inversion. Must be implemented in module class if the module supports it. More...
virtual int16_t | checkOutputPower (int8_t power, int8_t *clipped)
| Check if output power is configurable. Must be implemented in module class if the module supports it. More...
virtual int16_t | setSyncWord (uint8_t *sync, size_t len)
| Set sync word. Must be implemented in module class if the module supports it. More...
virtual int16_t | setPreambleLength (size_t len)
| Set preamble length. Must be implemented in module class if the module supports it. More...
virtual int16_t | setDataRate (DataRate_t dr)
| Set data. Must be implemented in module class if the module supports it. More...
virtual int16_t | checkDataRate (DataRate_t dr)
| Check the data rate can be configured by this module. Must be implemented in module class if the module supports it. More...
float | getFreqStep () const
| Gets the module frequency step size that was set in constructor. More...
virtual float | getRSSI ()
| Gets RSSI (Recorded Signal Strength Indicator) of the last received packet. More...
virtual float | getSNR ()
| Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa modem. More...
virtual RadioLibTime_t | getTimeOnAir (size_t len)
| Get expected time-on-air for a given size of payload. More...
virtual RadioLibTime_t | calculateRxTimeout (RadioLibTime_t timeoutUs)
| Calculate the timeout value for this specific module / series (in number of symbols or units of time) More...
virtual int16_t | irqRxDoneRxTimeout (uint32_t &irqFlags, uint32_t &irqMask)
| Create the flags that make up RxDone and RxTimeout used for receiving downlinks. More...
virtual bool | isRxTimeout ()
| Check whether the IRQ bit for RxTimeout is set. More...
virtual int16_t | startChannelScan ()
| Interrupt-driven channel activity detection method. interrupt will be activated when packet is detected. Must be implemented in module class. More...
virtual int16_t | getChannelScanResult ()
| Read the channel scan result. More...
virtual int16_t | scanChannel ()
| Check whether the current communication channel is free or occupied. Performs CAD for LoRa modules, or RSSI measurement for FSK modules. 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...
virtual uint8_t | randomByte ()
| Get one truly random byte from RSSI noise. Must be implemented in module class. 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...
int16_t | setDirectSyncWord (uint32_t syncWord, uint8_t len)
| Set sync word to be used to determine start of packet in direct reception mode. More...
virtual void | setDirectAction (void(*func)(void))
| Set interrupt service routine function to call when data bit is received in direct mode. Must be implemented in module class. More...
virtual void | readBit (uint32_t pin)
| Function to read and process data bit in direct reception mode. Must be implemented in module class. More...
int16_t | available ()
| Get the number of direct mode bytes currently available in buffer. More...
void | dropSync ()
| Forcefully drop synchronization.
uint8_t | read (bool drop=true)
| Get data from direct mode buffer. More...
virtual int16_t | setDIOMapping (uint32_t pin, uint32_t value)
| Configure DIO pin mapping to get a given signal on a DIO pin (if available). More...
virtual void | setChannelScanAction (void(*func)(void))
| Sets interrupt service routine to call when a channel scan is finished. More...
virtual void | clearChannelScanAction ()
| Clears interrupt service routine to call when a channel scan is finished.

## Detailed Description

Control class for nRF24 module.

## Constructor & Destructor Documentation

## nRF24()

nRF24::nRF24 | ( | Module * | mod | ) |

Default constructor.

Parameters

  mod | Instance of Module that will be used to communicate with the radio.

## Member Function Documentation

## begin()

int16_t nRF24::begin | ( | int16_t | freq = `RADIOLIB_NRF24_DEFAULT_FREQ`,
|  | int16_t | dr = `RADIOLIB_NRF24_DEFAULT_DR`,
|  | int8_t | pwr = `RADIOLIB_NRF24_DEFAULT_POWER`,
|  | uint8_t | addrWidth = `RADIOLIB_NRF24_DEFAULT_ADDRWIDTH`
| ) |  |

Initialization method.

Parameters

  freq | Carrier frequency in MHz. Defaults to 2400 MHz.
  dr | Data rate to be used in kbps. Defaults to 1000 kbps.
  pwr | Output power in dBm. Defaults to -12 dBm.
  addrWidth | Address width in bytes. Defaults to 5 bytes.

Returns
  Status Codes

## disablePipe()

int16_t nRF24::disablePipe | ( | uint8_t | pipeNum | ) |

Disables specified receive pipe.

Parameters

  pipeNum | Receive pipe to be disabled.

Returns
  Status Codes

## finishTransmit()

int16_t nRF24::finishTransmit | ( |  | ) |

overridevirtual

Clean up after transmission is done.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## getPacketLength()

size_t nRF24::getPacketLength | ( | bool | update = `true` | ) |

overridevirtual

Query modem for the packet length of received payload.

Parameters

  update | Update received packet length. Will return cached value when set to false.

Returns
  Length of last received packet in bytes.

Reimplemented from PhysicalLayer.

## getStatus()

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

Gets nRF24 status register.

Parameters

  mask | Bit 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.

## readData() [1/2]

int16_t PhysicalLayer::readData

Reads data that was received after calling startReceive method.

Parameters

  data | Pointer to array to save the received binary data.
  len | Number of bytes that will be read. When set to 0, the packet length will be retrieved automatically. When more bytes than received are requested, only the number of bytes requested will be returned.

Returns
  Status Codes

## readData() [2/2]

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

overridevirtual

Reads data received after calling startReceive method. When the packet length is not known in advance, getPacketLength method must be called BEFORE calling readData!

Parameters

  data | Pointer to array to save the received binary data.
  len | Number of bytes that will be received. Must be known in advance for binary transmissions.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## receive() [1/2]

int16_t PhysicalLayer::receive

Binary receive method. Must be implemented in module class.

Parameters

  data | Pointer to array to save the received binary data.
  len | Number of bytes that will be received. Must be known in advance for binary transmissions.

Returns
  Status Codes

## receive() [2/2]

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

  data | Binary data to be sent.
  len | Number of bytes to send.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## receiveDirect()

int16_t nRF24::receiveDirect | ( |  | ) |

overridevirtual

Dummy direct mode reception method, to ensure PhysicalLayer compatibility.

Returns
  Status Codes

Reimplemented from 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

  addrWidth | Address 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

  autoAckOn | Enable (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

  pipeNum | Number of pipe to which enable / disable auto-acks.
  autoAckOn | Enable (true) or disable (false) auto-acks.

Returns
  Status Codes

## setBitRate()

int16_t nRF24::setBitRate | ( | float | br | ) |

overridevirtual

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

Parameters

  br | Bit rate to be set in kbps.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## setCrcFiltering()

int16_t nRF24::setCrcFiltering | ( | bool | crcOn = `true` | ) |

Enable CRC filtering and generation.

Parameters

  crcOn | Set or unset CRC check.

Returns
  Status Codes

## setDataShaping()

int16_t nRF24::setDataShaping | ( | uint8_t | sh | ) |

overridevirtual

Dummy data shaping configuration method, to ensure PhysicalLayer compatibility.

Parameters

  sh | Ignored.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## setEncoding()

int16_t nRF24::setEncoding | ( | uint8_t | encoding | ) |

overridevirtual

Dummy encoding configuration method, to ensure PhysicalLayer compatibility.

Parameters

  encoding | Ignored.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## setFrequency()

int16_t nRF24::setFrequency | ( | float | freq | ) |

overridevirtual

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

Parameters

  freq | Carrier frequency to be set in MHz.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## setFrequencyDeviation()

int16_t nRF24::setFrequencyDeviation | ( | float | freqDev | ) |

overridevirtual

Dummy configuration method, to ensure PhysicalLayer compatibility.

Parameters

  freqDev | Dummy frequency deviation parameter, no configuration will be changed.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## setIrqAction()

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

Sets interrupt service routine to call when IRQ activates.

Parameters

  func | ISR to call.

## setOutputPower()

int16_t nRF24::setOutputPower | ( | int8_t | pwr | ) |

overridevirtual

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

Parameters

  pwr | Output power to be set in dBm.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## setPacketReceivedAction()

void nRF24::setPacketReceivedAction | ( | void(*)(void) | func | ) |

overridevirtual

Sets interrupt service routine to call when a packet is received.

Parameters

  func | ISR to call.

Reimplemented from PhysicalLayer.

## setPacketSentAction()

void nRF24::setPacketSentAction | ( | void(*)(void) | func | ) |

overridevirtual

Sets interrupt service routine to call when a packet is sent.

Parameters

  func | ISR to call.

Reimplemented from PhysicalLayer.

## 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

  pipeNum | Number of pipe to which the address shall be set. Either 0 or 1, other pipes are handled using overloaded method.
  addr | Address 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

  pipeNum | Number of pipe to which the address shall be set. Allowed values range from 2 to 5.
  addrByte | LSB 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

  addr | Address to which the next packet shall be transmitted.

Returns
  Status Codes

## sleep()

int16_t nRF24::sleep | ( |  | ) |

overridevirtual

Sets the module to sleep mode.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## standby() [1/2]

int16_t nRF24::standby | ( |  | ) |

overridevirtual

Sets the module to standby mode.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## standby() [2/2]

int16_t nRF24::standby | ( | uint8_t | mode | ) |

overridevirtual

Sets the module to standby.

Parameters

  mode | Standby mode to be used.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## startReceive() [1/2]

int16_t nRF24::startReceive | ( |  | ) |

overridevirtual

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

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## startReceive() [2/2]

int16_t nRF24::startReceive | ( | uint32_t | timeout,
|  | uint32_t | irqFlags,
|  | uint32_t | irqMask,
|  | size_t | len
| ) |  |

overridevirtual

Interrupt-driven receive method, implemented for compatibility with PhysicalLayer.

Parameters

  timeout | Ignored.
  irqFlags | Ignored.
  irqMask | Ignored.
  len | Ignored.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## startTransmit() [1/3]

int16_t PhysicalLayer::startTransmit

Interrupt-driven Arduino String transmit method. Unlike the standard transmit method, this one is non-blocking. Interrupt pin will be activated when transmission finishes.

Parameters

  str | C-string that will be transmitted.
  addr | Node address to transmit the packet to. Only used in FSK mode.

Returns
  Status Codes

## startTransmit() [2/3]

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

  data | Binary data to be sent.
  len | Number of bytes to send.
  addr | Dummy address parameter, to ensure PhysicalLayer compatibility.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## startTransmit() [3/3]

int16_t PhysicalLayer::startTransmit

Interrupt-driven binary transmit method.

Parameters

  data | Binary data that will be transmitted.
  len | Length of binary data to transmit (in bytes).
  addr | Node address to transmit the packet to. Only used in FSK mode.

Returns
  Status Codes

## transmit() [1/3]

int16_t PhysicalLayer::transmit

C-string transmit method.

Parameters

  str | C-string that will be transmitted.
  addr | Node address to transmit the packet to. Only used in FSK mode.

Returns
  Status Codes

## transmit() [2/3]

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

  data | Binary data to be sent.
  len | Number of bytes to send.
  addr | Dummy address parameter, to ensure PhysicalLayer compatibility.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## transmit() [3/3]

int16_t PhysicalLayer::transmit

Binary transmit method. Must be implemented in module class.

Parameters

  data | Binary data that will be transmitted.
  len | Length of binary data to transmit (in bytes).
  addr | Node address to transmit the packet to. Only used in FSK mode.

Returns
  Status Codes

## transmitDirect()

int16_t nRF24::transmitDirect | ( | uint32_t | frf = `0` | ) |

overridevirtual

Starts direct mode transmission.

Parameters

  frf | Raw RF frequency value. Defaults to 0, required for quick frequency shifts in RTTY.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

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

- src/modules/nRF24/nRF24.h
- src/modules/nRF24/nRF24.cpp