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;
76#if defined CCM_ENCRYPTION_ENABLED
77 NRF_CCM->INPTR = (uint32_t)inBuffer;
79 NRF_CCM->CNFPTR = (uint32_t)&ccmData;
80 NRF_CCM->SCRATCHPTR = (uint32_t)scratchPTR;
81 ccmData.counter = 12345;
91 NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
92 NRF_CLOCK->TASKS_HFCLKSTART = 1;
95 while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) {
99 NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
100 NRF_CLOCK->TASKS_LFCLKSTART = 1;
103 while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0) {
107 NRF_RADIO->POWER = 1;
109 NRF_RADIO->PCNF0 = (1 << RADIO_PCNF0_S0LEN_Pos) | (0 << RADIO_PCNF0_LFLEN_Pos) | (1 << RADIO_PCNF0_S1LEN_Pos);
111 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);
113 NRF_RADIO->BASE0 = 0xE7E7E7E7;
114 NRF_RADIO->BASE1 = 0x43434343;
115 NRF_RADIO->PREFIX0 = 0x23C343E7;
116 NRF_RADIO->PREFIX1 = 0x13E363A3;
117 NRF_RADIO->RXADDRESSES = 0x01;
118 NRF_RADIO->TXADDRESS = 0x00;
120 txBase = NRF_RADIO->BASE0;
121 txPrefix = NRF_RADIO->PREFIX0;
122 rxBase = NRF_RADIO->BASE0;
123 rxPrefix = NRF_RADIO->PREFIX0;
125 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_Two;
126 NRF_RADIO->CRCINIT = 0xFFFFUL;
127 NRF_RADIO->CRCPOLY = 0x11021UL;
129 NRF_RADIO->PACKETPTR = (uint32_t)
radioData;
130 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos);
131 NRF_RADIO->MODECNF0 = 0x200;
132 NRF_RADIO->MODECNF0 |= 1;
133 NRF_RADIO->TXPOWER = (
TXPOWER_PA_MAX << RADIO_TXPOWER_TXPOWER_Pos);
134 NRF_RADIO->SHORTS = 1 << 19;
135 NRF_RADIO->FREQUENCY = 0x4C;
146#ifdef NRF_HAS_ENERGY_DETECT
147 #define ED_RSSISCALE 4
148uint8_t nrf_to_nrf::sample_ed(
void)
151 NRF_RADIO->TASKS_EDSTART = 1;
152 while (NRF_RADIO->EVENTS_EDEND != 1) {
156 val = NRF_RADIO->EDSAMPLE;
157 return (uint8_t)(val > 63
159 : val * ED_RSSISCALE);
167 uint8_t pipe_num = 0;
176 if (payloadAvailable) {
177 *pipe_num = (uint8_t)NRF_RADIO->RXMATCH;
182 if (ackPayloadAvailable) {
183 *pipe_num = ackAvailablePipeNo;
187 if (NRF_RADIO->EVENTS_CRCOK) {
188 uint32_t counter = 0;
189#if defined CCM_ENCRYPTION_ENABLED
192 NRF_RADIO->EVENTS_CRCOK = 0;
195 return restartReturnRx();
198 return restartReturnRx();
201 return restartReturnRx();
205 *pipe_num = (uint8_t)NRF_RADIO->RXMATCH;
206 if (!DPL && acksEnabled(*pipe_num) ==
false) {
207#if defined CCM_ENCRYPTION_ENABLED
215 memcpy(&rxBuffer[1], &
radioData[0], staticPayloadSize);
216#if defined CCM_ENCRYPTION_ENABLED
221#if defined CCM_ENCRYPTION_ENABLED
238 memcpy(&rxBuffer[1], &
radioData[2], staticPayloadSize);
240#if defined CCM_ENCRYPTION_ENABLED
245 rxFifoAvailable =
true;
246 uint8_t packetCtr = 0;
253 rxBuffer[0] = staticPayloadSize;
257 uint16_t packetData = NRF_RADIO->RXCRC;
259 if (acksEnabled(NRF_RADIO->RXMATCH)) {
261 uint32_t txAddress = NRF_RADIO->TXADDRESS;
262 NRF_RADIO->TXADDRESS = NRF_RADIO->RXMATCH;
263 delayMicroseconds(75);
264 if (ackPayloadsEnabled) {
265 if (*pipe_num == ackPipe) {
266 write(&ackBuffer[1], ackBuffer[0], 1, 0);
273 uint8_t payloadSize = 0;
283 NRF_RADIO->TXADDRESS = txAddress;
288 if (NRF_RADIO->CRCCNF != 0) {
289 if (packetCtr == lastPacketCounter && packetData == lastData) {
290 return restartReturnRx();
295#if defined CCM_ENCRYPTION_ENABLED
297 ccmData.counter = counter;
299 uint8_t bufferLength = 0;
306 if (!
decrypt(&rxBuffer[1], bufferLength)) {
307 Serial.println(
"DECRYPT FAIL");
308 return restartReturnRx();
311 memset(&rxBuffer[1], 0,
sizeof(rxBuffer) - 1);
322 lastPacketCounter = packetCtr;
323 lastData = packetData;
324 payloadAvailable =
true;
326 NRF_RADIO->TASKS_START = 1;
330 if (NRF_RADIO->EVENTS_CRCERROR) {
331 NRF_RADIO->EVENTS_CRCERROR = 0;
332 NRF_RADIO->TASKS_START = 1;
339bool nrf_to_nrf::restartReturnRx()
342 NRF_RADIO->TASKS_START = 1;
351 memcpy(buf, &rxBuffer[1], len);
352 ackPayloadAvailable =
false;
353 payloadAvailable =
false;
361 uint8_t PID = ackPID;
363 PID = ((ackPID += 1) % 7) << 1;
368 uint8_t payloadSize = 0;
370#if defined CCM_ENCRYPTION_ENABLED
372 uint32_t tmpCounter = 0;
379 while (!NRF_RNG->EVENTS_VALRDY) {
381 NRF_RNG->EVENTS_VALRDY = 0;
382 tmpIV[i] = NRF_RNG->VALUE;
383 ccmData.iv[i] = tmpIV[i];
385 tmpCounter = packetCounter;
386 ccmData.counter = tmpCounter;
395 if (packetCounter > 200000) {
402 for (
int i = 0; i < (retries + 1); i++) {
413 uint8_t dataStart = 0;
415#if defined CCM_ENCRYPTION_ENABLED
422 dataStart = (!DPL && acksEnabled(0) ==
false) ? 0 : 2;
423#if defined CCM_ENCRYPTION_ENABLED
427#if defined CCM_ENCRYPTION_ENABLED
436#if defined CCM_ENCRYPTION_ENABLED
440 NRF_RADIO->EVENTS_END = 0;
441 NRF_RADIO->TASKS_START = 1;
442 while (NRF_RADIO->EVENTS_END == 0) {
444 NRF_RADIO->EVENTS_END = 0;
445 if (!multicast && acksPerPipe[NRF_RADIO->TXADDRESS] ==
true) {
446 uint32_t rxAddress = NRF_RADIO->RXADDRESSES;
447 NRF_RADIO->RXADDRESSES = 1 << NRF_RADIO->TXADDRESS;
454 uint32_t realAckTimeout = ackTimeout;
456 if (NRF_RADIO->MODE == (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos)) {
468 realAckTimeout += 200;
474 uint32_t ack_timeout = micros();
475 while (!NRF_RADIO->EVENTS_CRCOK && !NRF_RADIO->EVENTS_CRCERROR) {
476 if (micros() - ack_timeout > realAckTimeout) {
480 if (NRF_RADIO->EVENTS_CRCOK) {
481 if (ackPayloadsEnabled &&
radioData[0] > 0) {
482#if defined CCM_ENCRYPTION_ENABLED
493#if defined CCM_ENCRYPTION_ENABLED
499 Serial.println(
"DECRYPT FAIL");
509 ackPayloadAvailable =
true;
510 ackAvailablePipeNo = NRF_RADIO->RXMATCH;
512 NRF_RADIO->EVENTS_CRCOK = 0;
517 NRF_RADIO->RXADDRESSES = rxAddress;
521 else if (NRF_RADIO->EVENTS_CRCERROR) {
522 NRF_RADIO->EVENTS_CRCERROR = 0;
524 uint32_t duration = 258 * retryDuration;
525 delayMicroseconds(duration);
530 NRF_RADIO->RXADDRESSES = rxAddress;
537 lastTxResult =
false;
546 uint8_t PID = ackPID;
548 PID = ((ackPID += 1) % 7) << 1;
554#if defined CCM_ENCRYPTION_ENABLED
556 uint32_t tmpCounter = 0;
563 while (!NRF_RNG->EVENTS_VALRDY) {
565 NRF_RNG->EVENTS_VALRDY = 0;
566 tmpIV[i] = NRF_RNG->VALUE;
567 ccmData.iv[i] = tmpIV[i];
569 tmpCounter = packetCounter;
570 ccmData.counter = tmpCounter;
579 if (packetCounter > 200000) {
597 uint8_t dataStart = 0;
599#if defined CCM_ENCRYPTION_ENABLED
606 dataStart = (!DPL && acksEnabled(0) ==
false) ? 0 : 2;
607#if defined CCM_ENCRYPTION_ENABLED
611#if defined CCM_ENCRYPTION_ENABLED
620#if defined CCM_ENCRYPTION_ENABLED
624 NRF_RADIO->EVENTS_END = 0;
625 NRF_RADIO->TASKS_START = 1;
636#if defined CCM_ENCRYPTION_ENABLED
641 while (!NRF_RNG->EVENTS_VALRDY) {
643 NRF_RNG->EVENTS_VALRDY = 0;
644 ccmData.iv[i] = NRF_RNG->VALUE;
645 ackBuffer[i + 1] = ccmData.iv[i];
648 ccmData.counter = packetCounter;
658 if (packetCounter > 200000) {
665 memcpy(&ackBuffer[1], buf, len);
666#if defined CCM_ENCRYPTION_ENABLED
687 NRF_RADIO->EVENTS_DISABLED = 0;
688 NRF_RADIO->TASKS_DISABLE = 1;
689 while (NRF_RADIO->EVENTS_DISABLED == 0) {
691 NRF_RADIO->EVENTS_DISABLED = 0;
693 if (resetAddresses ==
true) {
694 NRF_RADIO->BASE0 = rxBase;
695 NRF_RADIO->PREFIX0 = rxPrefix;
698 NRF_RADIO->EVENTS_RXREADY = 0;
699 NRF_RADIO->EVENTS_CRCOK = 0;
700 NRF_RADIO->TASKS_RXEN = 1;
709 NRF_RADIO->EVENTS_DISABLED = 0;
710 NRF_RADIO->TASKS_DISABLE = 1;
711 while (NRF_RADIO->EVENTS_DISABLED == 0) {
713 NRF_RADIO->EVENTS_DISABLED = 0;
715 if (resetAddresses) {
716 NRF_RADIO->BASE0 = txBase;
717 NRF_RADIO->PREFIX0 = txPrefix;
719 if (setWritingPipe) {
720 NRF_RADIO->TXADDRESS = 0x00;
723 if (NRF_RADIO->STATE < 9) {
724 NRF_RADIO->EVENTS_TXREADY = 0;
725 NRF_RADIO->TASKS_TXEN = 1;
726 while (NRF_RADIO->EVENTS_TXREADY == 0) {
728 NRF_RADIO->EVENTS_TXREADY = 0;
747 uint8_t size = min(staticPayloadSize, rxBuffer[0]);
756 uint32_t freq = NRF_RADIO->FREQUENCY;
757 NRF_RADIO->FREQUENCY = 0x4C;
758 if (NRF_RADIO->FREQUENCY == 0x4C) {
759 NRF_RADIO->FREQUENCY = freq;
778 for (
int i = 0; i < 8; i++) {
779 acksPerPipe[i] = enable;
791 acksPerPipe[pipe] = enable;
804 staticPayloadSize = payloadSize;
806 if (payloadSize <= 32) {
807 NRF_RADIO->PCNF0 = (0 << RADIO_PCNF0_S0LEN_Pos) | (6 << RADIO_PCNF0_LFLEN_Pos) | (3 << RADIO_PCNF0_S1LEN_Pos);
811 NRF_RADIO->PCNF0 = (0 << RADIO_PCNF0_S0LEN_Pos) | (8 << RADIO_PCNF0_LFLEN_Pos) | (3 << RADIO_PCNF0_S1LEN_Pos);
814 NRF_RADIO->PCNF1 &= ~(0xFF << RADIO_PCNF1_MAXLEN_Pos | 0xFF << RADIO_PCNF1_STATLEN_Pos);
815 NRF_RADIO->PCNF1 |= payloadSize << RADIO_PCNF1_MAXLEN_Pos;
825 uint8_t lenConfig = 0;
826 if (acksEnabled(0)) {
829 NRF_RADIO->PCNF0 = (lenConfig << RADIO_PCNF0_S0LEN_Pos) | (0 << RADIO_PCNF0_LFLEN_Pos) | (lenConfig << RADIO_PCNF0_S1LEN_Pos);
831 NRF_RADIO->PCNF1 &= ~(0xFF << RADIO_PCNF1_MAXLEN_Pos | 0xFF << RADIO_PCNF1_STATLEN_Pos);
832 NRF_RADIO->PCNF1 |= staticPayloadSize << RADIO_PCNF1_STATLEN_Pos | staticPayloadSize << RADIO_PCNF1_MAXLEN_Pos;
839 staticPayloadSize = size;
842 uint8_t lenConfig = 0;
843 if (acksEnabled(0)) {
846 NRF_RADIO->PCNF0 = (lenConfig << RADIO_PCNF0_S0LEN_Pos) | (0 << RADIO_PCNF0_LFLEN_Pos) | (lenConfig << RADIO_PCNF0_S1LEN_Pos);
848 NRF_RADIO->PCNF1 &= ~(0xFF << RADIO_PCNF1_MAXLEN_Pos | 0xFF << RADIO_PCNF1_STATLEN_Pos);
849 NRF_RADIO->PCNF1 |= staticPayloadSize << RADIO_PCNF1_STATLEN_Pos | staticPayloadSize << RADIO_PCNF1_MAXLEN_Pos;
856 return staticPayloadSize;
865 retryDuration = retryVar;
873 uint32_t prefix =
addrConv32(address & 0xFF) >> 24;
883 uint32_t prefix =
addrConv32(address & 0xFF) >> 24;
893 uint32_t prefix =
addr_conv(&address[0]) >> 24;
905 NRF_RADIO->PREFIX0 = rxPrefix;
906 NRF_RADIO->BASE0 = base;
907 NRF_RADIO->PREFIX0 &= ~(0xFF);
908 NRF_RADIO->PREFIX0 |= prefix;
909 rxBase = NRF_RADIO->BASE0;
910 rxPrefix = NRF_RADIO->PREFIX0;
912 else if (child < 4) {
913 NRF_RADIO->PREFIX0 = rxPrefix;
914 NRF_RADIO->BASE1 = base;
915 NRF_RADIO->PREFIX0 &= ~(0xFF << (8 * child));
916 NRF_RADIO->PREFIX0 |= prefix << (8 * child);
917 rxPrefix = NRF_RADIO->PREFIX0;
920 NRF_RADIO->BASE1 = base;
921 NRF_RADIO->PREFIX1 &= ~(0xFF << (8 * (child - 4)));
922 NRF_RADIO->PREFIX1 |= prefix << (8 * (child - 4));
924 NRF_RADIO->RXADDRESSES |= 1 << child;
933 uint32_t prefix =
addr_conv(&address[0]) >> 24;
943 NRF_RADIO->BASE0 = base;
944 NRF_RADIO->PREFIX0 &= ~(0xFF);
945 NRF_RADIO->PREFIX0 |= prefix;
946 NRF_RADIO->TXADDRESS = 0x00;
947 txBase = NRF_RADIO->BASE0;
948 txPrefix = NRF_RADIO->PREFIX0;
955 if (NRF_RADIO->STATE == 11) {
956 while (NRF_RADIO->EVENTS_END == 0) {
958 NRF_RADIO->EVENTS_END = 0;
961 NRF_RADIO->TASKS_STOP = 1;
971 if (NRF_RADIO->STATE == 11) {
972 while (NRF_RADIO->EVENTS_END == 0) {
974 NRF_RADIO->EVENTS_END = 0;
977 NRF_RADIO->TASKS_STOP = 1;
986 lastTxResult =
write((
void*)buf, len, multicast);
992bool nrf_to_nrf::acksEnabled(uint8_t pipe)
995 if (acksPerPipe[pipe]) {
1011 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos);
1019 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_2Mbit << RADIO_MODE_MODE_Pos);
1031 uint8_t paLevel = 0x00;
1045 NRF_RADIO->TXPOWER = paLevel;
1053 uint8_t paLevel = NRF_RADIO->TXPOWER;
1085 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_Two;
1086 NRF_RADIO->CRCINIT = 0xFFFFUL;
1087 NRF_RADIO->CRCPOLY = 0x11021UL;
1090 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_One;
1091 NRF_RADIO->CRCINIT = 0xFFUL;
1092 NRF_RADIO->CRCPOLY = 0x107UL;
1095 NRF_RADIO->CRCCNF = 0;
1096 NRF_RADIO->CRCINIT = 0x00L;
1097 NRF_RADIO->CRCPOLY = 0x00UL;
1105 if (NRF_RADIO->CRCCNF == 0) {
1108 else if (NRF_RADIO->CRCCNF == RADIO_CRCCNF_LEN_One) {
1121 NRF_RADIO->EVENTS_RSSIEND = 0;
1122 NRF_RADIO->TASKS_RSSISTART = 1;
1123 while (!NRF_RADIO->EVENTS_RSSIEND) {
1125 if (NRF_RADIO->RSSISAMPLE < RSSI) {
1142 NRF_RADIO->EVENTS_RSSIEND = 0;
1143 NRF_RADIO->TASKS_RSSISTART = 1;
1144 while (!NRF_RADIO->EVENTS_RSSIEND) {
1146 return (uint8_t)NRF_RADIO->RSSISAMPLE;
1160 NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
1161 NRF_CLOCK->TASKS_HFCLKSTART = 1;
1164 while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) {
1168 NRF_RADIO->POWER = 1;
1171 NRF_RNG->CONFIG = 1;
1172 NRF_RNG->TASKS_START = 1;
1173 NRF_CCM->ENABLE = 2;
1181 NRF_RADIO->POWER = 0;
1182 NRF_CLOCK->TASKS_HFCLKSTOP = 1;
1184 NRF_RNG->TASKS_STOP = 1;
1185 NRF_RNG->CONFIG = 0;
1186 NRF_CCM->ENABLE = 0;
1193 NRF_RADIO->PCNF1 &= ~(0xFF << RADIO_PCNF1_BALEN_Pos);
1194 NRF_RADIO->PCNF1 |= (a_width - 1) << RADIO_PCNF1_BALEN_Pos;
1201 uint8_t addressWidth = ((NRF_RADIO->PCNF1 >> 16) & 0xFF) + 1;
1203 Serial.println(
"================ Radio Configuration ================");
1204 Serial.print(
"STATUS\t\t= ");
1205 Serial.println(NRF_RADIO->STATE);
1208 Serial.print(
"RX_ADDR_P0-1\t= 0x");
1209 uint32_t base =
addrConv32(NRF_RADIO->BASE0);
1210 for (
int i = addressWidth - 2; i > -1; i--) {
1211 Serial.print((base >> (i * 8)) & 0xFF, HEX);
1213 uint32_t prefixes =
addrConv32(NRF_RADIO->PREFIX0);
1214 uint8_t prefix = (prefixes >> 24) & 0xFF;
1215 Serial.print(prefix, HEX);
1216 Serial.print(
" 0x");
1218 for (
int i = addressWidth - 2; i > -1; i--) {
1219 Serial.print((base >> (i * 8)) & 0xFF, HEX);
1221 prefix = (prefixes >> 16) & 0xFF;
1222 Serial.println(prefix, HEX);
1224 Serial.print(
"RX_ADDR_P2-7\t= 0x");
1225 prefix = (prefixes >> 8) & 0xFF;
1226 Serial.print(prefix, HEX);
1227 Serial.print(
" 0x");
1228 prefix = (prefixes)&0xFF;
1229 Serial.print(prefix, HEX);
1230 Serial.print(
" 0x");
1232 prefix = (prefixes >> 24) & 0xFF;
1233 Serial.print(prefix, HEX);
1234 Serial.print(
" 0x");
1235 prefix = (prefixes >> 16) & 0xFF;
1236 Serial.print(prefix, HEX);
1237 Serial.print(
" 0x");
1238 prefix = (prefixes >> 8) & 0xFF;
1239 Serial.print(prefix, HEX);
1240 Serial.print(
" 0x");
1241 prefix = (prefixes)&0xFF;
1242 Serial.println(prefix, HEX);
1245 for (
int i = 0; i < 6; i++) {
1246 enAA |= acksPerPipe[i] << i;
1248 Serial.print(
"EN_AA\t\t= 0x");
1249 Serial.println(enAA, HEX);
1250 Serial.print(
"EN_RXADDR\t= 0x");
1251 Serial.println(NRF_RADIO->RXADDRESSES, HEX);
1252 Serial.print(
"RF_CH\t\t= 0x");
1253 Serial.println(NRF_RADIO->FREQUENCY, HEX);
1254 Serial.println(
"DYNPD/FEATURE\t= 0x");
1255 Serial.print(
"Data Rate\t= ");
1256 Serial.println(NRF_RADIO->MODE ?
"2 MBPS" :
"1MBPS");
1257 Serial.println(
"Model\t\t= NRF52");
1258 Serial.print(
"CRC Length\t= ");
1261 Serial.println(
"16 bits");
1264 Serial.println(
"8 bits");
1267 Serial.println(
"Disabled");
1269 Serial.print(
"PA Power\t= ");
1272 Serial.println(
"PA_MAX");
1275 Serial.println(
"PA_HIGH");
1278 Serial.println(
"PA_LOW");
1281 Serial.println(
"PA_MIN");
1284 Serial.println(
"?");
1286 Serial.print(
"ARC\t\t= ");
1287 Serial.println(arcCounter);
1292#if defined CCM_ENCRYPTION_ENABLED
1296 NRF_CCM->MODE = 0 | 1 << 24 | 1 << 16;
1313 NRF_CCM->EVENTS_ENDKSGEN = 0;
1314 NRF_CCM->EVENTS_ENDCRYPT = 0;
1315 NRF_CCM->TASKS_KSGEN = 1;
1316 while (!NRF_CCM->EVENTS_ENDCRYPT) {
1319 if (NRF_CCM->EVENTS_ERROR) {
1329 NRF_CCM->MODE = 1 | 1 << 24 | 1 << 16;
1338 memcpy(&inBuffer[3], bufferIn, size);
1346 NRF_CCM->EVENTS_ENDKSGEN = 0;
1347 NRF_CCM->EVENTS_ENDCRYPT = 0;
1348 NRF_CCM->TASKS_KSGEN = 1;
1350 while (!NRF_CCM->EVENTS_ENDCRYPT) {
1353 if (NRF_CCM->EVENTS_ERROR) {
1357 if (NRF_CCM->MICSTATUS == (CCM_MICSTATUS_MICSTATUS_CheckFailed << CCM_MICSTATUS_MICSTATUS_Pos)) {
1369 NRF_CCM->MODE = 1 << 24 | 1 << 16;
1371 NRF_CCM->SHORTS = 1;
1372 NRF_CCM->ENABLE = 2;
1374 NRF_RNG->CONFIG = 1;
1375 NRF_RNG->TASKS_START = 1;
1385 ccmData.counter = counter;
1386 packetCounter = counter;
1394 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