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;
103#if defined CCM_ENCRYPTION_ENABLED
104 NRF_CCM->INPTR = (uint32_t)inBuffer;
106 NRF_CCM->CNFPTR = (uint32_t)&ccmData;
107 NRF_CCM->SCRATCHPTR = (uint32_t)scratchPTR;
108 ccmData.counter = 12345;
118#ifndef ARDUINO_NRF54L15
119 NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
120 NRF_CLOCK->TASKS_HFCLKSTART = 1;
126 NRF_POWER->TASKS_CONSTLAT = 1;
127 NRF_CLOCK->EVENTS_XOSTARTED = 0;
128 NRF_CLOCK->TASKS_XOSTART = 1;
134 NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
135 NRF_CLOCK->TASKS_LFCLKSTART = 1;
141#ifndef ARDUINO_NRF54L15
142 NRF_RADIO->POWER = 1;
145 NRF_RADIO->PCNF0 = (1 << RADIO_PCNF0_S0LEN_Pos) | (0 << RADIO_PCNF0_LFLEN_Pos) | (1 << RADIO_PCNF0_S1LEN_Pos);
147 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);
149 NRF_RADIO->BASE0 = 0xE7E7E7E7;
150 NRF_RADIO->BASE1 = 0x43434343;
151 NRF_RADIO->PREFIX0 = 0x23C343E7;
152 NRF_RADIO->PREFIX1 = 0x13E363A3;
153 NRF_RADIO->RXADDRESSES = 0x01;
154 NRF_RADIO->TXADDRESS = 0x00;
156 txBase = NRF_RADIO->BASE0;
157 txPrefix = NRF_RADIO->PREFIX0;
158 rxBase = NRF_RADIO->BASE0;
159 rxPrefix = NRF_RADIO->PREFIX0;
161 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_Two;
162 NRF_RADIO->CRCINIT = 0xFFFFUL;
163 NRF_RADIO->CRCPOLY = 0x11021UL;
165 NRF_RADIO->PACKETPTR = (uint32_t)
radioData;
166 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos);
168#ifndef ARDUINO_NRF54L15
169 NRF_RADIO->MODECNF0 = 0x201;
171 NRF_RADIO->TIMING = 0x1;
173 NRF_RADIO->TXPOWER = (
TXPOWER_PA_MAX << RADIO_TXPOWER_TXPOWER_Pos);
174 NRF_RADIO->FREQUENCY = 0x4C;
180#ifdef ARDUINO_NRF54L15
181 NRF_RADIO->TASKS_START = 1;
189#ifdef NRF_HAS_ENERGY_DETECT
190 #define ED_RSSISCALE 4
191uint8_t nrf_to_nrf::sample_ed(
void)
194 NRF_RADIO->TASKS_EDSTART = 1;
198 val = NRF_RADIO->EDSAMPLE;
199 return (uint8_t)(val > 63
201 : val * ED_RSSISCALE);
209 uint8_t pipe_num = 0;
218 if (payloadAvailable) {
219 *pipe_num = (uint8_t)NRF_RADIO->RXMATCH;
224 if (ackPayloadAvailable) {
225 *pipe_num = ackAvailablePipeNo;
229 if (NRF_RADIO->EVENTS_CRCOK) {
230 NRF_RADIO->EVENTS_CRCOK = 0;
233 return restartReturnRx();
237 *pipe_num = (uint8_t)NRF_RADIO->RXMATCH;
238 if (!DPL && acksEnabled(*pipe_num) ==
false) {
239#if defined CCM_ENCRYPTION_ENABLED
247 memcpy(&rxBuffer[1], &
radioData[0], staticPayloadSize);
248#if defined CCM_ENCRYPTION_ENABLED
253#if defined CCM_ENCRYPTION_ENABLED
270 memcpy(&rxBuffer[1], &
radioData[2], staticPayloadSize);
272#if defined CCM_ENCRYPTION_ENABLED
277 rxFifoAvailable =
true;
278 uint8_t packetCtr = 0;
285 rxBuffer[0] = staticPayloadSize;
289 uint16_t packetData = NRF_RADIO->RXCRC;
291 if (acksEnabled(NRF_RADIO->RXMATCH)) {
293 uint32_t txAddress = NRF_RADIO->TXADDRESS;
294 NRF_RADIO->TXADDRESS = NRF_RADIO->RXMATCH;
295 delayMicroseconds(75);
296 if (ackPayloadsEnabled) {
297 if (*pipe_num == ackPipe) {
298 write(&ackBuffer[1], ackBuffer[0], 1, 0);
305 uint8_t payloadSize = 0;
315 NRF_RADIO->TXADDRESS = txAddress;
320 if (NRF_RADIO->CRCCNF != 0) {
321 if (packetCtr == lastPacketCounter && packetData == lastData) {
322 return restartReturnRx();
327#if defined CCM_ENCRYPTION_ENABLED
329 uint8_t bufferLength = 0;
336 if (!
decrypt(&rxBuffer[1], bufferLength)) {
337 Serial.println(
"DECRYPT FAIL");
338 return restartReturnRx();
341 memset(&rxBuffer[1], 0,
sizeof(rxBuffer) - 1);
352 lastPacketCounter = packetCtr;
353 lastData = packetData;
355 if (inRxMode && !acksEnabled(NRF_RADIO->RXMATCH)) {
356 NRF_RADIO->TASKS_START = 1;
358 if ((DPL && rxBuffer[0]) || !DPL) {
359 payloadAvailable =
true;
363 if (NRF_RADIO->EVENTS_CRCERROR) {
364 NRF_RADIO->EVENTS_CRCERROR = 0;
365 NRF_RADIO->TASKS_START = 1;
372bool nrf_to_nrf::restartReturnRx()
375 NRF_RADIO->TASKS_START = 1;
384 memcpy(buf, &rxBuffer[1], len);
385 ackPayloadAvailable =
false;
386 payloadAvailable =
false;
393#ifdef ARDUINO_NRF54L15
394 uint32_t timeout = millis();
395 while (NRF_RADIO->STATE != 10) {
397 if (millis() - timeout > 250) {
403 uint8_t PID = ackPID;
405 PID = ((ackPID += 1) % 7) << 1;
410 uint8_t payloadSize = 0;
412#if defined CCM_ENCRYPTION_ENABLED
420 NRF_RNG->EVENTS_VALRDY = 0;
421 ccmData.iv[i] = NRF_RNG->VALUE;
423 ccmData.counter = packetCounter;
431 if (packetCounter > 200000) {
438 for (
int i = 0; i < (retries + 1); i++) {
449 uint8_t dataStart = 0;
451#if defined CCM_ENCRYPTION_ENABLED
458 dataStart = (!DPL && acksEnabled(0) ==
false) ? 0 : 2;
459#if defined CCM_ENCRYPTION_ENABLED
463#if defined CCM_ENCRYPTION_ENABLED
472#if defined CCM_ENCRYPTION_ENABLED
476 NRF_RADIO->EVENTS_END = 0;
477 NRF_RADIO->TASKS_START = 1;
481 NRF_RADIO->EVENTS_END = 0;
482 if (!multicast && acksPerPipe[NRF_RADIO->TXADDRESS] ==
true) {
483 uint32_t rxAddress = NRF_RADIO->RXADDRESSES;
484 NRF_RADIO->RXADDRESSES = 1 << NRF_RADIO->TXADDRESS;
491 int32_t realAckTimeout = (int32_t)ackTimeout;
493 if (NRF_RADIO->MODE == (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos)) {
505 realAckTimeout += 200;
511 if (realAckTimeout < 0) {
515 uint32_t ack_timeout = micros();
516 while (!NRF_RADIO->EVENTS_CRCOK && !NRF_RADIO->EVENTS_CRCERROR) {
517 if (micros() - ack_timeout > realAckTimeout) {
521 if (NRF_RADIO->EVENTS_CRCOK) {
522 if (ackPayloadsEnabled &&
radioData[0] > 0) {
523#if defined CCM_ENCRYPTION_ENABLED
534#if defined CCM_ENCRYPTION_ENABLED
540 Serial.println(
"DECRYPT FAIL");
550 ackPayloadAvailable =
true;
551 ackAvailablePipeNo = NRF_RADIO->RXMATCH;
553 NRF_RADIO->EVENTS_CRCOK = 0;
558 NRF_RADIO->RXADDRESSES = rxAddress;
562 else if (NRF_RADIO->EVENTS_CRCERROR) {
563 NRF_RADIO->EVENTS_CRCERROR = 0;
565 uint32_t duration = 258 * retryDuration;
566 delayMicroseconds(duration);
571 NRF_RADIO->RXADDRESSES = rxAddress;
578 lastTxResult =
false;
587 uint8_t PID = ackPID;
589 PID = ((ackPID += 1) % 7) << 1;
595#if defined CCM_ENCRYPTION_ENABLED
597 uint32_t tmpCounter = 0;
605 NRF_RNG->EVENTS_VALRDY = 0;
606 tmpIV[i] = NRF_RNG->VALUE;
607 ccmData.iv[i] = tmpIV[i];
609 tmpCounter = packetCounter;
610 ccmData.counter = tmpCounter;
618 if (packetCounter > 200000) {
636 uint8_t dataStart = 0;
638#if defined CCM_ENCRYPTION_ENABLED
645 dataStart = (!DPL && acksEnabled(0) ==
false) ? 0 : 2;
646#if defined CCM_ENCRYPTION_ENABLED
650#if defined CCM_ENCRYPTION_ENABLED
659#if defined CCM_ENCRYPTION_ENABLED
663 NRF_RADIO->EVENTS_END = 0;
664 NRF_RADIO->TASKS_START = 1;
675#if defined CCM_ENCRYPTION_ENABLED
682 NRF_RNG->EVENTS_VALRDY = 0;
683 ccmData.iv[i] = NRF_RNG->VALUE;
684 ackBuffer[i + 1] = ccmData.iv[i];
687 ccmData.counter = packetCounter;
697 if (packetCounter > 200000) {
704 memcpy(&ackBuffer[1], buf, len);
705#if defined CCM_ENCRYPTION_ENABLED
726 NRF_RADIO->EVENTS_DISABLED = 0;
727 NRF_RADIO->TASKS_DISABLE = 1;
730 NRF_RADIO->EVENTS_DISABLED = 0;
732 if (resetAddresses ==
true) {
733 NRF_RADIO->BASE0 = rxBase;
734 NRF_RADIO->PREFIX0 = rxPrefix;
735#ifndef ARDUINO_NRF54L15
736 NRF_RADIO->MODECNF0 = 0x201;
738 NRF_RADIO->TIMING = 0x1;
743 NRF_RADIO->SHORTS = 0x0;
745 NRF_RADIO->EVENTS_RXREADY = 0;
746 NRF_RADIO->EVENTS_CRCOK = 0;
747 NRF_RADIO->TASKS_RXEN = 1;
751 NRF_RADIO->TASKS_START = 1;
759 NRF_RADIO->EVENTS_DISABLED = 0;
760 NRF_RADIO->TASKS_DISABLE = 1;
763 NRF_RADIO->EVENTS_DISABLED = 0;
765 if (resetAddresses) {
766 NRF_RADIO->BASE0 = txBase;
767 NRF_RADIO->PREFIX0 = txPrefix;
769 if (setWritingPipe) {
770 NRF_RADIO->TXADDRESS = 0x00;
772#ifndef ARDUINO_NRF54L15
773 NRF_RADIO->MODECNF0 = 0x200;
775 NRF_RADIO->TIMING = 0x0;
778#ifndef ARDUINO_NRF54L15
779 NRF_RADIO->SHORTS = 0x6;
781 NRF_RADIO->SHORTS = 0x100008;
783 if (NRF_RADIO->STATE < 9) {
784 NRF_RADIO->EVENTS_TXREADY = 0;
785 NRF_RADIO->TASKS_TXEN = 1;
788 NRF_RADIO->EVENTS_TXREADY = 0;
806 uint8_t size = min(staticPayloadSize, rxBuffer[0]);
815 uint32_t freq = NRF_RADIO->FREQUENCY;
816 NRF_RADIO->FREQUENCY = 0x4C;
817 if (NRF_RADIO->FREQUENCY == 0x4C) {
818 NRF_RADIO->FREQUENCY = freq;
826void nrf_to_nrf::setChannel(uint8_t channel,
bool map) { NRF_RADIO->FREQUENCY = channel | map << RADIO_FREQUENCY_MAP_Pos; }
837 for (
int i = 0; i < 8; i++) {
838 acksPerPipe[i] = enable;
850 acksPerPipe[pipe] = enable;
863 staticPayloadSize = payloadSize;
865 if (payloadSize <= 63) {
866 NRF_RADIO->PCNF0 = (0 << RADIO_PCNF0_S0LEN_Pos) | (6 << RADIO_PCNF0_LFLEN_Pos) | (3 << RADIO_PCNF0_S1LEN_Pos);
870 NRF_RADIO->PCNF0 = (0 << RADIO_PCNF0_S0LEN_Pos) | (8 << RADIO_PCNF0_LFLEN_Pos) | (3 << RADIO_PCNF0_S1LEN_Pos);
873 NRF_RADIO->PCNF1 &= ~(0xFF << RADIO_PCNF1_MAXLEN_Pos | 0xFF << RADIO_PCNF1_STATLEN_Pos);
874 NRF_RADIO->PCNF1 |= payloadSize << RADIO_PCNF1_MAXLEN_Pos;
884 uint8_t lenConfig = 0;
885 if (acksEnabled(0)) {
888 NRF_RADIO->PCNF0 = (lenConfig << RADIO_PCNF0_S0LEN_Pos) | (0 << RADIO_PCNF0_LFLEN_Pos) | (lenConfig << RADIO_PCNF0_S1LEN_Pos);
890 NRF_RADIO->PCNF1 &= ~(0xFF << RADIO_PCNF1_MAXLEN_Pos | 0xFF << RADIO_PCNF1_STATLEN_Pos);
891 NRF_RADIO->PCNF1 |= staticPayloadSize << RADIO_PCNF1_STATLEN_Pos | staticPayloadSize << RADIO_PCNF1_MAXLEN_Pos;
898 staticPayloadSize = size;
901 uint8_t lenConfig = 0;
902 if (acksEnabled(0)) {
905 NRF_RADIO->PCNF0 = (lenConfig << RADIO_PCNF0_S0LEN_Pos) | (0 << RADIO_PCNF0_LFLEN_Pos) | (lenConfig << RADIO_PCNF0_S1LEN_Pos);
907 NRF_RADIO->PCNF1 &= ~(0xFF << RADIO_PCNF1_MAXLEN_Pos | 0xFF << RADIO_PCNF1_STATLEN_Pos);
908 NRF_RADIO->PCNF1 |= staticPayloadSize << RADIO_PCNF1_STATLEN_Pos | staticPayloadSize << RADIO_PCNF1_MAXLEN_Pos;
915 return staticPayloadSize;
924 retryDuration = retryVar;
932 uint32_t prefix =
addrConv32(address & 0xFF) >> 24;
942 uint32_t prefix =
addrConv32(address & 0xFF) >> 24;
952 uint32_t prefix =
addr_conv(&address[0]) >> 24;
964 NRF_RADIO->PREFIX0 = rxPrefix;
965 NRF_RADIO->BASE0 = base;
966 NRF_RADIO->PREFIX0 &= ~(0xFF);
967 NRF_RADIO->PREFIX0 |= prefix;
968 rxBase = NRF_RADIO->BASE0;
969 rxPrefix = NRF_RADIO->PREFIX0;
971 else if (child < 4) {
972 NRF_RADIO->PREFIX0 = rxPrefix;
973 NRF_RADIO->BASE1 = base;
974 NRF_RADIO->PREFIX0 &= ~(0xFF << (8 * child));
975 NRF_RADIO->PREFIX0 |= prefix << (8 * child);
976 rxPrefix = NRF_RADIO->PREFIX0;
979 NRF_RADIO->BASE1 = base;
980 NRF_RADIO->PREFIX1 &= ~(0xFF << (8 * (child - 4)));
981 NRF_RADIO->PREFIX1 |= prefix << (8 * (child - 4));
983 NRF_RADIO->RXADDRESSES |= 1 << child;
992 uint32_t prefix =
addr_conv(&address[0]) >> 24;
1002 NRF_RADIO->BASE0 = base;
1003 NRF_RADIO->PREFIX0 &= ~(0xFF);
1004 NRF_RADIO->PREFIX0 |= prefix;
1005 NRF_RADIO->TXADDRESS = 0x00;
1006 txBase = NRF_RADIO->BASE0;
1007 txPrefix = NRF_RADIO->PREFIX0;
1013 return lastTxResult;
1020 return lastTxResult;
1027 lastTxResult =
write(buf, len, multicast);
1028 return lastTxResult;
1033bool nrf_to_nrf::acksEnabled(uint8_t pipe)
1036 if (acksPerPipe[pipe]) {
1052 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos);
1060 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_2Mbit << RADIO_MODE_MODE_Pos);
1063#ifdef ARDUINO_NRF54L15
1064 else if (speed == NRF_4MBPS_OBT4) {
1065 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_4Mbit_OBT4 << RADIO_MODE_MODE_Pos);
1069 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_4Mbit_OBT6 << RADIO_MODE_MODE_Pos);
1082 uint8_t paLevel = 0x00;
1096 NRF_RADIO->TXPOWER = paLevel;
1104 uint8_t paLevel = NRF_RADIO->TXPOWER;
1135 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_Three;
1136 NRF_RADIO->CRCINIT = 0x555555UL;
1137 NRF_RADIO->CRCPOLY = 0x65BUL;
1140 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_Two;
1141 NRF_RADIO->CRCINIT = 0xFFFFUL;
1142 NRF_RADIO->CRCPOLY = 0x11021UL;
1145 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_One;
1146 NRF_RADIO->CRCINIT = 0xFFUL;
1147 NRF_RADIO->CRCPOLY = 0x107UL;
1150 NRF_RADIO->CRCCNF = 0;
1151 NRF_RADIO->CRCINIT = 0x00L;
1152 NRF_RADIO->CRCPOLY = 0x00UL;
1160 if (NRF_RADIO->CRCCNF == 0) {
1163 else if (NRF_RADIO->CRCCNF == RADIO_CRCCNF_LEN_One) {
1166 if (NRF_RADIO->CRCCNF == RADIO_CRCCNF_LEN_Two) {
1178#ifndef ARDUINO_NRF54L15
1179 NRF_RADIO->EVENTS_RSSIEND = 0;
1180 NRF_RADIO->TASKS_RSSISTART = 1;
1184 if (NRF_RADIO->RSSISAMPLE < RSSI) {
1202#ifndef ARDUINO_NRF54L15
1203 NRF_RADIO->EVENTS_RSSIEND = 0;
1204 NRF_RADIO->TASKS_RSSISTART = 1;
1208 return (uint8_t)NRF_RADIO->RSSISAMPLE;
1224#ifndef ARDUINO_NRF54L15
1225 NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
1226 NRF_CLOCK->TASKS_HFCLKSTART = 1;
1231 NRF_RADIO->POWER = 1;
1233 NRF_POWER->TASKS_CONSTLAT = 1;
1234 NRF_CLOCK->EVENTS_XOSTARTED = 0;
1235 NRF_CLOCK->TASKS_XOSTART = 1;
1240#ifdef CCM_ENCRYPTION_ENABLED
1242 NRF_RNG->CONFIG = 1;
1243 NRF_RNG->TASKS_START = 1;
1244 NRF_CCM->ENABLE = 2;
1253#ifndef ARDUINO_NRF54L15
1254 NRF_RADIO->POWER = 0;
1255 NRF_CLOCK->TASKS_HFCLKSTOP = 1;
1257 NRF_CLOCK->TASKS_XOSTOP = 1;
1260#ifdef CCM_ENCRYPTION_ENABLED
1262 NRF_RNG->TASKS_STOP = 1;
1263 NRF_RNG->CONFIG = 0;
1264 NRF_CCM->ENABLE = 0;
1272 NRF_RADIO->PCNF1 &= ~(0xFF << RADIO_PCNF1_BALEN_Pos);
1273 NRF_RADIO->PCNF1 |= (a_width - 1) << RADIO_PCNF1_BALEN_Pos;
1280 uint8_t addressWidth = ((NRF_RADIO->PCNF1 >> 16) & 0xFF) + 1;
1282 Serial.println(
"================ Radio Configuration ================");
1283 Serial.print(
"STATUS\t\t= ");
1284 Serial.println(NRF_RADIO->STATE);
1287 Serial.print(
"RX_ADDR_P0-1\t= 0x");
1288 uint32_t base =
addrConv32(NRF_RADIO->BASE0);
1289 for (
int i = addressWidth - 2; i > -1; i--) {
1290 Serial.print((base >> (i * 8)) & 0xFF, HEX);
1292 uint32_t prefixes =
addrConv32(NRF_RADIO->PREFIX0);
1293 uint8_t prefix = (prefixes >> 24) & 0xFF;
1294 Serial.print(prefix, HEX);
1295 Serial.print(
" 0x");
1297 for (
int i = addressWidth - 2; i > -1; i--) {
1298 Serial.print((base >> (i * 8)) & 0xFF, HEX);
1300 prefix = (prefixes >> 16) & 0xFF;
1301 Serial.println(prefix, HEX);
1303 Serial.print(
"RX_ADDR_P2-7\t= 0x");
1304 prefix = (prefixes >> 8) & 0xFF;
1305 Serial.print(prefix, HEX);
1306 Serial.print(
" 0x");
1307 prefix = (prefixes) & 0xFF;
1308 Serial.print(prefix, HEX);
1309 Serial.print(
" 0x");
1311 prefix = (prefixes >> 24) & 0xFF;
1312 Serial.print(prefix, HEX);
1313 Serial.print(
" 0x");
1314 prefix = (prefixes >> 16) & 0xFF;
1315 Serial.print(prefix, HEX);
1316 Serial.print(
" 0x");
1317 prefix = (prefixes >> 8) & 0xFF;
1318 Serial.print(prefix, HEX);
1319 Serial.print(
" 0x");
1320 prefix = (prefixes) & 0xFF;
1321 Serial.println(prefix, HEX);
1324 for (
int i = 0; i < 6; i++) {
1325 enAA |= acksPerPipe[i] << i;
1327 Serial.print(
"EN_AA\t\t= 0x");
1328 Serial.println(enAA, HEX);
1329 Serial.print(
"EN_RXADDR\t= 0x");
1330 Serial.println(NRF_RADIO->RXADDRESSES, HEX);
1331 Serial.print(
"RF_CH\t\t= 0x");
1332 Serial.println(NRF_RADIO->FREQUENCY, HEX);
1333 Serial.println(
"DYNPD/FEATURE\t= 0x");
1334 Serial.print(
"Data Rate\t= ");
1335 Serial.println(NRF_RADIO->MODE ?
"2 MBPS" :
"1MBPS");
1336 Serial.println(
"Model\t\t= NRF52");
1337 Serial.print(
"CRC Length\t= ");
1340 Serial.println(
"16 bits");
1343 Serial.println(
"8 bits");
1346 Serial.println(
"Disabled");
1348 Serial.print(
"PA Power\t= ");
1351 Serial.println(
"PA_MAX");
1354 Serial.println(
"PA_HIGH");
1357 Serial.println(
"PA_LOW");
1360 Serial.println(
"PA_MIN");
1363 Serial.println(
"?");
1365 Serial.print(
"ARC\t\t= ");
1366 Serial.println(arcCounter);
1371#if defined CCM_ENCRYPTION_ENABLED
1375 NRF_CCM->MODE = 0 | 1 << 24 | 1 << 16;
1391 NRF_CCM->EVENTS_ENDKSGEN = 0;
1392 NRF_CCM->EVENTS_ENDCRYPT = 0;
1393 NRF_CCM->TASKS_KSGEN = 1;
1397 if (NRF_CCM->EVENTS_ERROR) {
1407 NRF_CCM->MODE = 1 | 1 << 24 | 1 << 16;
1424 NRF_CCM->EVENTS_ENDKSGEN = 0;
1425 NRF_CCM->EVENTS_ENDCRYPT = 0;
1426 NRF_CCM->TASKS_KSGEN = 1;
1431 if (NRF_CCM->EVENTS_ERROR) {
1435 if (NRF_CCM->MICSTATUS == (CCM_MICSTATUS_MICSTATUS_CheckFailed << CCM_MICSTATUS_MICSTATUS_Pos)) {
1447 NRF_CCM->MODE = 1 << 24 | 1 << 16;
1449 NRF_CCM->SHORTS = 1;
1450 NRF_CCM->ENABLE = 2;
1452 NRF_RNG->CONFIG = 1;
1453 NRF_RNG->TASKS_START = 1;
1463 ccmData.counter = counter;
1464 packetCounter = counter;
1472 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