10 #include <RHGenericSPI.h>
11 #include <RHNRFSPIDriver.h>
15 #define RH_NRF24_MAX_PAYLOAD_LEN 32
19 #define RH_NRF24_HEADER_LEN 4
23 #define RH_NRF24_MAX_MESSAGE_LEN (RH_NRF24_MAX_PAYLOAD_LEN-RH_NRF24_HEADER_LEN)
26 #define RH_NRF24_COMMAND_R_REGISTER 0x00
27 #define RH_NRF24_COMMAND_W_REGISTER 0x20
28 #define RH_NRF24_COMMAND_ACTIVATE 0x50 // only on RFM73 ?
29 #define RH_NRF24_COMMAND_R_RX_PAYLOAD 0x61
30 #define RH_NRF24_COMMAND_W_TX_PAYLOAD 0xa0
31 #define RH_NRF24_COMMAND_FLUSH_TX 0xe1
32 #define RH_NRF24_COMMAND_FLUSH_RX 0xe2
33 #define RH_NRF24_COMMAND_REUSE_TX_PL 0xe3
34 #define RH_NRF24_COMMAND_R_RX_PL_WID 0x60
35 #define RH_NRF24_COMMAND_W_ACK_PAYLOAD(pipe) (0xa8|(pipe&0x7))
36 #define RH_NRF24_COMMAND_W_TX_PAYLOAD_NOACK 0xb0
37 #define RH_NRF24_COMMAND_NOP 0xff
40 #define RH_NRF24_REGISTER_MASK 0x1f
41 #define RH_NRF24_REG_00_CONFIG 0x00
42 #define RH_NRF24_REG_01_EN_AA 0x01
43 #define RH_NRF24_REG_02_EN_RXADDR 0x02
44 #define RH_NRF24_REG_03_SETUP_AW 0x03
45 #define RH_NRF24_REG_04_SETUP_RETR 0x04
46 #define RH_NRF24_REG_05_RF_CH 0x05
47 #define RH_NRF24_REG_06_RF_SETUP 0x06
48 #define RH_NRF24_REG_07_STATUS 0x07
49 #define RH_NRF24_REG_08_OBSERVE_TX 0x08
50 #define RH_NRF24_REG_09_RPD 0x09
51 #define RH_NRF24_REG_0A_RX_ADDR_P0 0x0a
52 #define RH_NRF24_REG_0B_RX_ADDR_P1 0x0b
53 #define RH_NRF24_REG_0C_RX_ADDR_P2 0x0c
54 #define RH_NRF24_REG_0D_RX_ADDR_P3 0x0d
55 #define RH_NRF24_REG_0E_RX_ADDR_P4 0x0e
56 #define RH_NRF24_REG_0F_RX_ADDR_P5 0x0f
57 #define RH_NRF24_REG_10_TX_ADDR 0x10
58 #define RH_NRF24_REG_11_RX_PW_P0 0x11
59 #define RH_NRF24_REG_12_RX_PW_P1 0x12
60 #define RH_NRF24_REG_13_RX_PW_P2 0x13
61 #define RH_NRF24_REG_14_RX_PW_P3 0x14
62 #define RH_NRF24_REG_15_RX_PW_P4 0x15
63 #define RH_NRF24_REG_16_RX_PW_P5 0x16
64 #define RH_NRF24_REG_17_FIFO_STATUS 0x17
65 #define RH_NRF24_REG_1C_DYNPD 0x1c
66 #define RH_NRF24_REG_1D_FEATURE 0x1d
71 #define RH_NRF24_MASK_RX_DR 0x40
72 #define RH_NRF24_MASK_TX_DS 0x20
73 #define RH_NRF24_MASK_MAX_RT 0x10
74 #define RH_NRF24_EN_CRC 0x08
75 #define RH_NRF24_CRCO 0x04
76 #define RH_NRF24_PWR_UP 0x02
77 #define RH_NRF24_PRIM_RX 0x01
80 #define RH_NRF24_ENAA_P5 0x20
81 #define RH_NRF24_ENAA_P4 0x10
82 #define RH_NRF24_ENAA_P3 0x08
83 #define RH_NRF24_ENAA_P2 0x04
84 #define RH_NRF24_ENAA_P1 0x02
85 #define RH_NRF24_ENAA_P0 0x01
88 #define RH_NRF24_ERX_P5 0x20
89 #define RH_NRF24_ERX_P4 0x10
90 #define RH_NRF24_ERX_P3 0x08
91 #define RH_NRF24_ERX_P2 0x04
92 #define RH_NRF24_ERX_P1 0x02
93 #define RH_NRF24_ERX_P0 0x01
96 #define RH_NRF24_AW_3_BYTES 0x01
97 #define RH_NRF24_AW_4_BYTES 0x02
98 #define RH_NRF24_AW_5_BYTES 0x03
101 #define RH_NRF24_ARD 0xf0
102 #define RH_NRF24_ARC 0x0f
105 #define RH_NRF24_RF_CH 0x7f
108 #define RH_NRF24_CONT_WAVE 0x80
109 #define RH_NRF24_RF_DR_LOW 0x20
110 #define RH_NRF24_PLL_LOCK 0x10
111 #define RH_NRF24_RF_DR_HIGH 0x08
112 #define RH_NRF24_PWR 0x06
113 #define RH_NRF24_PWR_m18dBm 0x00
114 #define RH_NRF24_PWR_m12dBm 0x02
115 #define RH_NRF24_PWR_m6dBm 0x04
116 #define RH_NRF24_PWR_0dBm 0x06
117 #define RH_NRF24_LNA_HCURR 0x01
120 #define RH_NRF24_RX_DR 0x40
121 #define RH_NRF24_TX_DS 0x20
122 #define RH_NRF24_MAX_RT 0x10
123 #define RH_NRF24_RX_P_NO 0x0e
124 #define RH_NRF24_STATUS_TX_FULL 0x01
127 #define RH_NRF24_PLOS_CNT 0xf0
128 #define RH_NRF24_ARC_CNT 0x0f
131 #define RH_NRF24_RPD 0x01
134 #define RH_NRF24_TX_REUSE 0x40
135 #define RH_NRF24_TX_FULL 0x20
136 #define RH_NRF24_TX_EMPTY 0x10
137 #define RH_NRF24_RX_FULL 0x02
138 #define RH_NRF24_RX_EMPTY 0x01
141 #define RH_NRF24_DPL_ALL 0x3f
142 #define RH_NRF24_DPL_P5 0x20
143 #define RH_NRF24_DPL_P4 0x10
144 #define RH_NRF24_DPL_P3 0x08
145 #define RH_NRF24_DPL_P2 0x04
146 #define RH_NRF24_DPL_P1 0x02
147 #define RH_NRF24_DPL_P0 0x01
150 #define RH_NRF24_EN_DPL 0x04
151 #define RH_NRF24_EN_ACK_PAY 0x02
152 #define RH_NRF24_EN_DYN_ACK 0x01
459 RH_NRF24(uint8_t chipEnablePin = 8, uint8_t slaveSelectPin = SS,
RHGenericSPI& spi = hardware_spi);
555 bool send(
const uint8_t* data, uint8_t len);
588 bool recv(uint8_t* buf, uint8_t* len);
599 virtual bool sleep();
618 uint8_t _configuration;
621 uint8_t _chipEnablePin;
627 uint8_t _buf[RH_NRF24_MAX_PAYLOAD_LEN];
volatile uint16_t _rxGood
Count of the number of successfully transmitted messaged.
Definition: RHGenericDriver.h:292
@ TransmitPower0dBm
On nRF24, 0 dBm.
Definition: RH_NRF24.h:438
bool setChannel(uint8_t channel)
Definition: RH_NRF24.cpp:98
uint8_t spiReadRegister(uint8_t reg)
Definition: RH_NRF24.cpp:62
bool recv(uint8_t *buf, uint8_t *len)
Definition: RH_NRF24.cpp:331
uint8_t spiCommand(uint8_t command)
Definition: RHNRFSPIDriver.cpp:31
uint8_t flushRx()
Definition: RH_NRF24.cpp:93
Base class for SPI interfaces.
Definition: RHGenericSPI.h:30
bool setOpMode(uint8_t mode)
Definition: RH_NRF24.cpp:104
uint8_t spiRead(uint8_t reg)
Definition: RHNRFSPIDriver.cpp:48
@ RFM73TransmitPowerm10dBm
On RFM73, -10 dBm.
Definition: RH_NRF24.h:442
void setModeRx()
Definition: RH_NRF24.cpp:163
@ RFM73TransmitPower5dBm
On RFM73, 5 dBm. 20dBm on RFM73P-S2 ?
Definition: RH_NRF24.h:445
bool isSending()
Definition: RH_NRF24.cpp:236
volatile uint8_t _rxHeaderFrom
FROM header in the last received mesasge.
Definition: RHGenericDriver.h:265
virtual void setFrequency(Frequency frequency)
Definition: RHGenericSPI.cpp:27
bool printRegisters()
Definition: RH_NRF24.cpp:242
bool send(const uint8_t *data, uint8_t len)
Definition: RH_NRF24.cpp:188
virtual bool waitPacketSent()
Definition: RH_NRF24.cpp:209
@ TransmitPowerm18dBm
On nRF24, -18 dBm.
Definition: RH_NRF24.h:435
volatile uint8_t _rxHeaderTo
TO header in the last received mesasge.
Definition: RHGenericDriver.h:262
TransmitPower
Convenient values for setting transmitter power in setRF() These are designed to agree with the value...
Definition: RH_NRF24.h:432
uint8_t _txHeaderFrom
FROM header to send in all messages.
Definition: RHGenericDriver.h:277
@ TransmitPowerm6dBm
On nRF24, -6 dBm.
Definition: RH_NRF24.h:437
bool setNetworkAddress(uint8_t *address, uint8_t len)
Definition: RH_NRF24.cpp:110
uint8_t _thisAddress
This node id.
Definition: RHGenericDriver.h:256
volatile uint16_t _txGood
Count of the number of bad messages (correct checksum etc) received.
Definition: RHGenericDriver.h:295
Send and receive unaddressed, unreliable datagrams by nRF24L01 and compatible transceivers.
Definition: RH_NRF24.h:417
bool init()
Definition: RHNRFSPIDriver.cpp:15
bool _promiscuous
Whether the transport is in promiscuous mode.
Definition: RHGenericDriver.h:259
uint8_t spiBurstWrite(uint8_t reg, const uint8_t *src, uint8_t len)
Definition: RHNRFSPIDriver.cpp:109
volatile uint8_t _rxHeaderFlags
FLAGS header in the last received mesasge.
Definition: RHGenericDriver.h:271
uint8_t statusRead()
Definition: RH_NRF24.cpp:82
@ DataRate250kbps
250 kbps
Definition: RH_NRF24.h:426
bool init()
Definition: RH_NRF24.cpp:17
@ RHModeSleep
Transport hardware is in low power sleep mode (if supported)
Definition: RHGenericDriver.h:51
@ TransmitPowerm12dBm
On nRF24, -12 dBm.
Definition: RH_NRF24.h:436
void validateRxBuf()
Examine the receive buffer to determine whether the message is for this node.
Definition: RH_NRF24.cpp:276
void clearRxBuf()
Clear our local receive buffer.
Definition: RH_NRF24.cpp:325
uint8_t maxMessageLength()
Definition: RH_NRF24.cpp:346
@ RFM73TransmitPowerm5dBm
On RFM73, -5 dBm.
Definition: RH_NRF24.h:443
uint8_t _txHeaderId
ID header to send in all messages.
Definition: RHGenericDriver.h:280
uint8_t _txHeaderTo
TO header to send in all messages.
Definition: RHGenericDriver.h:274
bool setRF(DataRate data_rate, TransmitPower power)
Definition: RH_NRF24.cpp:122
uint8_t spiBurstWriteRegister(uint8_t reg, uint8_t *src, uint8_t len)
Definition: RH_NRF24.cpp:77
@ DataRate2Mbps
2 Mbps
Definition: RH_NRF24.h:425
uint8_t _txHeaderFlags
FLAGS header to send in all messages.
Definition: RHGenericDriver.h:283
DataRate
Defines convenient values for setting data rates in setRF()
Definition: RH_NRF24.h:422
Base class for RadioHead drivers that use the SPI bus to communicate with its NRF family transport ha...
Definition: RHNRFSPIDriver.h:33
uint8_t spiBurstReadRegister(uint8_t reg, uint8_t *dest, uint8_t len)
Definition: RH_NRF24.cpp:72
uint8_t spiWrite(uint8_t reg, uint8_t val)
Definition: RHNRFSPIDriver.cpp:66
@ RFM73TransmitPowerm0dBm
On RFM73, 0 dBm.
Definition: RH_NRF24.h:444
volatile uint8_t _rxHeaderId
ID header in the last received mesasge.
Definition: RHGenericDriver.h:268
void setModeIdle()
Definition: RH_NRF24.cpp:141
uint8_t flushTx()
Definition: RH_NRF24.cpp:88
uint8_t spiWriteRegister(uint8_t reg, uint8_t val)
Definition: RH_NRF24.cpp:67
uint8_t spiBurstRead(uint8_t reg, uint8_t *dest, uint8_t len)
Definition: RHNRFSPIDriver.cpp:90
@ RHModeIdle
Transport is idle.
Definition: RHGenericDriver.h:52
volatile RHMode _mode
The current transport operating mode.
Definition: RHGenericDriver.h:253
RH_NRF24(uint8_t chipEnablePin=8, uint8_t slaveSelectPin=SS, RHGenericSPI &spi=hardware_spi)
Definition: RH_NRF24.cpp:8
RHGenericSPI & _spi
Reference to the RHGenericSPI instance to use to trasnfer data with teh SPI device.
Definition: RHNRFSPIDriver.h:95
@ RHModeTx
Transport is in the process of transmitting a message.
Definition: RHGenericDriver.h:53
bool available()
Definition: RH_NRF24.cpp:294
virtual RHMode mode()
Definition: RHGenericDriver.cpp:159
@ DataRate1Mbps
1 Mbps
Definition: RH_NRF24.h:424
@ RHModeRx
Transport is in the process of receiving a message.
Definition: RHGenericDriver.h:54
@ Frequency1MHz
SPI bus frequency close to 1MHz.
Definition: RHGenericSPI.h:57
virtual bool waitCAD()
Definition: RHGenericDriver.cpp:72
virtual bool sleep()
Definition: RH_NRF24.cpp:151
void setModeTx()
Definition: RH_NRF24.cpp:173