|
|
@@ -19,6 +19,9 @@ extern volatile bool nrfInterruptRaised;
|
|
19
|
19
|
void Print_Register_Contents(uint8_t address);
|
|
20
|
20
|
void Send_TX_Flush_Command(void);
|
|
21
|
21
|
|
|
|
22
|
+static void Write_Two_Bytes(uint8_t byte1, uint8_t byte2);
|
|
|
23
|
+static void Write_Byte_And_Buffer(uint8_t byte, uint8_t * buffer, uint8_t length);
|
|
|
24
|
+
|
|
22
|
25
|
/* Startup and initial configuration of the NRF24L01 */
|
|
23
|
26
|
void Initialize_NRF24L01(void)
|
|
24
|
27
|
{
|
|
|
@@ -168,41 +171,6 @@ void NRF24L01_Send_Message(uint8_t *buffer, uint8_t length)
|
|
168
|
171
|
return;
|
|
169
|
172
|
}
|
|
170
|
173
|
|
|
171
|
|
-void Print_Register_Contents(uint8_t address)
|
|
172
|
|
-{
|
|
173
|
|
- uint8_t registerContent[5];
|
|
174
|
|
- uint8_t lengthRead;
|
|
175
|
|
- char registerContentString[30];
|
|
176
|
|
-
|
|
177
|
|
-
|
|
178
|
|
- lengthRead = Read_NRF_Register(address, registerContent);
|
|
179
|
|
-
|
|
180
|
|
- registerContentString[0] = '\0';
|
|
181
|
|
- for (uint8_t i = 0; i < lengthRead; i++)
|
|
182
|
|
- {
|
|
183
|
|
- sprintf(registerContentString, "%s0x%x ", registerContentString, registerContent[i]);
|
|
184
|
|
- }
|
|
185
|
|
-}
|
|
186
|
|
-
|
|
187
|
|
-
|
|
188
|
|
-
|
|
189
|
|
-
|
|
190
|
|
-/* Send a message:
|
|
191
|
|
- * - Set PRIM_RX = 0 and add one message to the TX-FIFO
|
|
192
|
|
- * - Set CE=1 for more than 10 us
|
|
193
|
|
- * - The NRF takes 130 us to enter the TX Mode
|
|
194
|
|
- * - An Interrupt is generated once the
|
|
195
|
|
- * -
|
|
196
|
|
- */
|
|
197
|
|
-
|
|
198
|
|
-
|
|
199
|
|
-/* Set the NRF to RX Mode */
|
|
200
|
|
-
|
|
201
|
|
-/* Disable the RX Mode */
|
|
202
|
|
-
|
|
203
|
|
-
|
|
204
|
|
-
|
|
205
|
|
-
|
|
206
|
174
|
uint8_t Read_NRF_Status_Register(void)
|
|
207
|
175
|
{
|
|
208
|
176
|
uint8_t registerContents;
|
|
|
@@ -213,6 +181,9 @@ uint8_t Read_NRF_Status_Register(void)
|
|
213
|
181
|
return registerContents;
|
|
214
|
182
|
}
|
|
215
|
183
|
|
|
|
184
|
+
|
|
|
185
|
+/* TODO: rewrite the read register function if it is needed (remove the read operations for the 5-byte registers)*/
|
|
|
186
|
+#if 0
|
|
216
|
187
|
uint8_t Read_NRF_Register(uint8_t address, uint8_t * registerContents)
|
|
217
|
188
|
{
|
|
218
|
189
|
/* TODO: simplify this function, as the registers with more than one byte are accessed with other functions */
|
|
|
@@ -247,28 +218,24 @@ uint8_t Read_NRF_Register(uint8_t address, uint8_t * registerContents)
|
|
247
|
218
|
return numberOfBytes;
|
|
248
|
219
|
}
|
|
249
|
220
|
|
|
|
221
|
+#endif
|
|
|
222
|
+
|
|
250
|
223
|
void Write_NRF_Register(uint8_t address, uint8_t registerContents)
|
|
251
|
224
|
{
|
|
252
|
|
- /* First write the write command with the address */
|
|
253
|
|
- SPI_Start_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
|
|
254
|
|
-
|
|
255
|
|
- SPI_Transfer_Byte(address | 0x20);
|
|
256
|
|
-
|
|
257
|
|
- /* Write the data byte */
|
|
258
|
|
- SPI_Transfer_Byte(registerContents);
|
|
259
|
|
-
|
|
260
|
|
- SPI_Stop_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
|
|
|
225
|
+ Write_Two_Bytes(address | 0x20, registerContents);
|
|
261
|
226
|
}
|
|
262
|
227
|
|
|
263
|
|
-// TODO: clean up functions
|
|
264
|
228
|
void Send_Activate_Command(void)
|
|
265
|
229
|
{
|
|
266
|
|
- /* First write the write command with the address */
|
|
|
230
|
+ Write_Two_Bytes(0x50, 0x73);
|
|
|
231
|
+}
|
|
|
232
|
+
|
|
|
233
|
+static void Write_Two_Bytes(uint8_t byte1, uint8_t byte2)
|
|
|
234
|
+{
|
|
267
|
235
|
SPI_Start_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
|
|
268
|
|
- SPI_Transfer_Byte(0x50);
|
|
269
|
236
|
|
|
270
|
|
- /* Write the data byte */
|
|
271
|
|
- SPI_Transfer_Byte(0x73);
|
|
|
237
|
+ SPI_Transfer_Byte(byte1);
|
|
|
238
|
+ SPI_Transfer_Byte(byte2);
|
|
272
|
239
|
|
|
273
|
240
|
SPI_Stop_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
|
|
274
|
241
|
}
|
|
|
@@ -287,44 +254,29 @@ void Send_TX_Flush_Command(void)
|
|
287
|
254
|
|
|
288
|
255
|
void Write_Message_To_TX_FIFO(uint8_t length, uint8_t * buffer)
|
|
289
|
256
|
{
|
|
290
|
|
- SPI_Start_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
|
|
291
|
|
-
|
|
292
|
|
- /* Issue the write command: */
|
|
293
|
|
- SPI_Transfer_Byte(0xA0);
|
|
294
|
|
-
|
|
295
|
|
- /* Write the data bytes */
|
|
296
|
|
- for (uint8_t i = 0; i < length; i++)
|
|
297
|
|
- {
|
|
298
|
|
- SPI_Transfer_Byte(buffer[i]);
|
|
299
|
|
- }
|
|
300
|
|
-
|
|
301
|
|
- SPI_Stop_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
|
|
|
257
|
+ Write_Byte_And_Buffer(0xA0, buffer, length);
|
|
302
|
258
|
}
|
|
303
|
259
|
|
|
304
|
260
|
void Set_TX_Address(uint8_t * txAddress, uint8_t length)
|
|
305
|
261
|
{
|
|
306
|
|
- SPI_Start_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
|
|
307
|
|
-
|
|
308
|
|
- SPI_Transfer_Byte(TX_ADDR_ADDRESS | 0x20);
|
|
309
|
|
- /* Write the data byte */
|
|
310
|
|
- for (uint8_t i = 0; i < length; i ++)
|
|
311
|
|
- {
|
|
312
|
|
- SPI_Transfer_Byte(txAddress[i]);
|
|
313
|
|
- }
|
|
314
|
|
-
|
|
315
|
|
- SPI_Stop_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
|
|
|
262
|
+ Write_Byte_And_Buffer(TX_ADDR_ADDRESS | 0x20, txAddress, length);
|
|
316
|
263
|
}
|
|
317
|
264
|
|
|
318
|
265
|
void Set_RX_P0_Address(uint8_t * rxAddress, uint8_t length)
|
|
|
266
|
+{
|
|
|
267
|
+ Write_Byte_And_Buffer(RX_ADDR_P0_ADDRESS | 0x20, rxAddress, length);
|
|
|
268
|
+}
|
|
|
269
|
+
|
|
|
270
|
+static void Write_Byte_And_Buffer(uint8_t byte, uint8_t * buffer, uint8_t length)
|
|
319
|
271
|
{
|
|
320
|
272
|
SPI_Start_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
|
|
321
|
273
|
|
|
322
|
|
- SPI_Transfer_Byte(RX_ADDR_P0_ADDRESS | 0x20);
|
|
|
274
|
+ SPI_Transfer_Byte(byte);
|
|
323
|
275
|
|
|
324
|
276
|
/* Write the data byte */
|
|
325
|
277
|
for (uint8_t i = 0; i < length; i ++)
|
|
326
|
278
|
{
|
|
327
|
|
- SPI_Transfer_Byte(rxAddress[i]);
|
|
|
279
|
+ SPI_Transfer_Byte(buffer[i]);
|
|
328
|
280
|
}
|
|
329
|
281
|
|
|
330
|
282
|
SPI_Stop_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
|