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;
68 ackPayloadsEnabled =
false;
73 payloadAvailable =
false;
77#if defined CCM_ENCRYPTION_ENABLED
78 NRF_CCM->INPTR = (uint32_t)inBuffer;
80 NRF_CCM->CNFPTR = (uint32_t)&ccmData;
81 NRF_CCM->SCRATCHPTR = (uint32_t)scratchPTR;
82 ccmData.counter = 12345;
92 NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
93 NRF_CLOCK->TASKS_HFCLKSTART = 1;
96 while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) {
100 NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
101 NRF_CLOCK->TASKS_LFCLKSTART = 1;
104 while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0) {
108 NRF_RADIO->POWER = 1;
110 NRF_RADIO->PCNF0 = (1 << RADIO_PCNF0_S0LEN_Pos) | (0 << RADIO_PCNF0_LFLEN_Pos) | (1 << RADIO_PCNF0_S1LEN_Pos);
112 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);
114 NRF_RADIO->BASE0 = 0xE7E7E7E7;
115 NRF_RADIO->BASE1 = 0x43434343;
116 NRF_RADIO->PREFIX0 = 0x23C343E7;
117 NRF_RADIO->PREFIX1 = 0x13E363A3;
118 NRF_RADIO->RXADDRESSES = 0x01;
119 NRF_RADIO->TXADDRESS = 0x00;
121 txBase = NRF_RADIO->BASE0;
122 txPrefix = NRF_RADIO->PREFIX0;
123 rxBase = NRF_RADIO->BASE0;
124 rxPrefix = NRF_RADIO->PREFIX0;
126 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_Two;
127 NRF_RADIO->CRCINIT = 0xFFFFUL;
128 NRF_RADIO->CRCPOLY = 0x11021UL;
130 NRF_RADIO->PACKETPTR = (uint32_t)
radioData;
131 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos);
132 NRF_RADIO->MODECNF0 = 0x201;
133 NRF_RADIO->TXPOWER = (
TXPOWER_PA_MAX << RADIO_TXPOWER_TXPOWER_Pos);
134 NRF_RADIO->FREQUENCY = 0x4C;
145#ifdef NRF_HAS_ENERGY_DETECT
146 #define ED_RSSISCALE 4
147uint8_t nrf_to_nrf::sample_ed(
void)
150 NRF_RADIO->TASKS_EDSTART = 1;
151 while (NRF_RADIO->EVENTS_EDEND != 1) {
155 val = NRF_RADIO->EDSAMPLE;
156 return (uint8_t)(val > 63
158 : val * ED_RSSISCALE);
166 uint8_t pipe_num = 0;
175 if (payloadAvailable) {
176 *pipe_num = (uint8_t)NRF_RADIO->RXMATCH;
181 if (ackPayloadAvailable) {
182 *pipe_num = ackAvailablePipeNo;
186 if (NRF_RADIO->EVENTS_CRCOK) {
187 NRF_RADIO->EVENTS_CRCOK = 0;
190 return restartReturnRx();
194 *pipe_num = (uint8_t)NRF_RADIO->RXMATCH;
195 if (!DPL && acksEnabled(*pipe_num) ==
false) {
196#if defined CCM_ENCRYPTION_ENABLED
204 memcpy(&rxBuffer[1], &
radioData[0], staticPayloadSize);
205#if defined CCM_ENCRYPTION_ENABLED
210#if defined CCM_ENCRYPTION_ENABLED
227 memcpy(&rxBuffer[1], &
radioData[2], staticPayloadSize);
229#if defined CCM_ENCRYPTION_ENABLED
234 rxFifoAvailable =
true;
235 uint8_t packetCtr = 0;
242 rxBuffer[0] = staticPayloadSize;
246 uint16_t packetData = NRF_RADIO->RXCRC;
248 if (acksEnabled(NRF_RADIO->RXMATCH)) {
250 uint32_t txAddress = NRF_RADIO->TXADDRESS;
251 NRF_RADIO->TXADDRESS = NRF_RADIO->RXMATCH;
252 delayMicroseconds(75);
253 if (ackPayloadsEnabled) {
254 if (*pipe_num == ackPipe) {
255 write(&ackBuffer[1], ackBuffer[0], 1, 0);
262 uint8_t payloadSize = 0;
272 NRF_RADIO->TXADDRESS = txAddress;
277 if (NRF_RADIO->CRCCNF != 0) {
278 if (packetCtr == lastPacketCounter && packetData == lastData) {
279 return restartReturnRx();
284#if defined CCM_ENCRYPTION_ENABLED
286 uint8_t bufferLength = 0;
293 if (!
decrypt(&rxBuffer[1], bufferLength)) {
294 Serial.println(
"DECRYPT FAIL");
295 return restartReturnRx();
298 memset(&rxBuffer[1], 0,
sizeof(rxBuffer) - 1);
309 lastPacketCounter = packetCtr;
310 lastData = packetData;
312 if (inRxMode && !acksEnabled(NRF_RADIO->RXMATCH)) {
313 NRF_RADIO->TASKS_START = 1;
315 if ((DPL && rxBuffer[0]) || !DPL) {
316 payloadAvailable =
true;
320 if (NRF_RADIO->EVENTS_CRCERROR) {
321 NRF_RADIO->EVENTS_CRCERROR = 0;
322 NRF_RADIO->TASKS_START = 1;
329bool nrf_to_nrf::restartReturnRx()
332 NRF_RADIO->TASKS_START = 1;
341 memcpy(buf, &rxBuffer[1], len);
342 ackPayloadAvailable =
false;
343 payloadAvailable =
false;
351 uint8_t PID = ackPID;
353 PID = ((ackPID += 1) % 7) << 1;
358 uint8_t payloadSize = 0;
360#if defined CCM_ENCRYPTION_ENABLED
366 while (!NRF_RNG->EVENTS_VALRDY) {
368 NRF_RNG->EVENTS_VALRDY = 0;
369 ccmData.iv[i] = NRF_RNG->VALUE;
371 ccmData.counter = packetCounter;
379 if (packetCounter > 200000) {
386 for (
int i = 0; i < (retries + 1); i++) {
397 uint8_t dataStart = 0;
399#if defined CCM_ENCRYPTION_ENABLED
406 dataStart = (!DPL && acksEnabled(0) ==
false) ? 0 : 2;
407#if defined CCM_ENCRYPTION_ENABLED
411#if defined CCM_ENCRYPTION_ENABLED
420#if defined CCM_ENCRYPTION_ENABLED
424 NRF_RADIO->EVENTS_END = 0;
425 NRF_RADIO->TASKS_START = 1;
426 while (NRF_RADIO->EVENTS_END == 0) {
428 NRF_RADIO->EVENTS_END = 0;
429 if (!multicast && acksPerPipe[NRF_RADIO->TXADDRESS] ==
true) {
430 uint32_t rxAddress = NRF_RADIO->RXADDRESSES;
431 NRF_RADIO->RXADDRESSES = 1 << NRF_RADIO->TXADDRESS;
438 uint32_t realAckTimeout = ackTimeout;
440 if (NRF_RADIO->MODE == (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos)) {
452 realAckTimeout += 200;
458 uint32_t ack_timeout = micros();
459 while (!NRF_RADIO->EVENTS_CRCOK && !NRF_RADIO->EVENTS_CRCERROR) {
460 if (micros() - ack_timeout > realAckTimeout) {
464 if (NRF_RADIO->EVENTS_CRCOK) {
465 if (ackPayloadsEnabled &&
radioData[0] > 0) {
466#if defined CCM_ENCRYPTION_ENABLED
477#if defined CCM_ENCRYPTION_ENABLED
483 Serial.println(
"DECRYPT FAIL");
493 ackPayloadAvailable =
true;
494 ackAvailablePipeNo = NRF_RADIO->RXMATCH;
496 NRF_RADIO->EVENTS_CRCOK = 0;
501 NRF_RADIO->RXADDRESSES = rxAddress;
505 else if (NRF_RADIO->EVENTS_CRCERROR) {
506 NRF_RADIO->EVENTS_CRCERROR = 0;
508 uint32_t duration = 258 * retryDuration;
509 delayMicroseconds(duration);
514 NRF_RADIO->RXADDRESSES = rxAddress;
521 lastTxResult =
false;
530 uint8_t PID = ackPID;
532 PID = ((ackPID += 1) % 7) << 1;
538#if defined CCM_ENCRYPTION_ENABLED
540 uint32_t tmpCounter = 0;
546 while (!NRF_RNG->EVENTS_VALRDY) {
548 NRF_RNG->EVENTS_VALRDY = 0;
549 tmpIV[i] = NRF_RNG->VALUE;
550 ccmData.iv[i] = tmpIV[i];
552 tmpCounter = packetCounter;
553 ccmData.counter = tmpCounter;
561 if (packetCounter > 200000) {
579 uint8_t dataStart = 0;
581#if defined CCM_ENCRYPTION_ENABLED
588 dataStart = (!DPL && acksEnabled(0) ==
false) ? 0 : 2;
589#if defined CCM_ENCRYPTION_ENABLED
593#if defined CCM_ENCRYPTION_ENABLED
602#if defined CCM_ENCRYPTION_ENABLED
606 NRF_RADIO->EVENTS_END = 0;
607 NRF_RADIO->TASKS_START = 1;
618#if defined CCM_ENCRYPTION_ENABLED
623 while (!NRF_RNG->EVENTS_VALRDY) {
625 NRF_RNG->EVENTS_VALRDY = 0;
626 ccmData.iv[i] = NRF_RNG->VALUE;
627 ackBuffer[i + 1] = ccmData.iv[i];
630 ccmData.counter = packetCounter;
640 if (packetCounter > 200000) {
647 memcpy(&ackBuffer[1], buf, len);
648#if defined CCM_ENCRYPTION_ENABLED
669 NRF_RADIO->EVENTS_DISABLED = 0;
670 NRF_RADIO->TASKS_DISABLE = 1;
671 while (NRF_RADIO->EVENTS_DISABLED == 0) {
673 NRF_RADIO->EVENTS_DISABLED = 0;
675 if (resetAddresses ==
true) {
676 NRF_RADIO->BASE0 = rxBase;
677 NRF_RADIO->PREFIX0 = rxPrefix;
678 NRF_RADIO->MODECNF0 = 0x201;
681 NRF_RADIO->SHORTS = 0x0;
683 NRF_RADIO->EVENTS_RXREADY = 0;
684 NRF_RADIO->EVENTS_CRCOK = 0;
685 NRF_RADIO->TASKS_RXEN = 1;
686 while (NRF_RADIO->EVENTS_RXREADY == 0) {
689 NRF_RADIO->TASKS_START = 1;
697 NRF_RADIO->EVENTS_DISABLED = 0;
698 NRF_RADIO->TASKS_DISABLE = 1;
699 while (NRF_RADIO->EVENTS_DISABLED == 0) {
701 NRF_RADIO->EVENTS_DISABLED = 0;
703 if (resetAddresses) {
704 NRF_RADIO->BASE0 = txBase;
705 NRF_RADIO->PREFIX0 = txPrefix;
707 if (setWritingPipe) {
708 NRF_RADIO->TXADDRESS = 0x00;
710 NRF_RADIO->MODECNF0 = 0x200;
713 NRF_RADIO->SHORTS = 0x6;
714 if (NRF_RADIO->STATE < 9) {
715 NRF_RADIO->EVENTS_TXREADY = 0;
716 NRF_RADIO->TASKS_TXEN = 1;
717 while (NRF_RADIO->EVENTS_TXREADY == 0) {
719 NRF_RADIO->EVENTS_TXREADY = 0;
737 uint8_t size = min(staticPayloadSize, rxBuffer[0]);
746 uint32_t freq = NRF_RADIO->FREQUENCY;
747 NRF_RADIO->FREQUENCY = 0x4C;
748 if (NRF_RADIO->FREQUENCY == 0x4C) {
749 NRF_RADIO->FREQUENCY = freq;
757void nrf_to_nrf::setChannel(uint8_t channel,
bool map) { NRF_RADIO->FREQUENCY = channel | map << RADIO_FREQUENCY_MAP_Pos; }
768 for (
int i = 0; i < 8; i++) {
769 acksPerPipe[i] = enable;
781 acksPerPipe[pipe] = enable;
794 staticPayloadSize = payloadSize;
796 if (payloadSize <= 63) {
797 NRF_RADIO->PCNF0 = (0 << RADIO_PCNF0_S0LEN_Pos) | (6 << RADIO_PCNF0_LFLEN_Pos) | (3 << RADIO_PCNF0_S1LEN_Pos);
801 NRF_RADIO->PCNF0 = (0 << RADIO_PCNF0_S0LEN_Pos) | (8 << RADIO_PCNF0_LFLEN_Pos) | (3 << RADIO_PCNF0_S1LEN_Pos);
804 NRF_RADIO->PCNF1 &= ~(0xFF << RADIO_PCNF1_MAXLEN_Pos | 0xFF << RADIO_PCNF1_STATLEN_Pos);
805 NRF_RADIO->PCNF1 |= payloadSize << RADIO_PCNF1_MAXLEN_Pos;
815 uint8_t lenConfig = 0;
816 if (acksEnabled(0)) {
819 NRF_RADIO->PCNF0 = (lenConfig << RADIO_PCNF0_S0LEN_Pos) | (0 << RADIO_PCNF0_LFLEN_Pos) | (lenConfig << RADIO_PCNF0_S1LEN_Pos);
821 NRF_RADIO->PCNF1 &= ~(0xFF << RADIO_PCNF1_MAXLEN_Pos | 0xFF << RADIO_PCNF1_STATLEN_Pos);
822 NRF_RADIO->PCNF1 |= staticPayloadSize << RADIO_PCNF1_STATLEN_Pos | staticPayloadSize << RADIO_PCNF1_MAXLEN_Pos;
829 staticPayloadSize = size;
832 uint8_t lenConfig = 0;
833 if (acksEnabled(0)) {
836 NRF_RADIO->PCNF0 = (lenConfig << RADIO_PCNF0_S0LEN_Pos) | (0 << RADIO_PCNF0_LFLEN_Pos) | (lenConfig << RADIO_PCNF0_S1LEN_Pos);
838 NRF_RADIO->PCNF1 &= ~(0xFF << RADIO_PCNF1_MAXLEN_Pos | 0xFF << RADIO_PCNF1_STATLEN_Pos);
839 NRF_RADIO->PCNF1 |= staticPayloadSize << RADIO_PCNF1_STATLEN_Pos | staticPayloadSize << RADIO_PCNF1_MAXLEN_Pos;
846 return staticPayloadSize;
855 retryDuration = retryVar;
863 uint32_t prefix =
addrConv32(address & 0xFF) >> 24;
873 uint32_t prefix =
addrConv32(address & 0xFF) >> 24;
883 uint32_t prefix =
addr_conv(&address[0]) >> 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;
923 uint32_t prefix =
addr_conv(&address[0]) >> 24;
933 NRF_RADIO->BASE0 = base;
934 NRF_RADIO->PREFIX0 &= ~(0xFF);
935 NRF_RADIO->PREFIX0 |= prefix;
936 NRF_RADIO->TXADDRESS = 0x00;
937 txBase = NRF_RADIO->BASE0;
938 txPrefix = NRF_RADIO->PREFIX0;
958 lastTxResult =
write(buf, len, multicast);
964bool nrf_to_nrf::acksEnabled(uint8_t pipe)
967 if (acksPerPipe[pipe]) {
983 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos);
991 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_2Mbit << RADIO_MODE_MODE_Pos);
1003 uint8_t paLevel = 0x00;
1017 NRF_RADIO->TXPOWER = paLevel;
1025 uint8_t paLevel = NRF_RADIO->TXPOWER;
1056 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_Three;
1057 NRF_RADIO->CRCINIT = 0x555555UL;
1058 NRF_RADIO->CRCPOLY = 0x65BUL;
1061 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_Two;
1062 NRF_RADIO->CRCINIT = 0xFFFFUL;
1063 NRF_RADIO->CRCPOLY = 0x11021UL;
1066 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_One;
1067 NRF_RADIO->CRCINIT = 0xFFUL;
1068 NRF_RADIO->CRCPOLY = 0x107UL;
1071 NRF_RADIO->CRCCNF = 0;
1072 NRF_RADIO->CRCINIT = 0x00L;
1073 NRF_RADIO->CRCPOLY = 0x00UL;
1081 if (NRF_RADIO->CRCCNF == 0) {
1084 else if (NRF_RADIO->CRCCNF == RADIO_CRCCNF_LEN_One) {
1087 if (NRF_RADIO->CRCCNF == RADIO_CRCCNF_LEN_Two) {
1100 NRF_RADIO->EVENTS_RSSIEND = 0;
1101 NRF_RADIO->TASKS_RSSISTART = 1;
1102 while (!NRF_RADIO->EVENTS_RSSIEND) {
1104 if (NRF_RADIO->RSSISAMPLE < RSSI) {
1121 NRF_RADIO->EVENTS_RSSIEND = 0;
1122 NRF_RADIO->TASKS_RSSISTART = 1;
1123 while (!NRF_RADIO->EVENTS_RSSIEND) {
1125 return (uint8_t)NRF_RADIO->RSSISAMPLE;
1139 NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
1140 NRF_CLOCK->TASKS_HFCLKSTART = 1;
1143 while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) {
1147 NRF_RADIO->POWER = 1;
1150 NRF_RNG->CONFIG = 1;
1151 NRF_RNG->TASKS_START = 1;
1152 NRF_CCM->ENABLE = 2;
1160 NRF_RADIO->POWER = 0;
1161 NRF_CLOCK->TASKS_HFCLKSTOP = 1;
1163 NRF_RNG->TASKS_STOP = 1;
1164 NRF_RNG->CONFIG = 0;
1165 NRF_CCM->ENABLE = 0;
1172 NRF_RADIO->PCNF1 &= ~(0xFF << RADIO_PCNF1_BALEN_Pos);
1173 NRF_RADIO->PCNF1 |= (a_width - 1) << RADIO_PCNF1_BALEN_Pos;
1180 uint8_t addressWidth = ((NRF_RADIO->PCNF1 >> 16) & 0xFF) + 1;
1182 Serial.println(
"================ Radio Configuration ================");
1183 Serial.print(
"STATUS\t\t= ");
1184 Serial.println(NRF_RADIO->STATE);
1187 Serial.print(
"RX_ADDR_P0-1\t= 0x");
1188 uint32_t base =
addrConv32(NRF_RADIO->BASE0);
1189 for (
int i = addressWidth - 2; i > -1; i--) {
1190 Serial.print((base >> (i * 8)) & 0xFF, HEX);
1192 uint32_t prefixes =
addrConv32(NRF_RADIO->PREFIX0);
1193 uint8_t prefix = (prefixes >> 24) & 0xFF;
1194 Serial.print(prefix, HEX);
1195 Serial.print(
" 0x");
1197 for (
int i = addressWidth - 2; i > -1; i--) {
1198 Serial.print((base >> (i * 8)) & 0xFF, HEX);
1200 prefix = (prefixes >> 16) & 0xFF;
1201 Serial.println(prefix, HEX);
1203 Serial.print(
"RX_ADDR_P2-7\t= 0x");
1204 prefix = (prefixes >> 8) & 0xFF;
1205 Serial.print(prefix, HEX);
1206 Serial.print(
" 0x");
1207 prefix = (prefixes)&0xFF;
1208 Serial.print(prefix, HEX);
1209 Serial.print(
" 0x");
1211 prefix = (prefixes >> 24) & 0xFF;
1212 Serial.print(prefix, HEX);
1213 Serial.print(
" 0x");
1214 prefix = (prefixes >> 16) & 0xFF;
1215 Serial.print(prefix, HEX);
1216 Serial.print(
" 0x");
1217 prefix = (prefixes >> 8) & 0xFF;
1218 Serial.print(prefix, HEX);
1219 Serial.print(
" 0x");
1220 prefix = (prefixes)&0xFF;
1221 Serial.println(prefix, HEX);
1224 for (
int i = 0; i < 6; i++) {
1225 enAA |= acksPerPipe[i] << i;
1227 Serial.print(
"EN_AA\t\t= 0x");
1228 Serial.println(enAA, HEX);
1229 Serial.print(
"EN_RXADDR\t= 0x");
1230 Serial.println(NRF_RADIO->RXADDRESSES, HEX);
1231 Serial.print(
"RF_CH\t\t= 0x");
1232 Serial.println(NRF_RADIO->FREQUENCY, HEX);
1233 Serial.println(
"DYNPD/FEATURE\t= 0x");
1234 Serial.print(
"Data Rate\t= ");
1235 Serial.println(NRF_RADIO->MODE ?
"2 MBPS" :
"1MBPS");
1236 Serial.println(
"Model\t\t= NRF52");
1237 Serial.print(
"CRC Length\t= ");
1240 Serial.println(
"16 bits");
1243 Serial.println(
"8 bits");
1246 Serial.println(
"Disabled");
1248 Serial.print(
"PA Power\t= ");
1251 Serial.println(
"PA_MAX");
1254 Serial.println(
"PA_HIGH");
1257 Serial.println(
"PA_LOW");
1260 Serial.println(
"PA_MIN");
1263 Serial.println(
"?");
1265 Serial.print(
"ARC\t\t= ");
1266 Serial.println(arcCounter);
1271#if defined CCM_ENCRYPTION_ENABLED
1275 NRF_CCM->MODE = 0 | 1 << 24 | 1 << 16;
1291 NRF_CCM->EVENTS_ENDKSGEN = 0;
1292 NRF_CCM->EVENTS_ENDCRYPT = 0;
1293 NRF_CCM->TASKS_KSGEN = 1;
1294 while (!NRF_CCM->EVENTS_ENDCRYPT) {
1297 if (NRF_CCM->EVENTS_ERROR) {
1307 NRF_CCM->MODE = 1 | 1 << 24 | 1 << 16;
1324 NRF_CCM->EVENTS_ENDKSGEN = 0;
1325 NRF_CCM->EVENTS_ENDCRYPT = 0;
1326 NRF_CCM->TASKS_KSGEN = 1;
1328 while (!NRF_CCM->EVENTS_ENDCRYPT) {
1331 if (NRF_CCM->EVENTS_ERROR) {
1335 if (NRF_CCM->MICSTATUS == (CCM_MICSTATUS_MICSTATUS_CheckFailed << CCM_MICSTATUS_MICSTATUS_Pos)) {
1347 NRF_CCM->MODE = 1 << 24 | 1 << 16;
1349 NRF_CCM->SHORTS = 1;
1350 NRF_CCM->ENABLE = 2;
1352 NRF_RNG->CONFIG = 1;
1353 NRF_RNG->TASKS_START = 1;
1363 ccmData.counter = counter;
1364 packetCounter = counter;
1372 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)
#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