1#if !defined(_RADIOLIB_NRF24_H) && !RADIOLIB_EXCLUDE_NRF24
2#define _RADIOLIB_NRF24_H
4#include "../../Module.h"
5#include "../../TypeDef.h"
7#include "../../protocols/PhysicalLayer/PhysicalLayer.h"
10#define RADIOLIB_NRF24_FREQUENCY_STEP_SIZE 1000000.0
11#define RADIOLIB_NRF24_MAX_PACKET_LENGTH 32
12#define RADIOLIB_NRF24_POUT_MIN -18
13#define RADIOLIB_NRF24_POUT_MAX 0
16#define RADIOLIB_NRF24_CMD_READ 0b00000000
17#define RADIOLIB_NRF24_CMD_WRITE 0b00100000
18#define RADIOLIB_NRF24_CMD_READ_RX_PAYLOAD 0b01100001
19#define RADIOLIB_NRF24_CMD_WRITE_TX_PAYLOAD 0b10100000
20#define RADIOLIB_NRF24_CMD_FLUSH_TX 0b11100001
21#define RADIOLIB_NRF24_CMD_FLUSH_RX 0b11100010
22#define RADIOLIB_NRF24_CMD_REUSE_TX_PAXLOAD 0b11100011
23#define RADIOLIB_NRF24_CMD_READ_RX_PAYLOAD_WIDTH 0b01100000
24#define RADIOLIB_NRF24_CMD_WRITE_ACK_PAYLOAD 0b10101000
25#define RADIOLIB_NRF24_CMD_WRITE_TX_PAYLOAD_NOACK 0b10110000
26#define RADIOLIB_NRF24_CMD_NOP 0b11111111
29#define RADIOLIB_NRF24_REG_CONFIG 0x00
30#define RADIOLIB_NRF24_REG_EN_AA 0x01
31#define RADIOLIB_NRF24_REG_EN_RXADDR 0x02
32#define RADIOLIB_NRF24_REG_SETUP_AW 0x03
33#define RADIOLIB_NRF24_REG_SETUP_RETR 0x04
34#define RADIOLIB_NRF24_REG_RF_CH 0x05
35#define RADIOLIB_NRF24_REG_RF_SETUP 0x06
36#define RADIOLIB_NRF24_REG_STATUS 0x07
37#define RADIOLIB_NRF24_REG_OBSERVE_TX 0x08
38#define RADIOLIB_NRF24_REG_RPD 0x09
39#define RADIOLIB_NRF24_REG_RX_ADDR_P0 0x0A
40#define RADIOLIB_NRF24_REG_RX_ADDR_P1 0x0B
41#define RADIOLIB_NRF24_REG_RX_ADDR_P2 0x0C
42#define RADIOLIB_NRF24_REG_RX_ADDR_P3 0x0D
43#define RADIOLIB_NRF24_REG_RX_ADDR_P4 0x0E
44#define RADIOLIB_NRF24_REG_RX_ADDR_P5 0x0F
45#define RADIOLIB_NRF24_REG_TX_ADDR 0x10
46#define RADIOLIB_NRF24_REG_RX_PW_P0 0x11
47#define RADIOLIB_NRF24_REG_RX_PW_P1 0x12
48#define RADIOLIB_NRF24_REG_RX_PW_P2 0x13
49#define RADIOLIB_NRF24_REG_RX_PW_P3 0x14
50#define RADIOLIB_NRF24_REG_RX_PW_P4 0x15
51#define RADIOLIB_NRF24_REG_RX_PW_P5 0x16
52#define RADIOLIB_NRF24_REG_FIFO_STATUS 0x17
53#define RADIOLIB_NRF24_REG_DYNPD 0x1C
54#define RADIOLIB_NRF24_REG_FEATURE 0x1D
57#define RADIOLIB_NRF24_MASK_RX_DR_IRQ_OFF 0b01000000
58#define RADIOLIB_NRF24_MASK_RX_DR_IRQ_ON 0b00000000
59#define RADIOLIB_NRF24_MASK_TX_DS_IRQ_OFF 0b00100000
60#define RADIOLIB_NRF24_MASK_TX_DS_IRQ_ON 0b00000000
61#define RADIOLIB_NRF24_MASK_MAX_RT_IRQ_OFF 0b00010000
62#define RADIOLIB_NRF24_MASK_MAX_RT_IRQ_ON 0b00000000
63#define RADIOLIB_NRF24_CRC_OFF 0b00000000
64#define RADIOLIB_NRF24_CRC_ON 0b00001000
65#define RADIOLIB_NRF24_CRC_8 0b00000000
66#define RADIOLIB_NRF24_CRC_16 0b00000100
67#define RADIOLIB_NRF24_POWER_UP 0b00000010
68#define RADIOLIB_NRF24_POWER_DOWN 0b00000000
69#define RADIOLIB_NRF24_PTX 0b00000000
70#define RADIOLIB_NRF24_PRX 0b00000001
73#define RADIOLIB_NRF24_AA_ALL_OFF 0b00000000
74#define RADIOLIB_NRF24_AA_ALL_ON 0b00111111
75#define RADIOLIB_NRF24_AA_P5_OFF 0b00000000
76#define RADIOLIB_NRF24_AA_P5_ON 0b00100000
77#define RADIOLIB_NRF24_AA_P4_OFF 0b00000000
78#define RADIOLIB_NRF24_AA_P4_ON 0b00010000
79#define RADIOLIB_NRF24_AA_P3_OFF 0b00000000
80#define RADIOLIB_NRF24_AA_P3_ON 0b00001000
81#define RADIOLIB_NRF24_AA_P2_OFF 0b00000000
82#define RADIOLIB_NRF24_AA_P2_ON 0b00000100
83#define RADIOLIB_NRF24_AA_P1_OFF 0b00000000
84#define RADIOLIB_NRF24_AA_P1_ON 0b00000010
85#define RADIOLIB_NRF24_AA_P0_OFF 0b00000000
86#define RADIOLIB_NRF24_AA_P0_ON 0b00000001
89#define RADIOLIB_NRF24_P5_OFF 0b00000000
90#define RADIOLIB_NRF24_P5_ON 0b00100000
91#define RADIOLIB_NRF24_P4_OFF 0b00000000
92#define RADIOLIB_NRF24_P4_ON 0b00010000
93#define RADIOLIB_NRF24_P3_OFF 0b00000000
94#define RADIOLIB_NRF24_P3_ON 0b00001000
95#define RADIOLIB_NRF24_P2_OFF 0b00000000
96#define RADIOLIB_NRF24_P2_ON 0b00000100
97#define RADIOLIB_NRF24_P1_OFF 0b00000000
98#define RADIOLIB_NRF24_P1_ON 0b00000010
99#define RADIOLIB_NRF24_P0_OFF 0b00000000
100#define RADIOLIB_NRF24_P0_ON 0b00000001
103#define RADIOLIB_NRF24_ADDRESS_2_BYTES 0b00000000
104#define RADIOLIB_NRF24_ADDRESS_3_BYTES 0b00000001
105#define RADIOLIB_NRF24_ADDRESS_4_BYTES 0b00000010
106#define RADIOLIB_NRF24_ADDRESS_5_BYTES 0b00000011
109#define RADIOLIB_NRF24_ARD 0b00000000
110#define RADIOLIB_NRF24_ARC_OFF 0b00000000
111#define RADIOLIB_NRF24_ARC 0b00000011
114#define RADIOLIB_NRF24_RF_CH 0b00000010
117#define RADIOLIB_NRF24_CONT_WAVE_OFF 0b00000000
118#define RADIOLIB_NRF24_CONT_WAVE_ON 0b10000000
119#define RADIOLIB_NRF24_DR_250_KBPS 0b00100000
120#define RADIOLIB_NRF24_DR_1_MBPS 0b00000000
121#define RADIOLIB_NRF24_DR_2_MBPS 0b00001000
122#define RADIOLIB_NRF24_PLL_LOCK_ON 0b00010000
123#define RADIOLIB_NRF24_PLL_LOCK_OFF 0b00000000
124#define RADIOLIB_NRF24_RF_PWR_18_DBM 0b00000000
125#define RADIOLIB_NRF24_RF_PWR_12_DBM 0b00000010
126#define RADIOLIB_NRF24_RF_PWR_6_DBM 0b00000100
127#define RADIOLIB_NRF24_RF_PWR_0_DBM 0b00000110
128#define RADIOLIB_NRF24_RF_LNA_OFF 0b00000000
129#define RADIOLIB_NRF24_RF_LNA_ON 0b00000001
132#define RADIOLIB_NRF24_RX_DR 0b01000000
133#define RADIOLIB_NRF24_TX_DS 0b00100000
134#define RADIOLIB_NRF24_MAX_RT 0b00010000
135#define RADIOLIB_NRF24_RX_FIFO_EMPTY 0b00001110
136#define RADIOLIB_NRF24_RX_P_NO 0b00000000
137#define RADIOLIB_NRF24_TX_FIFO_FULL 0b00000001
140#define RADIOLIB_NRF24_PLOS_CNT 0b00000000
141#define RADIOLIB_NRF24_ARC_CNT 0b00000000
144#define RADIOLIB_NRF24_RP_BELOW_64_DBM 0b00000000
145#define RADIOLIB_NRF24_RP_ABOVE_64_DBM 0b00000001
148#define RADIOLIB_NRF24_TX_REUSE 0b01000000
149#define RADIOLIB_NRF24_TX_FIFO_FULL_FLAG 0b00100000
150#define RADIOLIB_NRF24_TX_FIFO_EMPTY_FLAG 0b00010000
151#define RADIOLIB_NRF24_RX_FIFO_FULL_FLAG 0b00000010
152#define RADIOLIB_NRF24_RX_FIFO_EMPTY_FLAG 0b00000001
155#define RADIOLIB_NRF24_DPL_P5_OFF 0b00000000
156#define RADIOLIB_NRF24_DPL_P5_ON 0b00100000
157#define RADIOLIB_NRF24_DPL_P4_OFF 0b00000000
158#define RADIOLIB_NRF24_DPL_P4_ON 0b00010000
159#define RADIOLIB_NRF24_DPL_P3_OFF 0b00000000
160#define RADIOLIB_NRF24_DPL_P3_ON 0b00001000
161#define RADIOLIB_NRF24_DPL_P2_OFF 0b00000000
162#define RADIOLIB_NRF24_DPL_P2_ON 0b00000100
163#define RADIOLIB_NRF24_DPL_P1_OFF 0b00000000
164#define RADIOLIB_NRF24_DPL_P1_ON 0b00000010
165#define RADIOLIB_NRF24_DPL_P0_OFF 0b00000000
166#define RADIOLIB_NRF24_DPL_P0_ON 0b00000001
167#define RADIOLIB_NRF24_DPL_ALL_OFF 0b00000000
168#define RADIOLIB_NRF24_DPL_ALL_ON 0b00111111
171#define RADIOLIB_NRF24_DPL_OFF 0b00000000
172#define RADIOLIB_NRF24_DPL_ON 0b00000100
173#define RADIOLIB_NRF24_ACK_PAY_OFF 0b00000000
174#define RADIOLIB_NRF24_ACK_PAY_ON 0b00000010
175#define RADIOLIB_NRF24_DYN_ACK_OFF 0b00000000
176#define RADIOLIB_NRF24_DYN_ACK_ON 0b00000001
179#define RADIOLIB_NRF24_DEFAULT_FREQ 2400
180#define RADIOLIB_NRF24_DEFAULT_DR 1000
181#define RADIOLIB_NRF24_DEFAULT_POWER -12
182#define RADIOLIB_NRF24_DEFAULT_ADDRWIDTH 5
223 int16_t
sleep()
override;
236 int16_t
standby(uint8_t mode)
override;
246 int16_t
transmit(
const uint8_t* data,
size_t len, uint8_t addr)
override;
282 int16_t
startTransmit(
const uint8_t* data,
size_t len, uint8_t addr)
override;
298 int16_t
startReceive(uint32_t timeout, uint32_t irqFlags, uint32_t irqMask,
size_t len)
override;
307 int16_t
readData(uint8_t* data,
size_t len)
override;
426 int16_t
setAutoAck(uint8_t pipeNum,
bool autoAckOn);
448 int16_t
setLNA(
bool enable);
450#if !RADIOLIB_GODMODE && !RADIOLIB_LOW_LEVEL
453 Module* getMod()
override;
455 void SPIreadRxPayload(uint8_t* data, uint8_t numBytes);
456 void SPIwriteTxPayload(
const uint8_t* data, uint8_t numBytes);
457 void SPItransfer(uint8_t cmd,
bool write =
false,
const uint8_t* dataOut = NULL, uint8_t* dataIn = NULL, uint8_t numBytes = 0);
464 int16_t frequency = RADIOLIB_NRF24_DEFAULT_FREQ;
465 int16_t dataRate = RADIOLIB_NRF24_DEFAULT_DR;
466 int8_t power = RADIOLIB_NRF24_DEFAULT_POWER;
Implements all common low-level methods to control the wireless module. Every module class contains o...
Definition Module.h:74
virtual int16_t readData(uint8_t *data, size_t len)
Reads data that was received after calling startReceive method.
Definition PhysicalLayer.cpp:235
int16_t transmit(const char *str, uint8_t addr=0)
C-string transmit method.
Definition PhysicalLayer.cpp:53
int16_t startTransmit(const char *str, uint8_t addr=0)
Interrupt-driven Arduino String transmit method. Unlike the standard transmit method,...
Definition PhysicalLayer.cpp:157
virtual int16_t receive(uint8_t *data, size_t len, RadioLibTime_t timeout=0)
Binary receive method. Must be implemented in module class.
Definition PhysicalLayer.cpp:111
PhysicalLayer()
Default constructor.
Definition PhysicalLayer.cpp:5
int16_t setEncoding(uint8_t encoding) override
Dummy encoding configuration method, to ensure PhysicalLayer compatibility.
Definition nRF24.cpp:540
int16_t finishReceive() override
Clean up after reception is done.
Definition nRF24.cpp:258
int16_t transmitDirect(uint32_t frf=0) override
Starts direct mode transmission.
Definition nRF24.cpp:145
int16_t setDataShaping(uint8_t sh) override
Dummy data shaping configuration method, to ensure PhysicalLayer compatibility.
Definition nRF24.cpp:533
size_t getPacketLength(bool update=true) override
Query modem for the packet length of received payload.
Definition nRF24.cpp:486
int16_t startReceive() override
Interrupt-driven receive method. IRQ will be activated when full packet is received.
Definition nRF24.cpp:206
int16_t setCrcFiltering(bool crcOn=true)
Enable CRC filtering and generation.
Definition nRF24.cpp:493
int16_t getStatus(uint8_t mask=0xFF)
Gets nRF24 status register.
Definition nRF24.cpp:471
int16_t receive(uint8_t *data, size_t len, RadioLibTime_t timeout=0) override
Binary receive method. Will attempt to receive arbitrary binary data up to 64 bytes long....
Definition nRF24.cpp:118
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...
Definition nRF24.cpp:240
int16_t receiveDirect() override
Dummy direct mode reception method, to ensure PhysicalLayer compatibility.
Definition nRF24.cpp:160
int16_t begin(const ConfigFSK_t &config)
Initialization method for FSK modem.
Definition nRF24.cpp:14
int16_t disablePipe(uint8_t pipeNum)
Disables specified receive pipe.
Definition nRF24.cpp:440
int16_t setOutputPower(int8_t pwr) override
Sets output power. Allowed values are -18, -12, -6 or 0 dBm.
Definition nRF24.cpp:306
int16_t standby() override
Sets the module to standby mode.
Definition nRF24.cpp:78
int16_t setAddressWidth(uint8_t addrWidth)
Sets address width of transmit and receive pipes in bytes. Allowed values are 3, 4 or 5 bytes.
Definition nRF24.cpp:340
int16_t setLNA(bool enable)
Enable or disable the low-noise amplifier. Improves receive performance at the cost of increased powe...
Definition nRF24.cpp:547
int16_t sleep() override
Sets the module to sleep mode.
Definition nRF24.cpp:74
int16_t setFrequency(uint32_t freq) override
Sets carrier frequency. Allowed values range from 2400 MHz to 2525 MHz.
Definition nRF24.cpp:266
int16_t startTransmit(const uint8_t *data, size_t len, uint8_t addr) override
Interrupt-driven binary transmit method. IRQ will be activated when full packet is transmitted....
Definition nRF24.cpp:166
int16_t setBitRate(uint32_t br) override
Sets bit rate. Allowed values are 2000, 1000 or 250 kbps.
Definition nRF24.cpp:279
int16_t setTransmitPipe(const uint8_t *addr)
Sets address of transmit pipe. The address width must be the same as the same as the configured in se...
Definition nRF24.cpp:373
int16_t setFrequencyDeviation(uint32_t freqDev) override
Dummy configuration method, to ensure PhysicalLayer compatibility.
Definition nRF24.cpp:479
nRF24(Module *mod)
Default constructor.
Definition nRF24.cpp:5
int16_t setReceivePipe(uint8_t pipeNum, const uint8_t *addr)
Sets address of receive pipes 0 or 1. The address width must be the same as the same as the configure...
Definition nRF24.cpp:388
int16_t setAutoAck(bool autoAckOn=true)
Enable or disable auto-acknowledge packets on all pipes.
Definition nRF24.cpp:504
bool isCarrierDetected()
Checks if carrier was detected during last RX.
Definition nRF24.cpp:475
int16_t transmit(const uint8_t *data, size_t len, uint8_t addr) override
Blocking binary transmit method. Overloads for string-based transmissions are implemented in Physical...
Definition nRF24.cpp:92
uint8_t addressWidth
Address width in bytes. Defaults to 5 bytes.
Definition nRF24.h:206
unsigned long RadioLibTime_t
Type used for durations in RadioLib.
Definition TypeDef.h:783
Definition PhysicalLayer.h:310