5#if defined(NRF52832_XXAA) || defined(NRF52832_XXAB) || defined(NRF52811_XXAA) || defined(NRF52810_XXAA) || defined(NRF52805_XXAA)
7 #define TXPOWER_PA_MIN 0xF4
8 #define TXPOWER_PA_LOW 0xFC
9 #define TXPOWER_PA_HIGH 0x00
10 #define TXPOWER_PA_MAX 0x04
13 #define TXPOWER_PA_MIN 0xF4
14 #define TXPOWER_PA_LOW 0x02
15 #define TXPOWER_PA_HIGH 0x06
16 #define TXPOWER_PA_MAX 0x08
21#ifndef RADIO_MODE_MODE_Nrf_250Kbit
22 #define RADIO_MODE_MODE_Nrf_250Kbit (2UL)
30 uint32_t inp = (p_inp[3] << 24) | (p_inp[2] << 16) | (p_inp[1] << 8) | (p_inp[0]);
31 inp = (inp & 0xF0F0F0F0) >> 4 | (inp & 0x0F0F0F0F) << 4;
32 inp = (inp & 0xCCCCCCCC) >> 2 | (inp & 0x33333333) << 2;
33 inp = (inp & 0xAAAAAAAA) >> 1 | (inp & 0x55555555) << 1;
52 buffer[0] = addr & 0xFF;
53 buffer[1] = (addr >> 8) & 0xFF;
54 buffer[2] = (addr >> 16) & 0xFF;
55 buffer[3] = (addr >> 24) & 0xFF;
65 staticPayloadSize = 32;
70 ackPayloadsEnabled =
false;
76 payloadAvailable =
false;
78#if defined CCM_ENCRYPTION_ENABLED
79 NRF_CCM->INPTR = (uint32_t)inBuffer;
81 NRF_CCM->CNFPTR = (uint32_t)&ccmData;
82 NRF_CCM->SCRATCHPTR = (uint32_t)scratchPTR;
83 ccmData.counter = 12345;
85 NRF_CCM->MODE = 1 << 24 | 1 << 16;
91 NRF_RNG->TASKS_START = 1;
100 NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
101 NRF_CLOCK->TASKS_HFCLKSTART = 1;
104 while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) {
108 NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
109 NRF_CLOCK->TASKS_LFCLKSTART = 1;
112 while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0) {
116 NRF_RADIO->POWER = 1;
119 NRF_RADIO->PCNF0 = (1 << RADIO_PCNF0_S0LEN_Pos) | (0 << RADIO_PCNF0_LFLEN_Pos) | (1 << RADIO_PCNF0_S1LEN_Pos);
121 NRF_RADIO->PCNF1 = (RADIO_PCNF1_WHITEEN_Disabled << RADIO_PCNF1_WHITEEN_Pos) | (RADIO_PCNF1_ENDIAN_Big << RADIO_PCNF1_ENDIAN_Pos) | (4 << RADIO_PCNF1_BALEN_Pos) | (staticPayloadSize << RADIO_PCNF1_STATLEN_Pos) | (staticPayloadSize << RADIO_PCNF1_MAXLEN_Pos);
123 NRF_RADIO->BASE0 = 0xE7E7E7E7;
124 NRF_RADIO->BASE1 = 0x43434343;
125 NRF_RADIO->PREFIX0 = 0x23C343E7;
126 NRF_RADIO->PREFIX1 = 0x13E363A3;
127 NRF_RADIO->RXADDRESSES = 0x01;
128 NRF_RADIO->TXADDRESS = 0x00;
130 txBase = NRF_RADIO->BASE0;
131 txPrefix = NRF_RADIO->PREFIX0;
132 rxBase = NRF_RADIO->BASE0;
133 rxPrefix = NRF_RADIO->PREFIX0;
135 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_Two;
136 NRF_RADIO->CRCINIT = 0xFFFFUL;
137 NRF_RADIO->CRCPOLY = 0x11021UL;
139 NRF_RADIO->PACKETPTR = (uint32_t)
radioData;
140 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos);
141 NRF_RADIO->MODECNF0 = 0x200;
142 NRF_RADIO->MODECNF0 |= 1;
143 NRF_RADIO->TXPOWER = (
TXPOWER_PA_MAX << RADIO_TXPOWER_TXPOWER_Pos);
144 NRF_RADIO->SHORTS = 1 << 19;
145 NRF_RADIO->FREQUENCY = 0x4C;
153#ifdef NRF_HAS_ENERGY_DETECT
154 #define ED_RSSISCALE 4
155uint8_t nrf_to_nrf::sample_ed(
void)
158 NRF_RADIO->TASKS_EDSTART = 1;
159 while (NRF_RADIO->EVENTS_EDEND != 1) {
163 val = NRF_RADIO->EDSAMPLE;
164 return (uint8_t)(val > 63
166 : val * ED_RSSISCALE);
174 uint8_t pipe_num = 0;
183 if (payloadAvailable) {
184 *pipe_num = (uint8_t)NRF_RADIO->RXMATCH;
189 if (ackPayloadAvailable) {
190 *pipe_num = ackAvailablePipeNo;
194 if (NRF_RADIO->EVENTS_CRCOK) {
195 uint32_t counter = 0;
196#if defined CCM_ENCRYPTION_ENABLED
199 NRF_RADIO->EVENTS_CRCOK = 0;
203 NRF_RADIO->TASKS_START = 1;
209 NRF_RADIO->TASKS_START = 1;
215 NRF_RADIO->TASKS_START = 1;
221 *pipe_num = (uint8_t)NRF_RADIO->RXMATCH;
222 if (!DPL && acksEnabled(*pipe_num) ==
false) {
223#if defined CCM_ENCRYPTION_ENABLED
231 memcpy(&rxBuffer[1], &
radioData[0], staticPayloadSize);
232#if defined CCM_ENCRYPTION_ENABLED
237#if defined CCM_ENCRYPTION_ENABLED
254 memcpy(&rxBuffer[1], &
radioData[2], staticPayloadSize);
256#if defined CCM_ENCRYPTION_ENABLED
261 rxFifoAvailable =
true;
262 uint8_t packetCtr = 0;
271 uint16_t packetData = NRF_RADIO->RXCRC;
273 if (acksEnabled(NRF_RADIO->RXMATCH)) {
275 uint32_t txAddress = NRF_RADIO->TXADDRESS;
276 NRF_RADIO->TXADDRESS = NRF_RADIO->RXMATCH;
277 delayMicroseconds(75);
278 if (ackPayloadsEnabled) {
279 if (*pipe_num == ackPipe) {
280 write(&ackBuffer[1], ackBuffer[0], 1, 0);
287 uint8_t payloadSize = 0;
297 NRF_RADIO->TXADDRESS = txAddress;
302 if (NRF_RADIO->CRCCNF != 0) {
303 if (packetCtr == lastPacketCounter && packetData == lastData) {
305 NRF_RADIO->TASKS_START = 1;
312#if defined CCM_ENCRYPTION_ENABLED
314 ccmData.counter = counter;
318 Serial.println(
"DECRYPT FAIL");
320 NRF_RADIO->TASKS_START = 1;
327 Serial.println(
"DECRYPT FAIL");
329 NRF_RADIO->TASKS_START = 1;
335 memset(&rxBuffer[1], 0,
sizeof(rxBuffer) - 1);
346 lastPacketCounter = packetCtr;
347 lastData = packetData;
348 payloadAvailable =
true;
350 NRF_RADIO->TASKS_START = 1;
354 if (NRF_RADIO->EVENTS_CRCERROR) {
355 NRF_RADIO->EVENTS_CRCERROR = 0;
356 NRF_RADIO->TASKS_START = 1;
365 memcpy(buf, &rxBuffer[1], len);
366 ackPayloadAvailable =
false;
367 payloadAvailable =
false;
375 uint8_t PID = ackPID;
377 PID = ((ackPID += 1) % 7) << 1;
382 uint8_t payloadSize = 0;
384#if defined CCM_ENCRYPTION_ENABLED
386 uint32_t tmpCounter = 0;
393 while (!NRF_RNG->EVENTS_VALRDY) {
395 NRF_RNG->EVENTS_VALRDY = 0;
396 tmpIV[i] = NRF_RNG->VALUE;
397 ccmData.iv[i] = tmpIV[i];
399 tmpCounter = packetCounter;
400 ccmData.counter = tmpCounter;
409 if (packetCounter > 200000) {
416 for (
int i = 0; i < (retries + 1); i++) {
427 uint8_t dataStart = 0;
429#if defined CCM_ENCRYPTION_ENABLED
436 dataStart = (!DPL && acksEnabled(0) ==
false) ? 0 : 2;
437#if defined CCM_ENCRYPTION_ENABLED
441#if defined CCM_ENCRYPTION_ENABLED
450#if defined CCM_ENCRYPTION_ENABLED
454 if (NRF_RADIO->STATE < 9) {
455 NRF_RADIO->EVENTS_TXREADY = 0;
456 NRF_RADIO->TASKS_TXEN = 1;
457 while (NRF_RADIO->EVENTS_TXREADY == 0) {
459 NRF_RADIO->EVENTS_TXREADY = 0;
462 NRF_RADIO->EVENTS_END = 0;
463 NRF_RADIO->TASKS_START = 1;
464 while (NRF_RADIO->EVENTS_END == 0) {
466 NRF_RADIO->EVENTS_END = 0;
467 if (!multicast && acksPerPipe[NRF_RADIO->TXADDRESS] ==
true) {
468 uint32_t rxAddress = NRF_RADIO->RXADDRESSES;
469 NRF_RADIO->RXADDRESSES = 1 << NRF_RADIO->TXADDRESS;
476 uint32_t realAckTimeout = ackTimeout;
478 if (NRF_RADIO->MODE == (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos)) {
490 realAckTimeout += 200;
496 uint32_t ack_timeout = micros();
497 while (!NRF_RADIO->EVENTS_CRCOK && !NRF_RADIO->EVENTS_CRCERROR) {
498 if (micros() - ack_timeout > realAckTimeout) {
502 if (NRF_RADIO->EVENTS_CRCOK) {
503 if (ackPayloadsEnabled &&
radioData[0] > 0) {
504#if defined CCM_ENCRYPTION_ENABLED
515#if defined CCM_ENCRYPTION_ENABLED
521 Serial.println(
"DECRYPT FAIL");
531 ackPayloadAvailable =
true;
532 ackAvailablePipeNo = NRF_RADIO->RXMATCH;
534 NRF_RADIO->EVENTS_CRCOK = 0;
539 NRF_RADIO->RXADDRESSES = rxAddress;
543 else if (NRF_RADIO->EVENTS_CRCERROR) {
544 NRF_RADIO->EVENTS_CRCERROR = 0;
546 uint32_t duration = 258 * retryDuration;
547 delayMicroseconds(duration);
552 NRF_RADIO->RXADDRESSES = rxAddress;
559 lastTxResult =
false;
568 uint8_t PID = ackPID;
570 PID = ((ackPID += 1) % 7) << 1;
576#if defined CCM_ENCRYPTION_ENABLED
578 uint32_t tmpCounter = 0;
585 while (!NRF_RNG->EVENTS_VALRDY) {
587 NRF_RNG->EVENTS_VALRDY = 0;
588 tmpIV[i] = NRF_RNG->VALUE;
589 ccmData.iv[i] = tmpIV[i];
591 tmpCounter = packetCounter;
592 ccmData.counter = tmpCounter;
601 if (packetCounter > 200000) {
619 uint8_t dataStart = 0;
621#if defined CCM_ENCRYPTION_ENABLED
628 dataStart = (!DPL && acksEnabled(0) ==
false) ? 0 : 2;
629#if defined CCM_ENCRYPTION_ENABLED
633#if defined CCM_ENCRYPTION_ENABLED
642#if defined CCM_ENCRYPTION_ENABLED
646 if (NRF_RADIO->STATE < 9) {
647 NRF_RADIO->EVENTS_TXREADY = 0;
648 NRF_RADIO->TASKS_TXEN = 1;
649 while (NRF_RADIO->EVENTS_TXREADY == 0) {
651 NRF_RADIO->EVENTS_TXREADY = 0;
654 NRF_RADIO->EVENTS_END = 0;
655 NRF_RADIO->TASKS_START = 1;
666#if defined CCM_ENCRYPTION_ENABLED
671 while (!NRF_RNG->EVENTS_VALRDY) {
673 NRF_RNG->EVENTS_VALRDY = 0;
674 ccmData.iv[i] = NRF_RNG->VALUE;
675 ackBuffer[i + 1] = ccmData.iv[i];
678 ccmData.counter = packetCounter;
688 if (packetCounter > 200000) {
695 memcpy(&ackBuffer[1], buf, len);
696#if defined CCM_ENCRYPTION_ENABLED
717 NRF_RADIO->EVENTS_DISABLED = 0;
718 NRF_RADIO->TASKS_DISABLE = 1;
719 while (NRF_RADIO->EVENTS_DISABLED == 0) {
721 NRF_RADIO->EVENTS_DISABLED = 0;
722 if (resetAddresses ==
true) {
724 NRF_RADIO->BASE0 = rxBase;
725 NRF_RADIO->PREFIX0 = rxPrefix;
729 NRF_RADIO->EVENTS_RXREADY = 0;
730 NRF_RADIO->EVENTS_CRCOK = 0;
731 NRF_RADIO->TASKS_RXEN = 1;
740 NRF_RADIO->EVENTS_DISABLED = 0;
741 NRF_RADIO->TASKS_DISABLE = 1;
742 while (NRF_RADIO->EVENTS_DISABLED == 0) {
744 NRF_RADIO->EVENTS_DISABLED = 0;
745 if (resetAddresses) {
746 NRF_RADIO->BASE0 = txBase;
747 NRF_RADIO->PREFIX0 = txPrefix;
749 if (setWritingPipe) {
750 NRF_RADIO->TXADDRESS = 0x00;
763 uint8_t size = min(staticPayloadSize, rxBuffer[0]);
772 uint32_t freq = NRF_RADIO->FREQUENCY;
773 NRF_RADIO->FREQUENCY = 0x4C;
774 if (NRF_RADIO->FREQUENCY == 0x4C) {
775 NRF_RADIO->FREQUENCY = freq;
794 for (
int i = 0; i < 8; i++) {
795 acksPerPipe[i] = enable;
807 acksPerPipe[pipe] = enable;
820 staticPayloadSize = payloadSize;
822 if (payloadSize <= 32) {
823 NRF_RADIO->PCNF0 = (0 << RADIO_PCNF0_S0LEN_Pos) | (6 << RADIO_PCNF0_LFLEN_Pos) | (3 << RADIO_PCNF0_S1LEN_Pos);
827 NRF_RADIO->PCNF0 = (0 << RADIO_PCNF0_S0LEN_Pos) | (8 << RADIO_PCNF0_LFLEN_Pos) | (3 << RADIO_PCNF0_S1LEN_Pos);
829 NRF_RADIO->PCNF1 = (RADIO_PCNF1_WHITEEN_Disabled << RADIO_PCNF1_WHITEEN_Pos) | (RADIO_PCNF1_ENDIAN_Big << RADIO_PCNF1_ENDIAN_Pos) | ((addressWidth - 1) << RADIO_PCNF1_BALEN_Pos) | (0 << RADIO_PCNF1_STATLEN_Pos) | (payloadSize << RADIO_PCNF1_MAXLEN_Pos);
839 uint8_t lenConfig = 0;
840 if (acksEnabled(0)) {
843 NRF_RADIO->PCNF0 = (lenConfig << RADIO_PCNF0_S0LEN_Pos) | (0 << RADIO_PCNF0_LFLEN_Pos) | (lenConfig << RADIO_PCNF0_S1LEN_Pos);
845 NRF_RADIO->PCNF1 = (RADIO_PCNF1_WHITEEN_Disabled << RADIO_PCNF1_WHITEEN_Pos) | (RADIO_PCNF1_ENDIAN_Big << RADIO_PCNF1_ENDIAN_Pos) | ((addressWidth - 1) << RADIO_PCNF1_BALEN_Pos) | (staticPayloadSize << RADIO_PCNF1_STATLEN_Pos) | (staticPayloadSize << RADIO_PCNF1_MAXLEN_Pos);
852 staticPayloadSize = size;
855 uint8_t lenConfig = 0;
856 if (acksEnabled(0)) {
859 NRF_RADIO->PCNF0 = (lenConfig << RADIO_PCNF0_S0LEN_Pos) | (0 << RADIO_PCNF0_LFLEN_Pos) | (lenConfig << RADIO_PCNF0_S1LEN_Pos);
861 NRF_RADIO->PCNF1 = (RADIO_PCNF1_WHITEEN_Disabled << RADIO_PCNF1_WHITEEN_Pos) | (RADIO_PCNF1_ENDIAN_Big << RADIO_PCNF1_ENDIAN_Pos) | ((addressWidth - 1) << RADIO_PCNF1_BALEN_Pos) | (staticPayloadSize << RADIO_PCNF1_STATLEN_Pos) | (staticPayloadSize << RADIO_PCNF1_MAXLEN_Pos);
868 return staticPayloadSize;
877 retryDuration = retryVar;
886 uint32_t base = address >> 8;
887 uint32_t prefix = address & 0xFF;
892 prefix = prefix >> 24;
895 NRF_RADIO->PREFIX0 = rxPrefix;
896 NRF_RADIO->BASE0 = base;
897 NRF_RADIO->PREFIX0 &= ~(0xFF);
898 NRF_RADIO->PREFIX0 |= prefix;
899 rxBase = NRF_RADIO->BASE0;
900 rxPrefix = NRF_RADIO->PREFIX0;
902 else if (child < 4) {
903 NRF_RADIO->PREFIX0 = rxPrefix;
904 NRF_RADIO->BASE1 = base;
905 NRF_RADIO->PREFIX0 &= ~(0xFF << (8 * child));
906 NRF_RADIO->PREFIX0 |= prefix << (8 * child);
907 rxPrefix = NRF_RADIO->PREFIX0;
910 NRF_RADIO->BASE1 = base;
911 NRF_RADIO->PREFIX1 &= ~(0xFF << (8 * (child - 4)));
912 NRF_RADIO->PREFIX1 |= prefix << (8 * (child - 4));
914 NRF_RADIO->RXADDRESSES |= 1 << child;
925 uint32_t base = address >> 8;
926 uint32_t prefix = address & 0xFF;
930 prefix = prefix >> 24;
932 NRF_RADIO->BASE0 = base;
933 NRF_RADIO->PREFIX0 &= 0xFFFFFF00;
934 NRF_RADIO->PREFIX0 |= prefix;
935 NRF_RADIO->TXADDRESS = 0x00;
936 txBase = NRF_RADIO->BASE0;
937 txPrefix = NRF_RADIO->PREFIX0;
951 uint8_t prefixArray[5];
952 prefixArray[0] = address[0];
954 prefix = prefix >> 24;
958 NRF_RADIO->PREFIX0 = rxPrefix;
959 NRF_RADIO->BASE0 = base;
960 NRF_RADIO->PREFIX0 &= ~(0xFF);
961 NRF_RADIO->PREFIX0 |= prefix;
962 rxBase = NRF_RADIO->BASE0;
963 rxPrefix = NRF_RADIO->PREFIX0;
965 else if (child < 4) {
966 NRF_RADIO->PREFIX0 = rxPrefix;
967 NRF_RADIO->BASE1 = base;
968 NRF_RADIO->PREFIX0 &= ~(0xFF << (8 * child));
969 NRF_RADIO->PREFIX0 |= prefix << (8 * child);
970 rxPrefix = NRF_RADIO->PREFIX0;
973 NRF_RADIO->BASE1 = base;
974 NRF_RADIO->PREFIX1 &= ~(0xFF << (8 * (child - 4)));
975 NRF_RADIO->PREFIX1 |= prefix << (8 * (child - 4));
977 NRF_RADIO->RXADDRESSES |= 1 << child;
994 prefix = prefix >> 24;
996 NRF_RADIO->BASE0 = base;
997 NRF_RADIO->PREFIX0 &= 0xFFFFFF00;
998 NRF_RADIO->PREFIX0 |= prefix;
999 NRF_RADIO->TXADDRESS = 0x00;
1000 txBase = NRF_RADIO->BASE0;
1001 txPrefix = NRF_RADIO->PREFIX0;
1009 if (NRF_RADIO->STATE == 11) {
1010 while (NRF_RADIO->EVENTS_END == 0) {
1012 NRF_RADIO->EVENTS_END = 0;
1015 NRF_RADIO->EVENTS_DISABLED = 0;
1016 NRF_RADIO->TASKS_DISABLE = 1;
1017 while (NRF_RADIO->EVENTS_DISABLED == 0) {
1019 NRF_RADIO->EVENTS_DISABLED = 0;
1021 return lastTxResult;
1029 if (NRF_RADIO->STATE == 11) {
1030 while (NRF_RADIO->EVENTS_END == 0) {
1032 NRF_RADIO->EVENTS_END = 0;
1035 NRF_RADIO->EVENTS_DISABLED = 0;
1036 NRF_RADIO->TASKS_DISABLE = 1;
1037 while (NRF_RADIO->EVENTS_DISABLED == 0) {
1039 NRF_RADIO->EVENTS_DISABLED = 0;
1041 return lastTxResult;
1048 lastTxResult =
write((
void*)buf, len, multicast);
1049 return lastTxResult;
1054bool nrf_to_nrf::acksEnabled(uint8_t pipe)
1057 if (acksPerPipe[pipe]) {
1073 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos);
1081 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_2Mbit << RADIO_MODE_MODE_Pos);
1093 uint8_t paLevel = 0x00;
1107 NRF_RADIO->TXPOWER = paLevel;
1115 uint8_t paLevel = NRF_RADIO->TXPOWER;
1147 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_Two;
1148 NRF_RADIO->CRCINIT = 0xFFFFUL;
1149 NRF_RADIO->CRCPOLY = 0x11021UL;
1152 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_One;
1153 NRF_RADIO->CRCINIT = 0xFFUL;
1154 NRF_RADIO->CRCPOLY = 0x107UL;
1157 NRF_RADIO->CRCCNF = 0;
1158 NRF_RADIO->CRCINIT = 0x00L;
1159 NRF_RADIO->CRCPOLY = 0x00UL;
1167 if (NRF_RADIO->CRCCNF == 0) {
1170 else if (NRF_RADIO->CRCCNF == RADIO_CRCCNF_LEN_One) {
1183 NRF_RADIO->EVENTS_RSSIEND = 0;
1184 NRF_RADIO->TASKS_RSSISTART = 1;
1185 while (!NRF_RADIO->EVENTS_RSSIEND) {
1187 if (NRF_RADIO->RSSISAMPLE < RSSI) {
1204 NRF_RADIO->EVENTS_RSSIEND = 0;
1205 NRF_RADIO->TASKS_RSSISTART = 1;
1206 while (!NRF_RADIO->EVENTS_RSSIEND) {
1208 return (uint8_t)NRF_RADIO->RSSISAMPLE;
1215 NRF_RADIO->POWER = 1;
1222 NRF_RADIO->POWER = 0;
1229 addressWidth = a_width;
1233 pSize = staticPayloadSize;
1236 NRF_RADIO->PCNF1 = (RADIO_PCNF1_WHITEEN_Disabled << RADIO_PCNF1_WHITEEN_Pos) | (RADIO_PCNF1_ENDIAN_Big << RADIO_PCNF1_ENDIAN_Pos) | ((a_width - 1) << RADIO_PCNF1_BALEN_Pos) | (pSize << RADIO_PCNF1_STATLEN_Pos) | (staticPayloadSize << RADIO_PCNF1_MAXLEN_Pos);
1244 Serial.println(
"================ Radio Configuration ================");
1245 Serial.print(
"STATUS\t\t= ");
1246 Serial.println(NRF_RADIO->STATE);
1249 Serial.print(
"RX_ADDR_P0-1\t= 0x");
1250 uint32_t base =
addrConv32(NRF_RADIO->BASE0);
1251 for (
int i = addressWidth - 2; i > -1; i--) {
1252 Serial.print((base >> (i * 8)) & 0xFF, HEX);
1254 uint32_t prefixes =
addrConv32(NRF_RADIO->PREFIX0);
1255 uint8_t prefix = (prefixes >> 24) & 0xFF;
1256 Serial.print(prefix, HEX);
1257 Serial.print(
" 0x");
1259 for (
int i = addressWidth - 2; i > -1; i--) {
1260 Serial.print((base >> (i * 8)) & 0xFF, HEX);
1262 prefix = (prefixes >> 16) & 0xFF;
1263 Serial.println(prefix, HEX);
1265 Serial.print(
"RX_ADDR_P2-7\t= 0x");
1266 prefix = (prefixes >> 8) & 0xFF;
1267 Serial.print(prefix, HEX);
1268 Serial.print(
" 0x");
1269 prefix = (prefixes)&0xFF;
1270 Serial.print(prefix, HEX);
1271 Serial.print(
" 0x");
1273 prefix = (prefixes >> 24) & 0xFF;
1274 Serial.print(prefix, HEX);
1275 Serial.print(
" 0x");
1276 prefix = (prefixes >> 16) & 0xFF;
1277 Serial.print(prefix, HEX);
1278 Serial.print(
" 0x");
1279 prefix = (prefixes >> 8) & 0xFF;
1280 Serial.print(prefix, HEX);
1281 Serial.print(
" 0x");
1282 prefix = (prefixes)&0xFF;
1283 Serial.println(prefix, HEX);
1286 for (
int i = 0; i < 6; i++) {
1287 enAA |= acksPerPipe[i] << i;
1289 Serial.print(
"EN_AA\t\t= 0x");
1290 Serial.println(enAA, HEX);
1291 Serial.print(
"EN_RXADDR\t= 0x");
1292 Serial.println(NRF_RADIO->RXADDRESSES, HEX);
1293 Serial.print(
"RF_CH\t\t= 0x");
1294 Serial.println(NRF_RADIO->FREQUENCY, HEX);
1295 Serial.println(
"DYNPD/FEATURE\t= 0x");
1296 Serial.print(
"Data Rate\t= ");
1297 Serial.println(NRF_RADIO->MODE ?
"2 MBPS" :
"1MBPS");
1298 Serial.println(
"Model\t\t= NRF52");
1299 Serial.print(
"CRC Length\t= ");
1302 Serial.println(
"16 bits");
1305 Serial.println(
"8 bits");
1308 Serial.println(
"Disabled");
1310 Serial.print(
"PA Power\t= ");
1313 Serial.println(
"PA_MAX");
1316 Serial.println(
"PA_HIGH");
1319 Serial.println(
"PA_LOW");
1322 Serial.println(
"PA_MIN");
1325 Serial.println(
"?");
1327 Serial.print(
"ARC\t\t= ");
1328 Serial.println(ARC);
1333#if defined CCM_ENCRYPTION_ENABLED
1353 NRF_CCM->EVENTS_ENDKSGEN = 0;
1354 NRF_CCM->EVENTS_ENDCRYPT = 0;
1355 NRF_CCM->TASKS_KSGEN = 1;
1356 while (!NRF_CCM->EVENTS_ENDCRYPT) {
1359 if (NRF_CCM->EVENTS_ERROR) {
1377 memcpy(&inBuffer[3], bufferIn, size);
1385 NRF_CCM->EVENTS_ENDKSGEN = 0;
1386 NRF_CCM->EVENTS_ENDCRYPT = 0;
1387 NRF_CCM->TASKS_KSGEN = 1;
1389 while (!NRF_CCM->EVENTS_ENDCRYPT) {
1392 if (NRF_CCM->EVENTS_ERROR) {
1411 ccmData.counter = counter;
1412 packetCounter = counter;
1420 ccmData.iv[i] = IV[i];
void startListening(bool resetAddresses=true)
void openReadingPipe(uint8_t child, const uint8_t *address)
void setPALevel(uint8_t level, bool lnaEnable=true)
bool testCarrier(uint8_t RSSI=65)
uint8_t decrypt(void *bufferIn, uint8_t size)
uint8_t radioData[ACTUAL_MAX_PAYLOAD_SIZE+2]
void setChannel(uint8_t channel)
uint32_t addrConv32(uint32_t addr)
void disableDynamicPayloads()
bool write(void *buf, uint8_t len, bool multicast=false, bool doEncryption=true)
bool testRPD(uint8_t RSSI=65)
void setCounter(uint64_t counter)
void setAddressWidth(uint8_t a_width)
uint8_t getDynamicPayloadSize()
bool setDataRate(uint8_t speed)
void setKey(uint8_t key[CCM_KEY_SIZE])
bool writeAckPayload(uint8_t pipe, void *buf, uint8_t len)
void enableDynamicPayloads(uint8_t payloadSize=DEFAULT_MAX_PAYLOAD_SIZE)
uint8_t encrypt(void *bufferIn, uint8_t size)
bool startWrite(void *buf, uint8_t len, bool multicast, bool doEncryption=true)
uint8_t outBuffer[MAX_PACKET_SIZE+CCM_MIC_SIZE+CCM_START_SIZE]
void setRetries(uint8_t retryVar, uint8_t attempts)
void openWritingPipe(const uint8_t *address)
void setCRCLength(nrf_crclength_e length)
bool writeFast(void *buf, uint8_t len, bool multicast=0)
void setAutoAck(bool enable)
void read(void *buf, uint8_t len)
void stopListening(bool setWritingPipe=true, bool resetAddresses=true)
void setIV(uint8_t IV[CCM_IV_SIZE])
void setPayloadSize(uint8_t size)
nrf_crclength_e getCRCLength()
#define RADIO_MODE_MODE_Nrf_250Kbit
static uint32_t bytewise_bit_swap(uint8_t const *p_inp)
static uint32_t addr_conv(uint8_t const *p_addr)
#define ACK_TIMEOUT_1MBPS_OFFSET
#define DEFAULT_MAX_PAYLOAD_SIZE
#define ACK_PAYLOAD_TIMEOUT_OFFSET
#define ACK_TIMEOUT_250KBPS_OFFSET
#define ACK_TIMEOUT_250KBPS
#define ACK_TIMEOUT_2MBPS
#define ACTUAL_MAX_PAYLOAD_SIZE
#define ACK_TIMEOUT_2MBPS_OFFSET
#define ACK_TIMEOUT_1MBPS