|
|
@@ -5,6 +5,7 @@
|
|
5
|
5
|
#include <stdbool.h>
|
|
6
|
6
|
|
|
7
|
7
|
#include "nrf24l01.h"
|
|
|
8
|
+#include "nrf24l01_definitions.h"
|
|
8
|
9
|
#include "uart_debug.h"
|
|
9
|
10
|
|
|
10
|
11
|
/* TODO
|
|
|
@@ -19,6 +20,8 @@ void Print_Register_Contents(uint8_t address);
|
|
19
|
20
|
/* Startup and initial configuration of the NRF24L01 */
|
|
20
|
21
|
void Initialize_NRF24L01(void)
|
|
21
|
22
|
{
|
|
|
23
|
+ CONFIG_REGISTER configRegisterContents = {.byte = 0x0};
|
|
|
24
|
+
|
|
22
|
25
|
/* Configure the AVR pins for the nrf24l01 */
|
|
23
|
26
|
/* Set up the NRF24L01 */
|
|
24
|
27
|
NRF_CE_DDR |= (1 << NRF_CE_PIN);
|
|
|
@@ -33,7 +36,9 @@ void Initialize_NRF24L01(void)
|
|
33
|
36
|
_delay_ms(11);
|
|
34
|
37
|
|
|
35
|
38
|
/* Write the PWR_UP bit of the CONFIG register (EN_CRC is also set) */
|
|
36
|
|
- Write_NRF_Register(0x0, 0xA);
|
|
|
39
|
+ configRegisterContents.bits.EN_CRC = 0x1;
|
|
|
40
|
+ configRegisterContents.bits.PWR_UP = 0x1;
|
|
|
41
|
+ Write_NRF_Register(CONFIG_ADDRESS, configRegisterContents.byte);
|
|
37
|
42
|
|
|
38
|
43
|
/* Wait more than 1.5 ms for the change to take effect */
|
|
39
|
44
|
_delay_ms(2);
|
|
|
@@ -43,6 +48,8 @@ void Initialize_NRF24L01(void)
|
|
43
|
48
|
|
|
44
|
49
|
void Configure_Transmission(void)
|
|
45
|
50
|
{
|
|
|
51
|
+ FEATURE_REGISTER featureRegisterContents = {.byte = 0x0};
|
|
|
52
|
+ DYNPD_REGISTER dyndpRegisterContents = {.byte = 0x0};
|
|
46
|
53
|
/*
|
|
47
|
54
|
* - Length of CRC (CRCO in CONFIG)
|
|
48
|
55
|
* - Enable auto acknowledgment (EN_AA)
|
|
|
@@ -66,15 +73,23 @@ void Configure_Transmission(void)
|
|
66
|
73
|
//Write_NRF_Register(0x03, 0x1);
|
|
67
|
74
|
|
|
68
|
75
|
/* Set the frequency to 1450 MHz */
|
|
69
|
|
- Write_NRF_Register(0x05, 0x32);
|
|
|
76
|
+ Write_NRF_Register(RF_CH_ADDRESS, 0x32);
|
|
70
|
77
|
|
|
71
|
78
|
/* Enable dynamic payload length */
|
|
72
|
79
|
Send_Activate_Command();
|
|
73
|
|
- Write_NRF_Register(0x1D, 0x4); // enable dynamic payload length
|
|
74
|
|
- Write_NRF_Register(0X1C, 0X3F); // set dynamic payload length for all data pipes
|
|
|
80
|
+ featureRegisterContents.bits.EN_DPL = 1; // enable dynamic payload length
|
|
|
81
|
+ Write_NRF_Register(FEATURE_ADDRESS, featureRegisterContents.byte);
|
|
|
82
|
+
|
|
|
83
|
+ /* set dynamic payload length for all data pipes */
|
|
|
84
|
+ dyndpRegisterContents.bits.DPL_P0 = 1;
|
|
|
85
|
+ dyndpRegisterContents.bits.DPL_P1 = 1;
|
|
|
86
|
+ dyndpRegisterContents.bits.DPL_P2 = 1;
|
|
|
87
|
+ dyndpRegisterContents.bits.DPL_P3 = 1;
|
|
|
88
|
+ dyndpRegisterContents.bits.DPL_P4 = 1;
|
|
|
89
|
+ dyndpRegisterContents.bits.DPL_P5 = 1;
|
|
|
90
|
+ Write_NRF_Register(DYNPD_ADDRESS, dyndpRegisterContents.byte);
|
|
75
|
91
|
|
|
76
|
92
|
/* Set the TX address */
|
|
77
|
|
- //Set_TX_Address(0x563412);
|
|
78
|
93
|
Set_TX_Address(0x123456);
|
|
79
|
94
|
|
|
80
|
95
|
Set_RX_P0_Address(0x123456);
|
|
|
@@ -90,6 +105,7 @@ void Send_Test_Message(void)
|
|
90
|
105
|
uint8_t statusContent = 0;
|
|
91
|
106
|
|
|
92
|
107
|
uint8_t registerContent[5];
|
|
|
108
|
+ STATUS_REGISTER statusRegisterContents = {.byte = 0x0};
|
|
93
|
109
|
uint8_t lengthRead;
|
|
94
|
110
|
char debugString[50] = "";
|
|
95
|
111
|
uint32_t timeout = 0;
|
|
|
@@ -112,22 +128,22 @@ void Send_Test_Message(void)
|
|
112
|
128
|
do
|
|
113
|
129
|
{
|
|
114
|
130
|
_delay_ms(1);
|
|
115
|
|
- lengthRead = Read_NRF_Register(0x07, registerContent);
|
|
|
131
|
+ lengthRead = Read_NRF_Register(STATUS_ADDRESS, &(statusRegisterContents.byte)); /* TODO: use funtion to read status register -> no overflow possible, only one NOP transfer needed, not two */
|
|
116
|
132
|
|
|
117
|
133
|
if (lengthRead > 1)
|
|
118
|
134
|
{
|
|
119
|
|
- sprintf(debugString, "%s\r\n", "read error");
|
|
|
135
|
+ sprintf(debugString, "%s\r\n", "Read error");
|
|
120
|
136
|
Print_Debug_String(debugString);
|
|
121
|
137
|
}
|
|
122
|
138
|
|
|
123
|
|
- if ((registerContent[0] & (1<<5)) != 0)
|
|
|
139
|
+ if (statusRegisterContent.bits.TX_DS == true)
|
|
124
|
140
|
{
|
|
125
|
141
|
transmissionFinished = true;
|
|
126
|
142
|
sprintf(debugString, "%s\r\n", "TX fin");
|
|
127
|
143
|
Print_Debug_String(debugString);
|
|
128
|
144
|
}
|
|
129
|
145
|
|
|
130
|
|
- if ((registerContent[0] & (1<<4)) != 0)
|
|
|
146
|
+ if (statusRegisterContent.bits.MAX_RT == true)
|
|
131
|
147
|
{
|
|
132
|
148
|
transmissionFinished = true;
|
|
133
|
149
|
sprintf(debugString, "%s\r\n", "max ret");
|
|
|
@@ -144,9 +160,12 @@ void Send_Test_Message(void)
|
|
144
|
160
|
}
|
|
145
|
161
|
|
|
146
|
162
|
/* Reset the interrupts */
|
|
147
|
|
- lengthRead = Read_NRF_Register(0x07, registerContent);
|
|
|
163
|
+ lengthRead = Read_NRF_Register(STATUS_ADDRESS, statusRegisterContents); /* TODO: use status register read function */
|
|
148
|
164
|
statusContent = registerContent[0] & 0x0F;
|
|
149
|
|
- Write_NRF_Register(0x07, statusContent);
|
|
|
165
|
+ statusRegisterContents.bits.RX_DR = false;
|
|
|
166
|
+ statusRegisterContents.bits.TX_DS = false;
|
|
|
167
|
+ statusRegisterContents.bits.MAX_RT = false;
|
|
|
168
|
+ Write_NRF_Register(STATUS_ADDRESS, statusContent);
|
|
150
|
169
|
|
|
151
|
170
|
// TODO: flush FIFO if an error occured
|
|
152
|
171
|
}
|