Browse Source

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

Bernd Gottschlag 5 years ago
parent
commit
3dcfae6196

+ 11
- 15
weather-sensor/firmware/nrf24l01.c View File

64
 	FEATURE_REGISTER featureRegisterContents = {.byte = 0x0};
64
 	FEATURE_REGISTER featureRegisterContents = {.byte = 0x0};
65
 	DYNPD_REGISTER dyndpRegisterContents = {.byte = 0x0};
65
 	DYNPD_REGISTER dyndpRegisterContents = {.byte = 0x0};
66
 	SETUP_RETR_REGISTER setupRetrRegisterContents = {.byte = 0x0};
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
 	 * - Length of CRC (CRCO in CONFIG)
71
 	 * - Length of CRC (CRCO in CONFIG)
69
 	 * - Enable auto acknowledgment (EN_AA)
72
 	 * - Enable auto acknowledgment (EN_AA)
109
 	Write_NRF_Register(DYNPD_ADDRESS, dyndpRegisterContents.byte);
112
 	Write_NRF_Register(DYNPD_ADDRESS, dyndpRegisterContents.byte);
110
 
113
 
111
 	/* Set the TX address */
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
 	PCMSK2 |= (1<<PCINT21); // Set the external interrupt for PD5
120
 	PCMSK2 |= (1<<PCINT21); // Set the external interrupt for PD5
298
 	SPI_Stop_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
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
 	SPI_Start_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
305
 	SPI_Start_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
306
 
306
 
307
 	SPI_Transfer_Byte(TX_ADDR_ADDRESS | 0x20);
307
 	SPI_Transfer_Byte(TX_ADDR_ADDRESS | 0x20);
308
 	/* Write the data byte */
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
 	SPI_Stop_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
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
 	SPI_Start_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
319
 	SPI_Start_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
323
 
320
 
324
 	SPI_Transfer_Byte(RX_ADDR_P0_ADDRESS | 0x20);
321
 	SPI_Transfer_Byte(RX_ADDR_P0_ADDRESS | 0x20);
325
 
322
 
326
 	/* Write the data byte */
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
 	SPI_Stop_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
329
 	SPI_Stop_Transmission(&NRF_CSN_PORT, NRF_CSN_PIN);
334
 }
330
 }

+ 2
- 2
weather-sensor/firmware/nrf24l01.h View File

27
 
27
 
28
 void NRF24L01_Send_Message(uint8_t *buffer, uint8_t length);
28
 void NRF24L01_Send_Message(uint8_t *buffer, uint8_t length);
29
 void Write_Message_To_TX_FIFO(uint8_t length, uint8_t * buffer);
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
 #endif
33
 #endif

+ 1
- 0
weather-sensor/firmware/nrf24l01_definitions.h View File

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

Loading…
Cancel
Save