6 #define __REV(x) __builtin_bswap32(x);
9#if defined(NRF52832_XXAA) || defined(NRF52832_XXAB) || defined(NRF52811_XXAA) || defined(NRF52810_XXAA) || defined(NRF52805_XXAA)
11 #define TXPOWER_PA_MIN 0xF4
12 #define TXPOWER_PA_LOW 0xFC
13 #define TXPOWER_PA_HIGH 0x00
14 #define TXPOWER_PA_MAX 0x04
15#elif !defined(ARDUINO_NRF54L15)
17 #define TXPOWER_PA_MIN 0xF4
18 #define TXPOWER_PA_LOW 0x02
19 #define TXPOWER_PA_HIGH 0x06
20 #define TXPOWER_PA_MAX 0x08
22 #define TXPOWER_PA_MIN 0x6
23 #define TXPOWER_PA_LOW 0x1F
24 #define TXPOWER_PA_HIGH 0x33
25 #define TXPOWER_PA_MAX 0x3F
29#ifndef RADIO_MODE_MODE_Nrf_250Kbit
30 #define RADIO_MODE_MODE_Nrf_250Kbit (2UL)
32#ifdef ARDUINO_NRF54L15
33 #define RADIO_MODE_MODE_Nrf_4Mbit_OBT4 (10UL)
34 #define RADIO_MODE_MODE_Nrf_4Mbit_OBT6 (9UL)
37#define DEFAULT_TIMEOUT 250
43 uint32_t start = millis();
45 if (millis() - start > timeout) {
57 uint32_t inp = (p_inp[3] << 24) | (p_inp[2] << 16) | (p_inp[1] << 8) | (p_inp[0]);
58 inp = (inp & 0xF0F0F0F0) >> 4 | (inp & 0x0F0F0F0F) << 4;
59 inp = (inp & 0xCCCCCCCC) >> 2 | (inp & 0x33333333) << 2;
60 inp = (inp & 0xAAAAAAAA) >> 1 | (inp & 0x55555555) << 1;
79 buffer[0] = addr & 0xFF;
80 buffer[1] = (addr >> 8) & 0xFF;
81 buffer[2] = (addr >> 16) & 0xFF;
82 buffer[3] = (addr >> 24) & 0xFF;
92 staticPayloadSize = 32;
95 ackPayloadsEnabled =
false;
100 payloadAvailable =
false;
101#ifndef ARDUINO_NRF54L15
107#if defined CCM_ENCRYPTION_ENABLED
108 NRF_CCM->INPTR = (uint32_t)inBuffer;
110 NRF_CCM->CNFPTR = (uint32_t)&ccmData;
111 NRF_CCM->SCRATCHPTR = (uint32_t)scratchPTR;
112 ccmData.counter = 12345;
122#ifndef ARDUINO_NRF54L15
123 NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
124 NRF_CLOCK->TASKS_HFCLKSTART = 1;
130 NRF_POWER->TASKS_CONSTLAT = 1;
131 NRF_CLOCK->EVENTS_XOSTARTED = 0;
132 NRF_CLOCK->TASKS_XOSTART = 1;
138 NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
139 NRF_CLOCK->TASKS_LFCLKSTART = 1;
145#ifndef ARDUINO_NRF54L15
146 NRF_RADIO->POWER = 1;
149 NRF_RADIO->PCNF0 = (1 << RADIO_PCNF0_S0LEN_Pos) | (0 << RADIO_PCNF0_LFLEN_Pos) | (1 << RADIO_PCNF0_S1LEN_Pos);
151 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);
153 NRF_RADIO->BASE0 = 0xE7E7E7E7;
154 NRF_RADIO->BASE1 = 0x43434343;
155 NRF_RADIO->PREFIX0 = 0x23C343E7;
156 NRF_RADIO->PREFIX1 = 0x13E363A3;
157 NRF_RADIO->RXADDRESSES = 0x01;
158 NRF_RADIO->TXADDRESS = 0x00;
160 txBase = NRF_RADIO->BASE0;
161 txPrefix = NRF_RADIO->PREFIX0;
162 rxBase = NRF_RADIO->BASE0;
163 rxPrefix = NRF_RADIO->PREFIX0;
165 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_Two;
166 NRF_RADIO->CRCINIT = 0xFFFFUL;
167 NRF_RADIO->CRCPOLY = 0x11021UL;
169 NRF_RADIO->PACKETPTR = (uint32_t)
radioData;
170 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos);
172#ifndef ARDUINO_NRF54L15
173 NRF_RADIO->MODECNF0 = 0x201;
175 NRF_RADIO->TIMING = 0x1;
177 NRF_RADIO->TXPOWER = (
TXPOWER_PA_MAX << RADIO_TXPOWER_TXPOWER_Pos);
178 NRF_RADIO->FREQUENCY = 0x4C;
184#ifdef ARDUINO_NRF54L15
185 NRF_RADIO->TASKS_START = 1;
193#ifdef NRF_HAS_ENERGY_DETECT
194 #define ED_RSSISCALE 4
195uint8_t nrf_to_nrf::sample_ed(
void)
198 NRF_RADIO->TASKS_EDSTART = 1;
202 val = NRF_RADIO->EDSAMPLE;
203 return (uint8_t)(val > 63
205 : val * ED_RSSISCALE);
213 uint8_t pipe_num = 0;
222 if (payloadAvailable) {
223 *pipe_num = (uint8_t)NRF_RADIO->RXMATCH;
228 if (ackPayloadAvailable) {
229 *pipe_num = ackAvailablePipeNo;
233 if (NRF_RADIO->EVENTS_CRCOK) {
234 NRF_RADIO->EVENTS_CRCOK = 0;
237 return restartReturnRx();
241 *pipe_num = (uint8_t)NRF_RADIO->RXMATCH;
242 if (!DPL && acksEnabled(*pipe_num) ==
false) {
243#if defined CCM_ENCRYPTION_ENABLED
251 memcpy(&rxBuffer[1], &
radioData[0], staticPayloadSize);
252#if defined CCM_ENCRYPTION_ENABLED
257#if defined CCM_ENCRYPTION_ENABLED
274 memcpy(&rxBuffer[1], &
radioData[2], staticPayloadSize);
276#if defined CCM_ENCRYPTION_ENABLED
281 rxFifoAvailable =
true;
282 uint8_t packetCtr = 0;
289 rxBuffer[0] = staticPayloadSize;
293 uint16_t packetData = NRF_RADIO->RXCRC;
295 if (acksEnabled(NRF_RADIO->RXMATCH)) {
297 uint32_t txAddress = NRF_RADIO->TXADDRESS;
298 NRF_RADIO->TXADDRESS = NRF_RADIO->RXMATCH;
299 delayMicroseconds(75);
300 if (ackPayloadsEnabled) {
301 if (*pipe_num == ackPipe) {
302 write(&ackBuffer[1], ackBuffer[0], 1, 0);
309 uint8_t payloadSize = 0;
319 NRF_RADIO->TXADDRESS = txAddress;
324 if (NRF_RADIO->CRCCNF != 0) {
325 if (packetCtr == lastPacketCounter && packetData == lastData) {
326 return restartReturnRx();
331#if defined CCM_ENCRYPTION_ENABLED
333 uint8_t bufferLength = 0;
340 if (!
decrypt(&rxBuffer[1], bufferLength)) {
341 Serial.println(
"DECRYPT FAIL");
342 return restartReturnRx();
345 memset(&rxBuffer[1], 0,
sizeof(rxBuffer) - 1);
356 lastPacketCounter = packetCtr;
357 lastData = packetData;
359 if (inRxMode && !acksEnabled(NRF_RADIO->RXMATCH)) {
360 NRF_RADIO->TASKS_START = 1;
362 if ((DPL && rxBuffer[0]) || !DPL) {
363 payloadAvailable =
true;
367 if (NRF_RADIO->EVENTS_CRCERROR) {
368 NRF_RADIO->EVENTS_CRCERROR = 0;
369 NRF_RADIO->TASKS_START = 1;
376bool nrf_to_nrf::restartReturnRx()
379 NRF_RADIO->TASKS_START = 1;
388 memcpy(buf, &rxBuffer[1], len);
389 ackPayloadAvailable =
false;
390 payloadAvailable =
false;
398 uint8_t PID = ackPID;
400 PID = ((ackPID += 1) % 7) << 1;
405 uint8_t payloadSize = 0;
407#if defined CCM_ENCRYPTION_ENABLED
415 NRF_RNG->EVENTS_VALRDY = 0;
416 ccmData.iv[i] = NRF_RNG->VALUE;
418 ccmData.counter = packetCounter;
426 if (packetCounter > 200000) {
433 for (
int i = 0; i < (retries + 1); i++) {
444 uint8_t dataStart = 0;
446#if defined CCM_ENCRYPTION_ENABLED
453 dataStart = (!DPL && acksEnabled(0) ==
false) ? 0 : 2;
454#if defined CCM_ENCRYPTION_ENABLED
458#if defined CCM_ENCRYPTION_ENABLED
467#if defined CCM_ENCRYPTION_ENABLED
470#ifdef ARDUINO_NRF54L15
471 uint32_t timeout = millis();
472 while (NRF_RADIO->STATE != 10) {
474 if (millis() - timeout > 250) {
479 NRF_RADIO->EVENTS_END = 0;
480 NRF_RADIO->TASKS_START = 1;
484 NRF_RADIO->EVENTS_END = 0;
485 if (!multicast && acksPerPipe[NRF_RADIO->TXADDRESS] ==
true) {
486 uint32_t rxAddress = NRF_RADIO->RXADDRESSES;
487 NRF_RADIO->RXADDRESSES = 1 << NRF_RADIO->TXADDRESS;
494 int32_t realAckTimeout = (int32_t)ackTimeout;
496 if (NRF_RADIO->MODE == (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos)) {
508 realAckTimeout += 200;
514 if (realAckTimeout < 0) {
518 uint32_t ack_timeout = micros();
519 while (!NRF_RADIO->EVENTS_CRCOK && !NRF_RADIO->EVENTS_CRCERROR) {
520 if (micros() - ack_timeout > realAckTimeout) {
524 if (NRF_RADIO->EVENTS_CRCOK) {
525 if (ackPayloadsEnabled &&
radioData[0] > 0) {
526#if defined CCM_ENCRYPTION_ENABLED
537#if defined CCM_ENCRYPTION_ENABLED
543 Serial.println(
"DECRYPT FAIL");
553 ackPayloadAvailable =
true;
554 ackAvailablePipeNo = NRF_RADIO->RXMATCH;
556 NRF_RADIO->EVENTS_CRCOK = 0;
561 NRF_RADIO->RXADDRESSES = rxAddress;
565 else if (NRF_RADIO->EVENTS_CRCERROR) {
566 NRF_RADIO->EVENTS_CRCERROR = 0;
568 uint32_t duration = 258 * retryDuration;
569 delayMicroseconds(duration);
574 NRF_RADIO->RXADDRESSES = rxAddress;
581 lastTxResult =
false;
590 uint8_t PID = ackPID;
592 PID = ((ackPID += 1) % 7) << 1;
598#if defined CCM_ENCRYPTION_ENABLED
600 uint32_t tmpCounter = 0;
608 NRF_RNG->EVENTS_VALRDY = 0;
609 tmpIV[i] = NRF_RNG->VALUE;
610 ccmData.iv[i] = tmpIV[i];
612 tmpCounter = packetCounter;
613 ccmData.counter = tmpCounter;
621 if (packetCounter > 200000) {
639 uint8_t dataStart = 0;
641#if defined CCM_ENCRYPTION_ENABLED
648 dataStart = (!DPL && acksEnabled(0) ==
false) ? 0 : 2;
649#if defined CCM_ENCRYPTION_ENABLED
653#if defined CCM_ENCRYPTION_ENABLED
662#if defined CCM_ENCRYPTION_ENABLED
666 NRF_RADIO->EVENTS_END = 0;
667 NRF_RADIO->TASKS_START = 1;
678#if defined CCM_ENCRYPTION_ENABLED
685 NRF_RNG->EVENTS_VALRDY = 0;
686 ccmData.iv[i] = NRF_RNG->VALUE;
687 ackBuffer[i + 1] = ccmData.iv[i];
690 ccmData.counter = packetCounter;
700 if (packetCounter > 200000) {
707 memcpy(&ackBuffer[1], buf, len);
708#if defined CCM_ENCRYPTION_ENABLED
729 NRF_RADIO->EVENTS_DISABLED = 0;
730 NRF_RADIO->TASKS_DISABLE = 1;
733 NRF_RADIO->EVENTS_DISABLED = 0;
735 if (resetAddresses ==
true) {
736 NRF_RADIO->BASE0 = rxBase;
737 NRF_RADIO->PREFIX0 = rxPrefix;
738#ifndef ARDUINO_NRF54L15
739 NRF_RADIO->MODECNF0 = 0x201;
741 NRF_RADIO->TIMING = 0x1;
746 NRF_RADIO->SHORTS = 0x0;
748 NRF_RADIO->EVENTS_RXREADY = 0;
749 NRF_RADIO->EVENTS_CRCOK = 0;
750 NRF_RADIO->TASKS_RXEN = 1;
754 NRF_RADIO->TASKS_START = 1;
762 NRF_RADIO->EVENTS_DISABLED = 0;
763 NRF_RADIO->TASKS_DISABLE = 1;
766 NRF_RADIO->EVENTS_DISABLED = 0;
768 if (resetAddresses) {
769 NRF_RADIO->BASE0 = txBase;
770 NRF_RADIO->PREFIX0 = txPrefix;
772 if (setWritingPipe) {
773 NRF_RADIO->TXADDRESS = 0x00;
775#ifndef ARDUINO_NRF54L15
776 NRF_RADIO->MODECNF0 = 0x200;
778 NRF_RADIO->TIMING = 0x0;
781#ifndef ARDUINO_NRF54L15
782 NRF_RADIO->SHORTS = 0x6;
784 NRF_RADIO->SHORTS = 0x80004;
786 if (NRF_RADIO->STATE < 9) {
787 NRF_RADIO->EVENTS_TXREADY = 0;
788 NRF_RADIO->TASKS_TXEN = 1;
791 NRF_RADIO->EVENTS_TXREADY = 0;
809 uint8_t size = min(staticPayloadSize, rxBuffer[0]);
818 uint32_t freq = NRF_RADIO->FREQUENCY;
819 NRF_RADIO->FREQUENCY = 0x4C;
820 if (NRF_RADIO->FREQUENCY == 0x4C) {
821 NRF_RADIO->FREQUENCY = freq;
829void nrf_to_nrf::setChannel(uint8_t channel,
bool map) { NRF_RADIO->FREQUENCY = channel | map << RADIO_FREQUENCY_MAP_Pos; }
840 for (
int i = 0; i < 8; i++) {
841 acksPerPipe[i] = enable;
853 acksPerPipe[pipe] = enable;
866 staticPayloadSize = payloadSize;
868 if (payloadSize <= 63) {
869 NRF_RADIO->PCNF0 = (0 << RADIO_PCNF0_S0LEN_Pos) | (6 << RADIO_PCNF0_LFLEN_Pos) | (3 << RADIO_PCNF0_S1LEN_Pos);
873 NRF_RADIO->PCNF0 = (0 << RADIO_PCNF0_S0LEN_Pos) | (8 << RADIO_PCNF0_LFLEN_Pos) | (3 << RADIO_PCNF0_S1LEN_Pos);
876 NRF_RADIO->PCNF1 &= ~(0xFF << RADIO_PCNF1_MAXLEN_Pos | 0xFF << RADIO_PCNF1_STATLEN_Pos);
877 NRF_RADIO->PCNF1 |= payloadSize << RADIO_PCNF1_MAXLEN_Pos;
887 uint8_t lenConfig = 0;
888 if (acksEnabled(0)) {
891 NRF_RADIO->PCNF0 = (lenConfig << RADIO_PCNF0_S0LEN_Pos) | (0 << RADIO_PCNF0_LFLEN_Pos) | (lenConfig << RADIO_PCNF0_S1LEN_Pos);
893 NRF_RADIO->PCNF1 &= ~(0xFF << RADIO_PCNF1_MAXLEN_Pos | 0xFF << RADIO_PCNF1_STATLEN_Pos);
894 NRF_RADIO->PCNF1 |= staticPayloadSize << RADIO_PCNF1_STATLEN_Pos | staticPayloadSize << RADIO_PCNF1_MAXLEN_Pos;
901 staticPayloadSize = size;
904 uint8_t lenConfig = 0;
905 if (acksEnabled(0)) {
908 NRF_RADIO->PCNF0 = (lenConfig << RADIO_PCNF0_S0LEN_Pos) | (0 << RADIO_PCNF0_LFLEN_Pos) | (lenConfig << RADIO_PCNF0_S1LEN_Pos);
910 NRF_RADIO->PCNF1 &= ~(0xFF << RADIO_PCNF1_MAXLEN_Pos | 0xFF << RADIO_PCNF1_STATLEN_Pos);
911 NRF_RADIO->PCNF1 |= staticPayloadSize << RADIO_PCNF1_STATLEN_Pos | staticPayloadSize << RADIO_PCNF1_MAXLEN_Pos;
918 return staticPayloadSize;
927 retryDuration = retryVar;
935 uint32_t prefix =
addrConv32(address & 0xFF) >> 24;
945 uint32_t prefix =
addrConv32(address & 0xFF) >> 24;
955 uint32_t prefix =
addr_conv(&address[0]) >> 24;
967 NRF_RADIO->PREFIX0 = rxPrefix;
968 NRF_RADIO->BASE0 = base;
969 NRF_RADIO->PREFIX0 &= ~(0xFF);
970 NRF_RADIO->PREFIX0 |= prefix;
971 rxBase = NRF_RADIO->BASE0;
972 rxPrefix = NRF_RADIO->PREFIX0;
974 else if (child < 4) {
975 NRF_RADIO->PREFIX0 = rxPrefix;
976 NRF_RADIO->BASE1 = base;
977 NRF_RADIO->PREFIX0 &= ~(0xFF << (8 * child));
978 NRF_RADIO->PREFIX0 |= prefix << (8 * child);
979 rxPrefix = NRF_RADIO->PREFIX0;
982 NRF_RADIO->BASE1 = base;
983 NRF_RADIO->PREFIX1 &= ~(0xFF << (8 * (child - 4)));
984 NRF_RADIO->PREFIX1 |= prefix << (8 * (child - 4));
986 NRF_RADIO->RXADDRESSES |= 1 << child;
995 uint32_t prefix =
addr_conv(&address[0]) >> 24;
1005 NRF_RADIO->BASE0 = base;
1006 NRF_RADIO->PREFIX0 &= ~(0xFF);
1007 NRF_RADIO->PREFIX0 |= prefix;
1008 NRF_RADIO->TXADDRESS = 0x00;
1009 txBase = NRF_RADIO->BASE0;
1010 txPrefix = NRF_RADIO->PREFIX0;
1016 return lastTxResult;
1023 return lastTxResult;
1030 lastTxResult =
write(buf, len, multicast);
1031 return lastTxResult;
1036bool nrf_to_nrf::acksEnabled(uint8_t pipe)
1039 if (acksPerPipe[pipe]) {
1055 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos);
1063 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_2Mbit << RADIO_MODE_MODE_Pos);
1066#ifdef ARDUINO_NRF54L15
1067 else if (speed == NRF_4MBPS_OBT4) {
1068 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_4Mbit_OBT4 << RADIO_MODE_MODE_Pos);
1072 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_4Mbit_OBT6 << RADIO_MODE_MODE_Pos);
1085 uint8_t paLevel = 0x00;
1099 NRF_RADIO->TXPOWER = paLevel;
1107 uint8_t paLevel = NRF_RADIO->TXPOWER;
1138 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_Three;
1139 NRF_RADIO->CRCINIT = 0x555555UL;
1140 NRF_RADIO->CRCPOLY = 0x65BUL;
1143 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_Two;
1144 NRF_RADIO->CRCINIT = 0xFFFFUL;
1145 NRF_RADIO->CRCPOLY = 0x11021UL;
1148 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_One;
1149 NRF_RADIO->CRCINIT = 0xFFUL;
1150 NRF_RADIO->CRCPOLY = 0x107UL;
1153 NRF_RADIO->CRCCNF = 0;
1154 NRF_RADIO->CRCINIT = 0x00L;
1155 NRF_RADIO->CRCPOLY = 0x00UL;
1163 if (NRF_RADIO->CRCCNF == 0) {
1166 else if (NRF_RADIO->CRCCNF == RADIO_CRCCNF_LEN_One) {
1169 if (NRF_RADIO->CRCCNF == RADIO_CRCCNF_LEN_Two) {
1181#ifndef ARDUINO_NRF54L15
1182 NRF_RADIO->EVENTS_RSSIEND = 0;
1183 NRF_RADIO->TASKS_RSSISTART = 1;
1187 if (NRF_RADIO->RSSISAMPLE < RSSI) {
1205#ifndef ARDUINO_NRF54L15
1206 NRF_RADIO->EVENTS_RSSIEND = 0;
1207 NRF_RADIO->TASKS_RSSISTART = 1;
1211 return (uint8_t)NRF_RADIO->RSSISAMPLE;
1227#ifndef ARDUINO_NRF54L15
1228 NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
1229 NRF_CLOCK->TASKS_HFCLKSTART = 1;
1234 NRF_RADIO->POWER = 1;
1236 NRF_POWER->TASKS_CONSTLAT = 1;
1237 NRF_CLOCK->EVENTS_XOSTARTED = 0;
1238 NRF_CLOCK->TASKS_XOSTART = 1;
1243#ifdef CCM_ENCRYPTION_ENABLED
1245 NRF_RNG->CONFIG = 1;
1246 NRF_RNG->TASKS_START = 1;
1247 NRF_CCM->ENABLE = 2;
1256#ifndef ARDUINO_NRF54L15
1257 NRF_RADIO->POWER = 0;
1258 NRF_CLOCK->TASKS_HFCLKSTOP = 1;
1260 NRF_CLOCK->TASKS_XOSTOP = 1;
1263#ifdef CCM_ENCRYPTION_ENABLED
1265 NRF_RNG->TASKS_STOP = 1;
1266 NRF_RNG->CONFIG = 0;
1267 NRF_CCM->ENABLE = 0;
1275 NRF_RADIO->PCNF1 &= ~(0xFF << RADIO_PCNF1_BALEN_Pos);
1276 NRF_RADIO->PCNF1 |= (a_width - 1) << RADIO_PCNF1_BALEN_Pos;
1283 uint8_t addressWidth = ((NRF_RADIO->PCNF1 >> 16) & 0xFF) + 1;
1285 Serial.println(
"================ Radio Configuration ================");
1286 Serial.print(
"STATUS\t\t= ");
1287 Serial.println(NRF_RADIO->STATE);
1290 Serial.print(
"RX_ADDR_P0-1\t= 0x");
1291 uint32_t base =
addrConv32(NRF_RADIO->BASE0);
1292 for (
int i = addressWidth - 2; i > -1; i--) {
1293 Serial.print((base >> (i * 8)) & 0xFF, HEX);
1295 uint32_t prefixes =
addrConv32(NRF_RADIO->PREFIX0);
1296 uint8_t prefix = (prefixes >> 24) & 0xFF;
1297 Serial.print(prefix, HEX);
1298 Serial.print(
" 0x");
1300 for (
int i = addressWidth - 2; i > -1; i--) {
1301 Serial.print((base >> (i * 8)) & 0xFF, HEX);
1303 prefix = (prefixes >> 16) & 0xFF;
1304 Serial.println(prefix, HEX);
1306 Serial.print(
"RX_ADDR_P2-7\t= 0x");
1307 prefix = (prefixes >> 8) & 0xFF;
1308 Serial.print(prefix, HEX);
1309 Serial.print(
" 0x");
1310 prefix = (prefixes) & 0xFF;
1311 Serial.print(prefix, HEX);
1312 Serial.print(
" 0x");
1314 prefix = (prefixes >> 24) & 0xFF;
1315 Serial.print(prefix, HEX);
1316 Serial.print(
" 0x");
1317 prefix = (prefixes >> 16) & 0xFF;
1318 Serial.print(prefix, HEX);
1319 Serial.print(
" 0x");
1320 prefix = (prefixes >> 8) & 0xFF;
1321 Serial.print(prefix, HEX);
1322 Serial.print(
" 0x");
1323 prefix = (prefixes) & 0xFF;
1324 Serial.println(prefix, HEX);
1327 for (
int i = 0; i < 6; i++) {
1328 enAA |= acksPerPipe[i] << i;
1330 Serial.print(
"EN_AA\t\t= 0x");
1331 Serial.println(enAA, HEX);
1332 Serial.print(
"EN_RXADDR\t= 0x");
1333 Serial.println(NRF_RADIO->RXADDRESSES, HEX);
1334 Serial.print(
"RF_CH\t\t= 0x");
1335 Serial.println(NRF_RADIO->FREQUENCY, HEX);
1336 Serial.println(
"DYNPD/FEATURE\t= 0x");
1337 Serial.print(
"Data Rate\t= ");
1338 Serial.println(NRF_RADIO->MODE ?
"2 MBPS" :
"1MBPS");
1339 Serial.println(
"Model\t\t= NRF52");
1340 Serial.print(
"CRC Length\t= ");
1343 Serial.println(
"16 bits");
1346 Serial.println(
"8 bits");
1349 Serial.println(
"Disabled");
1351 Serial.print(
"PA Power\t= ");
1354 Serial.println(
"PA_MAX");
1357 Serial.println(
"PA_HIGH");
1360 Serial.println(
"PA_LOW");
1363 Serial.println(
"PA_MIN");
1366 Serial.println(
"?");
1368 Serial.print(
"ARC\t\t= ");
1369 Serial.println(arcCounter);
1374#if defined CCM_ENCRYPTION_ENABLED
1378 NRF_CCM->MODE = 0 | 1 << 24 | 1 << 16;
1394 NRF_CCM->EVENTS_ENDKSGEN = 0;
1395 NRF_CCM->EVENTS_ENDCRYPT = 0;
1396 NRF_CCM->TASKS_KSGEN = 1;
1400 if (NRF_CCM->EVENTS_ERROR) {
1410 NRF_CCM->MODE = 1 | 1 << 24 | 1 << 16;
1427 NRF_CCM->EVENTS_ENDKSGEN = 0;
1428 NRF_CCM->EVENTS_ENDCRYPT = 0;
1429 NRF_CCM->TASKS_KSGEN = 1;
1434 if (NRF_CCM->EVENTS_ERROR) {
1438 if (NRF_CCM->MICSTATUS == (CCM_MICSTATUS_MICSTATUS_CheckFailed << CCM_MICSTATUS_MICSTATUS_Pos)) {
1450 NRF_CCM->MODE = 1 << 24 | 1 << 16;
1452 NRF_CCM->SHORTS = 1;
1453 NRF_CCM->ENABLE = 2;
1455 NRF_RNG->CONFIG = 1;
1456 NRF_RNG->TASKS_START = 1;
1466 ccmData.counter = counter;
1467 packetCounter = counter;
1475 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]
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)
void setChannel(uint8_t channel, bool map=0)
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)
uint16_t interframeSpacing
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)
static bool waitForEvent(volatile uint32_t &event, uint32_t timeout=DEFAULT_TIMEOUT)
#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