nrf24L01  1.0
nrf24L01 library
 All Files Functions Variables Typedefs Enumerations Enumerator Macros
nrf24L01.h
Go to the documentation of this file.
1 
32 #ifndef __nrf24L01_H_
33 #define __nrf24L01_H_
34 
38 #define NRF_R_REGISTER 0x00
39 #define NRF_W_REGISTER 0x20
40 #define NRF_R_RX_PAYLOAD 0x61
41 #define NRF_W_TX_PAYLOAD 0xA0
42 #define NRF_FLUSH_TX 0xE1
43 #define NRF_FLUSH_RX 0xE2
44 #define NRF_REUSE_TX_PL 0xE3
45 #define NRF_ACTIVATE 0x50
46 #define NRF_R_RX_PL_WID 0x60
47 #define NRF_W_ACK_PAYLOAD 0xA8
48 #define NRF_W_TX_PAYLOAD_NO_ACK 0xB0
49 #define NRF_NOP 0xFF
50 
51 #define NRF_REGISTER_gm 0x1F
52 #define NRF_PIPE_gm 0x07
53 
57 #define REG_CONFIG 0x00
58 #define REG_EN_AA 0x01
59 #define REG_EN_RXADDR 0x02
60 #define REG_SETUP_AW 0x03
61 #define REG_SETUP_RETR 0x04
62 #define REG_RF_CH 0x05
63 #define REG_RF_SETUP 0x06
64 #define REG_STATUS 0x07
65 #define REG_OBSERVE_TX 0x08
66 #define REG_CD 0x09
67 #define REG_RPD 0x09
68 #define REG_RX_ADDR_P0 0x0A
69 #define REG_RX_ADDR_P1 0x0B
70 #define REG_RX_ADDR_P2 0x0C
71 #define REG_RX_ADDR_P3 0x0D
72 #define REG_RX_ADDR_P4 0x0E
73 #define REG_RX_ADDR_P5 0x0F
74 #define REG_TX_ADDR 0x10
75 #define REG_RX_PW_P0 0x11
76 #define REG_RX_PW_P1 0x12
77 #define REG_RX_PW_P2 0x13
78 #define REG_RX_PW_P3 0x14
79 #define REG_RX_PW_P4 0x15
80 #define REG_RX_PW_P5 0x16
81 #define REG_FIFO_STATUS 0x17
82 #define REG_DYNPD 0x1C
83 #define REG_FEATURE 0x1D
84 
85 // Definitions and typedefinitions for CONFIG register
86 #define NRF_CONFIG_MASK_RX_DR_bm (1<<6)
87 #define NRF_CONFIG_MASK_TX_DS_bm (1<<5)
88 #define NRF_CONFIG_MASK_MAX_RT_bm (1<<4)
89 #define NRF_CONFIG_EN_CRC_bm (1<<3)
90 #define NRF_CONFIG_CRC0_bm (1<<2)
91 #define NRF_CONFIG_PWR_UP_bm (1<<1)
92 #define NRF_CONFIG_PRIM_RX_bm (1<<0)
93 
94 typedef enum NRF_CONFIG_CRC_enum
95 {
100 #define NRF_CONFIG_CRC_gm ( NRF_CONFIG_EN_CRC_bm | NRF_CONFIG_CRC0_bm )
101 
102 // Definitions for EN_AA register
103 #define NRF_EN_AA_P5_bm (1<<5)
104 #define NRF_EN_AA_P4_bm (1<<4)
105 #define NRF_EN_AA_P3_bm (1<<3)
106 #define NRF_EN_AA_P2_bm (1<<2)
107 #define NRF_EN_AA_P1_bm (1<<1)
108 #define NRF_EN_AA_P0_bm (1<<0)
109 #define NRF_EN_AA_P_ALL_gm (0x3F)
110 
111 // Definitions for EN_RXADDR register
112 #define NRF_EN_RXADDR_P5_bm (1<<5)
113 #define NRF_EN_RXADDR_P4_bm (1<<4)
114 #define NRF_EN_RXADDR_P3_bm (1<<3)
115 #define NRF_EN_RXADDR_P2_bm (1<<2)
116 #define NRF_EN_RXADDR_P1_bm (1<<1)
117 #define NRF_EN_RXADDR_P0_bm (1<<0)
118 
119 // Definitions and typedefinitions for SETUP register
120 typedef enum NRF_SETUP_AW_enum
121 {
126 
127 // Definitions and typedefinitions for SETUP_RETR register
129 {
130  NRF_SETUP_ARD_250US_gc = (0x00<<4), /* 250 us */
131  NRF_SETUP_ARD_500US_gc = (0x01<<4), /* 500 us */
132  NRF_SETUP_ARD_7500US_gc = (0x02<<4), /* 750 us */
133  NRF_SETUP_ARD_1000US_gc = (0x03<<4), /* 1000 us */
134  NRF_SETUP_ARD_1250US_gc = (0x04<<4), /* 1250 us */
135  NRF_SETUP_ARD_1500US_gc = (0x05<<4), /* 1500 us */
136  NRF_SETUP_ARD_1750US_gc = (0x06<<4), /* 1750 us */
137  NRF_SETUP_ARD_2000US_gc = (0x07<<4), /* 2000 us */
138  NRF_SETUP_ARD_2250US_gc = (0x08<<4), /* 2250 us */
139  NRF_SETUP_ARD_2500US_gc = (0x09<<4), /* 2500 us */
140  NRF_SETUP_ARD_2750US_gc = (0x0A<<4), /* 2750 us */
141  NRF_SETUP_ARD_3000US_gc = (0x0B<<4), /* 3000 us */
142  NRF_SETUP_ARD_3250US_gc = (0x0C<<4), /* 3250 us */
143  NRF_SETUP_ARD_3500US_gc = (0x0D<<4), /* 3500 us */
144  NRF_SETUP_ARD_3750US_gc = (0x0E<<4), /* 3750 us */
145  NRF_SETUP_ARD_4000US_gc = (0x0F<<4) /* 4000 us */
147 #define NRF_SETUP_ARD_gm (0xF0)
148 #define NRF_SETUP_ARD_gp 4
149 
151 {
152  NRF_SETUP_ARC_NORETRANSMIT_gc = (0x00<<0), /* no retransmit */
153  NRF_SETUP_ARC_1RETRANSMIT_gc = (0x01<<0), /* 1 retransmit */
154  NRF_SETUP_ARC_2RETRANSMIT_gc = (0x02<<0), /* 2 retransmits */
155  NRF_SETUP_ARC_3RETRANSMIT_gc = (0x03<<0), /* 3 retransmits */
156  NRF_SETUP_ARC_4RETRANSMIT_gc = (0x04<<0), /* 4 retransmits */
157  NRF_SETUP_ARC_5RETRANSMIT_gc = (0x05<<0), /* 5 retransmits */
158  NRF_SETUP_ARC_6RETRANSMIT_gc = (0x06<<0), /* 6 retransmits */
159  NRF_SETUP_ARC_7RETRANSMIT_gc = (0x07<<0), /* 7 retransmits */
160  NRF_SETUP_ARC_8RETRANSMIT_gc = (0x08<<0), /* 8 retransmits */
161  NRF_SETUP_ARC_9RETRANSMIT_gc = (0x09<<0), /* 9 retransmits */
162  NRF_SETUP_ARC_10RETRANSMIT_gc = (0x0A<<0), /* 10 retransmits */
163  NRF_SETUP_ARC_11RETRANSMIT_gc = (0x0B<<0), /* 11 retransmits */
164  NRF_SETUP_ARC_12RETRANSMIT_gc = (0x0C<<0), /* 12 retransmits */
165  NRF_SETUP_ARC_13RETRANSMIT_gc = (0x0D<<0), /* 13 retransmits */
166  NRF_SETUP_ARC_14RETRANSMIT_gc = (0x0E<<0), /* 14 retransmits */
167  NRF_SETUP_ARC_15RETRANSMIT_gc = (0x0F<<0) /* 15 retransmits */
169 #define NRF_SETUP_ARC_gm (0x0F)
170 #define NRF_SETUP_ARC_gp 0
171 
172 // Definitions for RF_CH register
173 #define NRF_RF_CH_gm 0x7F
174 #define NRF_RF_CH_max 0x7F
175 
176 // Definitions and typedefinitions for RF_SETUP register
177 #define NRF_RF_SETUP_CONT_WAVE_bm (1<<7)
178 #define NRF_RF_SETUP_RF_DR_LOW_bm (1<<5)
179 #define NRF_RF_SETUP_PLL_LOCK_bm (1<<4)
180 #define NRF_RF_SETUP_RF_DR_HIGH_bm (1<<3)
182 {
183  NRF_RF_SETUP_RF_DR_1M_gc = ((0<<5)|(0<<3)),
184  NRF_RF_SETUP_RF_DR_2M_gc = ((0<<5)|(1<<3)),
185  NRF_RF_SETUP_RF_DR_250K_gc = ((1<<5)|(0<<3))
187 #define NRF_RF_SETUP_RF_DR_gm ((1<<5)|(1<<3))
189 {
195 #define NRF_RF_SETUP_PWR_gm (0x06)
196 
197 // Definitions and typedefinitions for STATUS register
198 #define NRF_STATUS_RX_DR_bm (1<<6)
199 #define NRF_STATUS_TX_DS_bm (1<<5)
200 #define NRF_STATUS_MAX_RT_bm (1<<4)
202 {
211 #define NRF_STATUS_RX_P_NO_gp 1
212 #define NRF_STATUS_RX_P_NO_gm (0x0E)
213 #define NRF_STATUS_TX_FULL_bm (1<<0)
214 
215 // Definitions for OBSERVE_TX register
216 #define NRF_OBSERVE_TX_PLOS_CNT_gm 0xF0
217 #define NRF_OBSERVE_TX_ARC_CNT_gm 0x0F
218 
219 // Definition for RPD-register (nRF24L01+) and CD-register (nRF24L01)
220 #define NRF_RPD_RPD_bm (1<<0)
221 #define NRF_CD_CD_bm (1<<0)
222 
223 // Definitions for RX_PW registers
224 #define NRF_RX_PW_P0_gm (0x3F)
225 #define NRF_RX_PW_P1_gm (0x3F)
226 #define NRF_RX_PW_P2_gm (0x3F)
227 #define NRF_RX_PW_P3_gm (0x3F)
228 #define NRF_RX_PW_P4_gm (0x3F)
229 #define NRF_RX_PW_P5_gm (0x3F)
230 
231 // Definitions for FIFO_STATUS register
232 #define NRF_FIFO_STATUS_TX_REUSE_bm (1<<6)
233 #define NRF_FIFO_STATUS_TX_FULL_bm (1<<5)
234 #define NRF_FIFO_STATUS_TX_EMPTY_bm (1<<4)
235 #define NRF_FIFO_STATUS_RX_FULL_bm (1<<1)
236 #define NRF_FIFO_STATUS_RX_EMPTY_bm (1<<0)
237 
238 // Definitions for DYNPD register
239 #define NRF_DYNPD_DPL_P5_bm (1<<5)
240 #define NRF_DYNPD_DPL_P4_bm (1<<4)
241 #define NRF_DYNPD_DPL_P3_bm (1<<3)
242 #define NRF_DYNPD_DPL_P2_bm (1<<2)
243 #define NRF_DYNPD_DPL_P1_bm (1<<1)
244 #define NRF_DYNPD_DPL_P0_bm (1<<0)
245 #define NRF_DYNPD_DPL_gm (0x3F)
246 
247 // Definitions for FEATURE register
248 #define NRF_FEATURE_EN_DPL_bm (1<<2)
249 #define NRF_FEATURE_EN_ACK_PAY_bm (1<<1)
250 #define NRF_FEATURE_EN_DYN_ACK_bm (1<<0)
251 
255 #define NRF_MAX_PAYLOAD_SIZE 32
256 #define NRF_MAX_CHANNEL 127
257 
261 uint8_t nrfReadRegisterMulti(uint8_t reg, uint8_t* buf, uint8_t len);
262 uint8_t nrfReadRegister(uint8_t reg);
263 uint8_t nrfWriteRegisterMulti(uint8_t reg, const uint8_t* buf, uint8_t len);
264 uint8_t nrfWriteRegister(uint8_t reg, uint8_t value);
265 uint8_t nrfWritePayload(const void* buf, uint8_t len, const uint8_t writeType);
266 uint8_t nrfReadPayload(void* buf, uint8_t len);
267 uint8_t nrfFlushRx(void);
268 uint8_t nrfFlushTx(void);
269 void nrfToggleFeatures(void);
270 
271 void nrfBegin(void);
272 void nrfStartListening(void);
273 void nrfStopListening(void);
274 uint8_t nrfGetStatus(void);
275 void nrfSetChannel(uint8_t channel);
276 uint8_t nrfGetChannel(void);
277 void nrfSetPayloadSize(uint8_t size);
278 uint8_t nrfGetPayloadSize(void);
279 void nrfPowerDown(void);
280 void nrfPowerUp(void);
281 uint8_t nrfWrite( uint8_t* buf, uint8_t len); // const void* buf ???
282 uint8_t nrfWaitForAck(void);
283 uint8_t nrfAvailable(uint8_t* pipe_num);
284 uint8_t nrfGetDynamicPayloadSize(void);
285 void nrfWriteAckPayload(uint8_t pipe, uint8_t* buf, uint8_t len);
286 void nrfStartWrite( const void* buf, uint8_t len, uint8_t multicast);
287 uint8_t nrfRead( void* buf, uint8_t len );
288 void nrfWhatHappened(uint8_t *tx_ok, uint8_t *tx_fail, uint8_t *rx_ready);
289 void nrfOpen64WritingPipe(uint64_t value);
290 void nrfOpenWritingPipe(uint8_t *address);
291 void nrfOpen64ReadingPipe(uint8_t child, uint64_t address);
292 void nrfOpenReadingPipe(uint8_t child, uint8_t *address);
293 void nrfEnableDynamicPayloads(void);
294 void nrfEnableAckPayload(void);
295 uint8_t nrfIsPVariant(void);
296 void nrfSetAutoAck(uint8_t enable);
297 void nrfSetAutoAckPipe( uint8_t pipe, uint8_t enable );
298 uint8_t nrfTestCarrier(void);
299 uint8_t nrfTestRPD(void);
302 uint8_t nrfSetDataRate(nrf_rf_setup_rf_dr_t speed);
304 void nrfSetCRCLength(nrf_config_crc_t length);
306 void nrfDisableCRC( void );
307 void nrfSetRetries(uint8_t delay, uint8_t retries);
308 uint16_t nrfGetMaxTimeout(void);
309 void nrfClearInterruptBits(void);
310 uint8_t nrfVerifySPIConnection(void);
311 
312 #endif
313 
314 
315 
316 
void nrfSetAutoAck(uint8_t enable)
Enable or disable auto-acknowlede packets.
Definition: nrf24L01.c:880
Definition: nrf24L01.h:203
NRF_SETUP_AW_ARC_enum
Definition: nrf24L01.h:150
uint8_t nrfWriteRegister(uint8_t reg, uint8_t value)
Write a byte to a register.
Definition: nrf24L01.c:205
Definition: nrf24L01.h:122
Definition: nrf24L01.h:143
Definition: nrf24L01.h:208
nrf_rf_setup_rf_dr_t nrfGetDataRate(void)
Get the transmission data rate.
Definition: nrf24L01.c:1029
Definition: nrf24L01.h:138
enum NRF_STATUS_P_NO_enum NRF_STATUS_P_NO_t
NRF_CONFIG_CRC_enum
Definition: nrf24L01.h:94
Definition: nrf24L01.h:209
Definition: nrf24L01.h:191
uint8_t nrfWaitForAck(void)
Wait for acknowledge.
Definition: nrf24L01.c:467
void nrfEnableDynamicPayloads(void)
Enable dynamically-sized payloads.
Definition: nrf24L01.c:728
NRF_RF_SETUP_RF_DR_enum
Definition: nrf24L01.h:181
void nrfStartWrite(const void *buf, uint8_t len, uint8_t multicast)
Write to open writing pipe.
Definition: nrf24L01.c:498
NRF_SETUP_AW_ARD_enum
Definition: nrf24L01.h:128
Definition: nrf24L01.h:97
Definition: nrf24L01.h:156
Definition: nrf24L01.h:158
Definition: nrf24L01.h:184
Definition: nrf24L01.h:204
uint8_t nrfVerifySPIConnection(void)
Verify SPI Interface.
Definition: nrf24L01.c:1142
uint8_t pipe[5]
pipe address is "HvA01"
Definition: nrf24_test_receive.c:45
NRF_RF_SETUP_PWR_enum
Definition: nrf24L01.h:188
enum NRF_SETUP_AW_ARC_enum NRF_SETUP_AW_ARC_t
void nrfPowerDown(void)
Enter low-power mode.
Definition: nrf24L01.c:524
uint8_t nrfWrite(uint8_t *buf, uint8_t len)
Write to the open writing pipe.
Definition: nrf24L01.c:439
void nrfBegin(void)
Begin operation of NRF24L01p.
Definition: nrf24L01.c:76
Definition: nrf24L01.h:159
Definition: nrf24L01.h:167
Definition: nrf24L01.h:163
enum NRF_SETUP_AW_ARD_enum NRF_SETUP_AW_ARD_t
Definition: nrf24L01.h:96
uint8_t nrfIsPVariant(void)
Determine whether the hardware is an nRF24L01+ or not.
Definition: nrf24L01.c:866
uint8_t nrfTestCarrier(void)
Test whether there was a carrier on the line for the previous listening period.
Definition: nrf24L01.c:922
uint8_t nrfGetDynamicPayloadSize(void)
Get Dynamic Payload Size.
Definition: nrf24L01.c:789
void nrfSetPayloadSize(uint8_t size)
Definition: nrf24L01.c:846
uint8_t nrfReadPayload(void *buf, uint8_t len)
Write the receive payload.
Definition: nrf24L01.c:302
nrf_rf_setup_pwr_t nrfGetPALevel(void)
Gets the current PA level.
Definition: nrf24L01.c:977
Definition: nrf24L01.h:161
uint8_t nrfWriteRegisterMulti(uint8_t reg, const uint8_t *buf, uint8_t len)
Write multiple bytes to a register.
Definition: nrf24L01.c:182
Definition: nrf24L01.h:157
void nrfClearInterruptBits(void)
Clear Interrupt Bits.
Definition: nrf24L01.c:1126
void nrfSetRetries(uint8_t delay, uint8_t retries)
Sets the number of retries and the delay between the retries.
Definition: nrf24L01.c:1096
Definition: nrf24L01.h:155
void nrfOpen64ReadingPipe(uint8_t child, uint64_t address)
Open a pipe for reading.
Definition: nrf24L01.c:622
Definition: nrf24L01.h:133
Definition: nrf24L01.h:162
enum NRF_CONFIG_CRC_enum nrf_config_crc_t
Definition: nrf24L01.h:124
enum NRF_RF_SETUP_PWR_enum nrf_rf_setup_pwr_t
void nrfOpen64WritingPipe(uint64_t value)
Open a pipe for writing.
Definition: nrf24L01.c:604
Definition: nrf24L01.h:192
Definition: nrf24L01.h:141
uint8_t nrfRead(void *buf, uint8_t len)
Read the payload.
Definition: nrf24L01.c:336
Definition: nrf24L01.h:132
void nrfOpenWritingPipe(uint8_t *address)
Open a pipe for writing.
Definition: nrf24L01.c:658
Definition: nrf24L01.h:152
uint8_t nrfGetChannel(void)
Definition: nrf24L01.c:840
Definition: nrf24L01.h:183
void nrfSetPALevel(nrf_rf_setup_pwr_t level)
Set Power Amplifier (PA) level.
Definition: nrf24L01.c:956
void nrfOpenReadingPipe(uint8_t child, uint8_t *address)
Open a pipe for reading.
Definition: nrf24L01.c:680
#define NRF_CONFIG_EN_CRC_bm
Definition: nrf24L01.h:89
void nrfSetChannel(uint8_t channel)
Definition: nrf24L01.c:830
Definition: nrf24L01.h:139
uint8_t nrfReadRegisterMulti(uint8_t reg, uint8_t *buf, uint8_t len)
Prototypes of functions.
Definition: nrf24L01.c:136
Definition: nrf24L01.h:123
Definition: nrf24L01.h:140
Definition: nrf24L01.h:137
void nrfPowerUp(void)
Leave low-power mode - making radio more responsive.
Definition: nrf24L01.c:535
void nrfSetCRCLength(nrf_config_crc_t length)
Sets the CRC length.
Definition: nrf24L01.c:1043
Definition: nrf24L01.h:136
uint8_t nrfWritePayload(const void *buf, uint8_t len, const uint8_t writeType)
Write the transmit payload.
Definition: nrf24L01.c:233
void nrfWhatHappened(uint8_t *tx_ok, uint8_t *tx_fail, uint8_t *rx_ready)
Call this to find out which interrupt occured.
Definition: nrf24L01.c:587
Definition: nrf24L01.h:166
void nrfStartListening(void)
Start listening on the pipes opened for reading.
Definition: nrf24L01.c:386
NRF_SETUP_AW_enum
Definition: nrf24L01.h:120
uint8_t nrfGetStatus(void)
Get fixed payload size.
Definition: nrf24L01.c:818
Definition: nrf24L01.h:185
uint8_t nrfFlushTx(void)
Empty the transmit fifo.
Definition: nrf24L01.c:367
void nrfEnableAckPayload(void)
Enable custom payloads on the acknowledge packets.
Definition: nrf24L01.c:757
Definition: nrf24L01.h:190
Definition: nrf24L01.h:207
Definition: nrf24L01.h:131
uint16_t nrfGetMaxTimeout(void)
Calculate the maximum timeout in us based on current configuration.
Definition: nrf24L01.c:1112
Definition: nrf24L01.h:206
Definition: nrf24L01.h:164
Definition: nrf24L01.h:134
Definition: nrf24L01.h:135
Definition: nrf24L01.h:130
Definition: nrf24L01.h:142
NRF_STATUS_P_NO_enum
Definition: nrf24L01.h:201
Definition: nrf24L01.h:153
void nrfDisableCRC(void)
Disbale CRC.
Definition: nrf24L01.c:1073
void nrfSetAutoAckPipe(uint8_t pipe, uint8_t enable)
Enable or disable auto-acknowlede packets for a distinct pipe.
Definition: nrf24L01.c:898
Definition: nrf24L01.h:144
void nrfToggleFeatures(void)
Turn on or off the special features.
Definition: nrf24L01.c:713
Definition: nrf24L01.h:193
#define NRF_CONFIG_CRC0_bm
Definition: nrf24L01.h:90
uint8_t nrfTestRPD(void)
Test whether a signal (carrier or otherwise) greater than or equal to -64dBm is present on the channe...
Definition: nrf24L01.c:939
nrf_config_crc_t nrfGetCRCLength(void)
Get the CRC length.
Definition: nrf24L01.c:1064
uint8_t nrfAvailable(uint8_t *pipe_num)
Test whether there are bytes available to be read.
Definition: nrf24L01.c:552
uint8_t nrfFlushRx(void)
Empty the receive fifo.
Definition: nrf24L01.c:351
uint8_t nrfGetPayloadSize(void)
Get fixed payload size.
Definition: nrf24L01.c:807
void nrfStopListening(void)
Stop listening for incoming messages.
Definition: nrf24L01.c:417
uint8_t nrfSetDataRate(nrf_rf_setup_rf_dr_t speed)
Set the transmission data rate.
Definition: nrf24L01.c:997
Definition: nrf24L01.h:98
Definition: nrf24L01.h:205
Definition: nrf24L01.h:160
enum NRF_SETUP_AW_enum NRF_SETUP_AW_t
enum NRF_RF_SETUP_RF_DR_enum nrf_rf_setup_rf_dr_t
void nrfWriteAckPayload(uint8_t pipe, uint8_t *buf, uint8_t len)
Write an ack payload for the specified pipe.
Definition: nrf24L01.c:274
Definition: nrf24L01.h:165
Definition: nrf24L01.h:154
uint8_t nrfReadRegister(uint8_t reg)
Read a byte from a register.
Definition: nrf24L01.c:158
Definition: nrf24L01.h:145