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;
747#if defined(NRF52832_XXAA)
748 NRF_RADIO->EVENTS_READY = 0;
750 NRF_RADIO->EVENTS_RXREADY = 0;
752 NRF_RADIO->EVENTS_CRCOK = 0;
753 NRF_RADIO->TASKS_RXEN = 1;
754#if defined(NRF52832_XXAA)
761 NRF_RADIO->TASKS_START = 1;
769 NRF_RADIO->EVENTS_DISABLED = 0;
770 NRF_RADIO->TASKS_DISABLE = 1;
773 NRF_RADIO->EVENTS_DISABLED = 0;
775 if (resetAddresses) {
776 NRF_RADIO->BASE0 = txBase;
777 NRF_RADIO->PREFIX0 = txPrefix;
779 if (setWritingPipe) {
780 NRF_RADIO->TXADDRESS = 0x00;
782#ifndef ARDUINO_NRF54L15
783 NRF_RADIO->MODECNF0 = 0x200;
785 NRF_RADIO->TIMING = 0x0;
788#ifndef ARDUINO_NRF54L15
789 NRF_RADIO->SHORTS = 0x6;
791 NRF_RADIO->SHORTS = 0x80004;
793 if (NRF_RADIO->STATE < 9) {
794#if defined(NRF52832_XXAA)
795 NRF_RADIO->EVENTS_READY = 0;
797 NRF_RADIO->EVENTS_TXREADY = 0;
799 NRF_RADIO->TASKS_TXEN = 1;
800#if defined(NRF52832_XXAA)
803 NRF_RADIO->EVENTS_READY = 0;
807 NRF_RADIO->EVENTS_TXREADY = 0;
826 uint8_t size = min(staticPayloadSize, rxBuffer[0]);
835 uint32_t freq = NRF_RADIO->FREQUENCY;
836 NRF_RADIO->FREQUENCY = 0x4C;
837 if (NRF_RADIO->FREQUENCY == 0x4C) {
838 NRF_RADIO->FREQUENCY = freq;
846void nrf_to_nrf::setChannel(uint8_t channel,
bool map) { NRF_RADIO->FREQUENCY = channel | map << RADIO_FREQUENCY_MAP_Pos; }
857 for (
int i = 0; i < 8; i++) {
858 acksPerPipe[i] = enable;
870 acksPerPipe[pipe] = enable;
883 staticPayloadSize = payloadSize;
885 if (payloadSize <= 63) {
886 NRF_RADIO->PCNF0 = (0 << RADIO_PCNF0_S0LEN_Pos) | (6 << RADIO_PCNF0_LFLEN_Pos) | (3 << RADIO_PCNF0_S1LEN_Pos);
890 NRF_RADIO->PCNF0 = (0 << RADIO_PCNF0_S0LEN_Pos) | (8 << RADIO_PCNF0_LFLEN_Pos) | (3 << RADIO_PCNF0_S1LEN_Pos);
893 NRF_RADIO->PCNF1 &= ~(0xFF << RADIO_PCNF1_MAXLEN_Pos | 0xFF << RADIO_PCNF1_STATLEN_Pos);
894 NRF_RADIO->PCNF1 |= payloadSize << RADIO_PCNF1_MAXLEN_Pos;
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 staticPayloadSize = size;
921 uint8_t lenConfig = 0;
922 if (acksEnabled(0)) {
925 NRF_RADIO->PCNF0 = (lenConfig << RADIO_PCNF0_S0LEN_Pos) | (0 << RADIO_PCNF0_LFLEN_Pos) | (lenConfig << RADIO_PCNF0_S1LEN_Pos);
927 NRF_RADIO->PCNF1 &= ~(0xFF << RADIO_PCNF1_MAXLEN_Pos | 0xFF << RADIO_PCNF1_STATLEN_Pos);
928 NRF_RADIO->PCNF1 |= staticPayloadSize << RADIO_PCNF1_STATLEN_Pos | staticPayloadSize << RADIO_PCNF1_MAXLEN_Pos;
935 return staticPayloadSize;
944 retryDuration = retryVar;
952 uint32_t prefix =
addrConv32(address & 0xFF) >> 24;
962 uint32_t prefix =
addrConv32(address & 0xFF) >> 24;
972 uint32_t prefix =
addr_conv(&address[0]) >> 24;
984 NRF_RADIO->PREFIX0 = rxPrefix;
985 NRF_RADIO->BASE0 = base;
986 NRF_RADIO->PREFIX0 &= ~(0xFF);
987 NRF_RADIO->PREFIX0 |= prefix;
988 rxBase = NRF_RADIO->BASE0;
989 rxPrefix = NRF_RADIO->PREFIX0;
991 else if (child < 4) {
992 NRF_RADIO->PREFIX0 = rxPrefix;
993 NRF_RADIO->BASE1 = base;
994 NRF_RADIO->PREFIX0 &= ~(0xFF << (8 * child));
995 NRF_RADIO->PREFIX0 |= prefix << (8 * child);
996 rxPrefix = NRF_RADIO->PREFIX0;
999 NRF_RADIO->BASE1 = base;
1000 NRF_RADIO->PREFIX1 &= ~(0xFF << (8 * (child - 4)));
1001 NRF_RADIO->PREFIX1 |= prefix << (8 * (child - 4));
1003 NRF_RADIO->RXADDRESSES |= 1 << child;
1012 uint32_t prefix =
addr_conv(&address[0]) >> 24;
1022 NRF_RADIO->BASE0 = base;
1023 NRF_RADIO->PREFIX0 &= ~(0xFF);
1024 NRF_RADIO->PREFIX0 |= prefix;
1025 NRF_RADIO->TXADDRESS = 0x00;
1026 txBase = NRF_RADIO->BASE0;
1027 txPrefix = NRF_RADIO->PREFIX0;
1033 return lastTxResult;
1040 return lastTxResult;
1047 lastTxResult =
write(buf, len, multicast);
1048 return lastTxResult;
1053bool nrf_to_nrf::acksEnabled(uint8_t pipe)
1056 if (acksPerPipe[pipe]) {
1072 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos);
1080 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_2Mbit << RADIO_MODE_MODE_Pos);
1083#ifdef ARDUINO_NRF54L15
1084 else if (speed == NRF_4MBPS_OBT4) {
1085 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_4Mbit_OBT4 << RADIO_MODE_MODE_Pos);
1089 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_4Mbit_OBT6 << RADIO_MODE_MODE_Pos);
1102 uint8_t paLevel = 0x00;
1116 NRF_RADIO->TXPOWER = paLevel;
1124 uint8_t paLevel = NRF_RADIO->TXPOWER;
1155 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_Three;
1156 NRF_RADIO->CRCINIT = 0x555555UL;
1157 NRF_RADIO->CRCPOLY = 0x65BUL;
1160 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_Two;
1161 NRF_RADIO->CRCINIT = 0xFFFFUL;
1162 NRF_RADIO->CRCPOLY = 0x11021UL;
1165 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_One;
1166 NRF_RADIO->CRCINIT = 0xFFUL;
1167 NRF_RADIO->CRCPOLY = 0x107UL;
1170 NRF_RADIO->CRCCNF = 0;
1171 NRF_RADIO->CRCINIT = 0x00L;
1172 NRF_RADIO->CRCPOLY = 0x00UL;
1180 if (NRF_RADIO->CRCCNF == 0) {
1183 else if (NRF_RADIO->CRCCNF == RADIO_CRCCNF_LEN_One) {
1186 if (NRF_RADIO->CRCCNF == RADIO_CRCCNF_LEN_Two) {
1198#ifndef ARDUINO_NRF54L15
1199 NRF_RADIO->EVENTS_RSSIEND = 0;
1200 NRF_RADIO->TASKS_RSSISTART = 1;
1204 if (NRF_RADIO->RSSISAMPLE < RSSI) {
1222#ifndef ARDUINO_NRF54L15
1223 NRF_RADIO->EVENTS_RSSIEND = 0;
1224 NRF_RADIO->TASKS_RSSISTART = 1;
1228 return (uint8_t)NRF_RADIO->RSSISAMPLE;
1244#ifndef ARDUINO_NRF54L15
1245 NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
1246 NRF_CLOCK->TASKS_HFCLKSTART = 1;
1251 NRF_RADIO->POWER = 1;
1253 NRF_POWER->TASKS_CONSTLAT = 1;
1254 NRF_CLOCK->EVENTS_XOSTARTED = 0;
1255 NRF_CLOCK->TASKS_XOSTART = 1;
1260#ifdef CCM_ENCRYPTION_ENABLED
1262 NRF_RNG->CONFIG = 1;
1263 NRF_RNG->TASKS_START = 1;
1264 NRF_CCM->ENABLE = 2;
1273#ifndef ARDUINO_NRF54L15
1274 NRF_RADIO->POWER = 0;
1275 NRF_CLOCK->TASKS_HFCLKSTOP = 1;
1277 NRF_CLOCK->TASKS_XOSTOP = 1;
1280#ifdef CCM_ENCRYPTION_ENABLED
1282 NRF_RNG->TASKS_STOP = 1;
1283 NRF_RNG->CONFIG = 0;
1284 NRF_CCM->ENABLE = 0;
1292 NRF_RADIO->PCNF1 &= ~(0xFF << RADIO_PCNF1_BALEN_Pos);
1293 NRF_RADIO->PCNF1 |= (a_width - 1) << RADIO_PCNF1_BALEN_Pos;
1300 uint8_t addressWidth = ((NRF_RADIO->PCNF1 >> 16) & 0xFF) + 1;
1302 Serial.println(
"================ Radio Configuration ================");
1303 Serial.print(
"STATUS\t\t= ");
1304 Serial.println(NRF_RADIO->STATE);
1307 Serial.print(
"RX_ADDR_P0-1\t= 0x");
1308 uint32_t base =
addrConv32(NRF_RADIO->BASE0);
1309 for (
int i = addressWidth - 2; i > -1; i--) {
1310 Serial.print((base >> (i * 8)) & 0xFF, HEX);
1312 uint32_t prefixes =
addrConv32(NRF_RADIO->PREFIX0);
1313 uint8_t prefix = (prefixes >> 24) & 0xFF;
1314 Serial.print(prefix, HEX);
1315 Serial.print(
" 0x");
1317 for (
int i = addressWidth - 2; i > -1; i--) {
1318 Serial.print((base >> (i * 8)) & 0xFF, HEX);
1320 prefix = (prefixes >> 16) & 0xFF;
1321 Serial.println(prefix, HEX);
1323 Serial.print(
"RX_ADDR_P2-7\t= 0x");
1324 prefix = (prefixes >> 8) & 0xFF;
1325 Serial.print(prefix, HEX);
1326 Serial.print(
" 0x");
1327 prefix = (prefixes) & 0xFF;
1328 Serial.print(prefix, HEX);
1329 Serial.print(
" 0x");
1331 prefix = (prefixes >> 24) & 0xFF;
1332 Serial.print(prefix, HEX);
1333 Serial.print(
" 0x");
1334 prefix = (prefixes >> 16) & 0xFF;
1335 Serial.print(prefix, HEX);
1336 Serial.print(
" 0x");
1337 prefix = (prefixes >> 8) & 0xFF;
1338 Serial.print(prefix, HEX);
1339 Serial.print(
" 0x");
1340 prefix = (prefixes) & 0xFF;
1341 Serial.println(prefix, HEX);
1344 for (
int i = 0; i < 6; i++) {
1345 enAA |= acksPerPipe[i] << i;
1347 Serial.print(
"EN_AA\t\t= 0x");
1348 Serial.println(enAA, HEX);
1349 Serial.print(
"EN_RXADDR\t= 0x");
1350 Serial.println(NRF_RADIO->RXADDRESSES, HEX);
1351 Serial.print(
"RF_CH\t\t= 0x");
1352 Serial.println(NRF_RADIO->FREQUENCY, HEX);
1353 Serial.println(
"DYNPD/FEATURE\t= 0x");
1354 Serial.print(
"Data Rate\t= ");
1355 Serial.println(NRF_RADIO->MODE ?
"2 MBPS" :
"1MBPS");
1356 Serial.println(
"Model\t\t= NRF52");
1357 Serial.print(
"CRC Length\t= ");
1360 Serial.println(
"16 bits");
1363 Serial.println(
"8 bits");
1366 Serial.println(
"Disabled");
1368 Serial.print(
"PA Power\t= ");
1371 Serial.println(
"PA_MAX");
1374 Serial.println(
"PA_HIGH");
1377 Serial.println(
"PA_LOW");
1380 Serial.println(
"PA_MIN");
1383 Serial.println(
"?");
1385 Serial.print(
"ARC\t\t= ");
1386 Serial.println(arcCounter);
1391#if defined CCM_ENCRYPTION_ENABLED
1395 NRF_CCM->MODE = 0 | 1 << 24 | 1 << 16;
1411 NRF_CCM->EVENTS_ENDKSGEN = 0;
1412 NRF_CCM->EVENTS_ENDCRYPT = 0;
1413 NRF_CCM->TASKS_KSGEN = 1;
1417 if (NRF_CCM->EVENTS_ERROR) {
1427 NRF_CCM->MODE = 1 | 1 << 24 | 1 << 16;
1444 NRF_CCM->EVENTS_ENDKSGEN = 0;
1445 NRF_CCM->EVENTS_ENDCRYPT = 0;
1446 NRF_CCM->TASKS_KSGEN = 1;
1451 if (NRF_CCM->EVENTS_ERROR) {
1455 if (NRF_CCM->MICSTATUS == (CCM_MICSTATUS_MICSTATUS_CheckFailed << CCM_MICSTATUS_MICSTATUS_Pos)) {
1467 NRF_CCM->MODE = 1 << 24 | 1 << 16;
1468#ifndef NRF52832_XXAA
1471 NRF_CCM->SHORTS = 1;
1472 NRF_CCM->ENABLE = 2;
1474 NRF_RNG->CONFIG = 1;
1475 NRF_RNG->TASKS_START = 1;
1485 ccmData.counter = counter;
1486 packetCounter = counter;
1494 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 bool waitForEvent(volatile uint32_t *event, uint32_t timeout=DEFAULT_TIMEOUT)
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