Przeglądaj źródła

Change the way the TX and RX addresses are written to the nrf24l01

Bernd Gottschlag 5 lat temu
rodzic
commit
3dcfae6196

+ 11
- 15
weather-sensor/firmware/nrf24l01.c Wyświetl plik

@@ -64,6 +64,9 @@ void Configure_Transmission(void)
64 64
 	FEATURE_REGISTER featureRegisterContents = {.byte = 0x0};
65 65
 	DYNPD_REGISTER dyndpRegisterContents = {.byte = 0x0};
66 66
 	SETUP_RETR_REGISTER setupRetrRegisterContents = {.byte = 0x0};
67
+
68
+	uint8_t txAddress[5] = {0xB3, 0xB3, 0xB3, 0xB3, 0x00};
69
+	uint8_t rx0Address[5] = {0xB3, 0xB3, 0xB3, 0xB3, 0x20};
67 70
 	/* 
68 71
 	 * - Length of CRC (CRCO in CONFIG)
69 72
 	 * - Enable auto acknowledgment (EN_AA)
@@ -109,10 +112,9 @@ void Configure_Transmission(void)
109 112
 	Write_NRF_Register(DYNPD_ADDRESS, dyndpRegisterContents.byte);
110 113
 
111 114
 	/* Set the TX address */
112
-	Set_TX_Address(0x123456);
115
+	Set_TX_Address(txAddress, MAX_ADDRESS_LENGTH);
113 116
 
114
-	Set_RX_P0_Address(0x123456);
115
-	// TODO: set addresses for all data pipes
117
+	Set_RX_P0_Address(rx0Address, MAX_ADDRESS_LENGTH);
116 118
 
117 119
 
118 120
 	PCMSK2 |= (1<<PCINT21); // Set the external interrupt for PD5
@@ -298,37 +300,31 @@ void Write_Message_To_TX_FIFO(uint8_t length, uint8_t * buffer)
298 300
 	SPI_Stop_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
299 301
 }
300 302
 
301
-void Set_TX_Address(uint32_t txAddress)
303
+void Set_TX_Address(uint8_t * txAddress, uint8_t length)
302 304
 {
303
-	uint8_t * buffer = (uint8_t*) &txAddress;
304
-
305 305
 	SPI_Start_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
306 306
 
307 307
 	SPI_Transfer_Byte(TX_ADDR_ADDRESS | 0x20);
308 308
 	/* Write the data byte */
309
-	for (uint8_t i = 0; i < 4; i ++)
309
+	for (uint8_t i = 0; i < length; i ++)
310 310
 	{
311
-		SPI_Transfer_Byte(buffer[i]);
311
+		SPI_Transfer_Byte(txAddress[i]);
312 312
 	}
313
-	SPI_Transfer_Byte(0x0);
314 313
 
315 314
 	SPI_Stop_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
316 315
 }
317 316
 
318
-void Set_RX_P0_Address(uint32_t rxAddress)
317
+void Set_RX_P0_Address(uint8_t * rxAddress, uint8_t length)
319 318
 {
320
-	uint8_t * buffer = (uint8_t*) &rxAddress;
321
-
322 319
 	SPI_Start_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
323 320
 
324 321
 	SPI_Transfer_Byte(RX_ADDR_P0_ADDRESS | 0x20);
325 322
 
326 323
 	/* Write the data byte */
327
-	for (uint8_t i = 0; i < 4; i ++)
324
+	for (uint8_t i = 0; i < length; i ++)
328 325
 	{
329
-		SPI_Transfer_Byte(buffer[i]);
326
+		SPI_Transfer_Byte(rxAddress[i]);
330 327
 	}
331
-	SPI_Transfer_Byte(0x0);
332 328
 
333 329
 	SPI_Stop_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
334 330
 }

+ 2
- 2
weather-sensor/firmware/nrf24l01.h Wyświetl plik

@@ -27,7 +27,7 @@ void Send_Activate_Command(void);
27 27
 
28 28
 void NRF24L01_Send_Message(uint8_t *buffer, uint8_t length);
29 29
 void Write_Message_To_TX_FIFO(uint8_t length, uint8_t * buffer);
30
-void Set_TX_Address(uint32_t txAddress);
31
-void Set_RX_P0_Address(uint32_t rxAddress);
30
+void Set_TX_Address(uint8_t * txAddress, uint8_t length);
31
+void Set_RX_P0_Address(uint8_t * rxAddress, uint8_t length);
32 32
 
33 33
 #endif

+ 1
- 0
weather-sensor/firmware/nrf24l01_definitions.h Wyświetl plik

@@ -1,6 +1,7 @@
1 1
 #ifndef NRF24L01_DEFINITIONS_H
2 2
 #define NRF24L01_DEFINITIONS_H
3 3
 
4
+#define MAX_ADDRESS_LENGTH 5
4 5
 
5 6
 /* NRF24L01 register mnemonic definitions */
6 7
 #define CONFIG_ADDRESS 0x0

Ładowanie…
Anuluj
Zapisz