-
Notifications
You must be signed in to change notification settings - Fork 1
/
Programmer.ino
678 lines (581 loc) · 18.2 KB
/
Programmer.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
/*
Programmer.ino
Programmer for flashing Nordic nRF24LE1 SOC RF chips using SPI interface from an Arduino.
Data to write to flash is fed from standard SDCC produced Intel Hex format file using the
accompanying programmer.pl perl script. Start the Arduino script first and then run the
perl script.
When uploading, make sure serial port speed is set to 57600 baud.
Copyright (c) 2014 Dean Cording
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/*
Arduino Uno connections:
See nRF24LE1 Product Specification for corresponding pin numbers.
NOTE: nRF24LE1 is a 3.3V device. Level converters are required to connect it to a
5V Arduino.
* D00: Serial RX
* D01: Serial TX
* D02:
*~D03:
* D04:
*~D05:
*~D06:
* D07: nRF24LE1 UART/RXD
* D08: nRF24LE1 PROG
*~D09: nRF24LE1 _RESET_
*~D10: nRF24LE1 FCSN, nRF24LE1 UART/TXD
*~D11: SPI MOSI, nRF24LE1 FMOSI
* D12: SPI MISO, nRF24LE1 FMISO
* D13: SPI SCK, On board Status LED, nRF24LE1 FSCK
* A0:
* A1:
* A2:
* A3:
* A4: I2C SDA
* A5: I2C SCL
* 5V:
* 3.3V: nRF24LE1 VDD
* AREF:
* GND: nRF24LE1 VSS
(~ PWM)
Interupts:
0:
1:
Pin-Mapping:
Arduino 24Pin 32Pin 48Pin
D07 (RXD) 12 P0.6 10 P0.4 15 P1.1
D08 (PROG) 5 PROG 6 PROG 10 PROG
D09 (RESET) 13 RESET 19 RESET 30 RESET
D10 (FCSN,TXD) 11 P0.5 15 P1.1 22 P2.0
D11 (FMOSI) 9 P0.3 13 P0.7 19 P1.5
D12 (FMISO) 10 P0.4 14 P1.0 20 P1.6
D13 (FSCK) 8 P0.2 11 P0.5 16 P1.2
*/
#include <SPI.h>
#include <SoftwareSerial.h>
#define NRFTYPE 24
// Specify pins in use
#define PROG 8 // nRF24LE1 Program
#define _RESET_ 9 // nRF24LE1 Reset
#define _FCSN_ 10 // nRF24LE1 Chip select
// nRF24LE1 Serial port connections. These will differ with the different chip
// packages
#define nRF24LE1_TXD 10 // nRF24LE1 UART/TXD
#define nRF24LE1_RXD 7 // nRF24LE1 UART/RXD
SoftwareSerial nRF24LE1Serial(nRF24LE1_TXD, nRF24LE1_RXD);
#define NRF24LE1_BAUD 19200
#define FLASH_TRIGGER_WRITEMAINPAGE 0x01 // Magic character to trigger uploading of flash
#define FLASH_TRIGGER_READMAINPAGE 0x02
#define FLASH_TRIGGER_WRITEINFOPAGE 0x11
#define FLASH_TRIGGER_READINFOPAGE 0x12
#define FLASH_TRIGGER_DUMP 0x20
// SPI Flash operations commands
#define WREN 0x06 // Set flase write enable latch
#define WRDIS 0x04 // Reset flash write enable latch
#define RDSR 0x05 // Read Flash Status Register (FSR)
#define WRSR 0x01 // Write Flash Status Register (FSR)
#define READ 0x03 // Read data from flash
#define PROGRAM 0x02 // Write data to flash
#define ERASE_PAGE 0x52 // Erase addressed page
#define ERASE_ALL 0x62 // Erase all pages in flash info page^ and/or main block
#define RDFPCR 0x89 // Read Flash Protect Configuration Register (FPCR)
#define RDISMB 0x85 // Enable flash readback protection
#define ENDEBUG 0x86 // Enable HW debug features
/* NOTE: The InfoPage area DSYS are used to store nRF24LE1 system and tuning
* parameters. Erasing the content of this area WILL cause changes to device
* behavior and performance. InfoPage area DSYS should ALWAYS be read out and
* stored prior to using ERASE ALL. Upon completion of the erase, the DSYS
* information must be written back to the flash InfoPage.
*
* Use the Read_Infopage sketch to make a backup.
*/
// Flash Status Register (FSR) bits
#define FSR_STP B01000000 // Enable code execution start from protected flash area
#define FSR_WEN B00100000 // Write enable latch
#define FSR_RDYN B00010000 // Flash ready flag - active low
#define FSR_INFEN B00001000 // Flash InfoPage enable
// Hex file processing definitions
#define HEX_REC_START_CODE ':'
#define HEX_REC_TYPE_DATA 0
#define HEX_REC_TYPE_EOF 1
#define HEX_REC_TYPE_EXT_SEG_ADDR 2
#define HEX_REC_TYPE_EXT_LIN_ADDR 4
#define HEX_REC_OK 0
#define HEX_REC_ILLEGAL_CHARS -1
#define HEX_REC_BAD_CHECKSUM -2
#define HEX_REC_NULL_PTR -3
#define HEX_REC_INVALID_FORMAT -4
#define HEX_REC_EOF -5
char inputRecord[521]; // Buffer for line of encoded hex data
typedef struct hexRecordStruct {
byte rec_data[256];
byte rec_data_len;
word rec_address;
byte rec_type;
byte rec_checksum;
byte calc_checksum;
}
hexRecordStruct;
hexRecordStruct hexRecord; // Decoded hex data
size_t numChars; // Serial characters received counter
byte fsr; // Flash status register buffer
byte spi_data; // SPI data transfer buffer
byte infopage[37]; // Buffer for storing InfoPage content
byte ConvertHexASCIIDigitToByte(char c){
if((c >= 'a') && (c <= 'f'))
return (c - 'a') + 0x0A;
else if ((c >= 'A') && (c <= 'F'))
return (c - 'A') + 0x0A;
else if ((c >= '0') && (c <= '9'))
return (c - '0');
else
return -1;
}
byte ConvertHexASCIIByteToByte(char msb, char lsb){
return ((ConvertHexASCIIDigitToByte(msb) << 4) + ConvertHexASCIIDigitToByte(lsb));
}
int ParseHexRecord(struct hexRecordStruct * record, char * inputRecord, int inputRecordLen){
int index = 0;
if((record == NULL) || (inputRecord == NULL)) {
return HEX_REC_NULL_PTR;
}
if(inputRecord[0] != HEX_REC_START_CODE) {
return HEX_REC_INVALID_FORMAT;
}
record->rec_data_len = ConvertHexASCIIByteToByte(inputRecord[1], inputRecord[2]);
record->rec_address = word(ConvertHexASCIIByteToByte(inputRecord[3], inputRecord[4]), ConvertHexASCIIByteToByte(inputRecord[5], inputRecord[6]));
record->rec_type = ConvertHexASCIIByteToByte(inputRecord[7], inputRecord[8]);
record->rec_checksum = ConvertHexASCIIByteToByte(inputRecord[9 + (record->rec_data_len * 2)], inputRecord[9 + (record->rec_data_len * 2) + 1]);
record->calc_checksum = record->rec_data_len + ((record->rec_address >> 8) & 0xFF) + (record->rec_address & 0xFF) + record->rec_type;
for(index = 0; index < record->rec_data_len; index++) {
record->rec_data[index] = ConvertHexASCIIByteToByte(inputRecord[9 + (index * 2)], inputRecord[9 + (index * 2) + 1]);
record->calc_checksum += record->rec_data[index];
}
record->calc_checksum = ~record->calc_checksum + 1;
if(record->calc_checksum != record->rec_checksum) {
return HEX_REC_BAD_CHECKSUM;
}
if (record->rec_type == HEX_REC_TYPE_EOF) {
return HEX_REC_EOF;
}
return HEX_REC_OK;
}
void flash() {
int line = 0;
Serial.println("FLASH");
// Initialise SPI
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
SPI.setClockDivider(SPI_CLOCK_DIV4);
// Initialise control pins
pinMode(PROG, OUTPUT);
digitalWrite(PROG, LOW);
pinMode(_RESET_, OUTPUT);
digitalWrite(_RESET_, HIGH);
pinMode(_FCSN_, OUTPUT);
digitalWrite(_FCSN_, HIGH);
SPI.begin();
Serial.println("READY");
if (!Serial.find("GO ")) {
Serial.println("TIMEOUT");
return;
}
// Read nupp and rdismb
byte nupp = Serial.parseInt();
byte rdismb = Serial.parseInt();
Serial.read();
// Put nRF24LE1 into programming mode
digitalWrite(PROG, HIGH);
digitalWrite(_RESET_, LOW);
delay(10);
digitalWrite(_RESET_, HIGH);
delay(10);
// Set InfoPage enable bit so all flash is erased
digitalWrite(_FCSN_, LOW);
SPI.transfer(RDSR);
fsr = SPI.transfer(0x00);
digitalWrite(_FCSN_, HIGH);
digitalWrite(_FCSN_, LOW);
SPI.transfer(WRSR);
SPI.transfer(fsr | FSR_INFEN);
delay(1);
digitalWrite(_FCSN_, HIGH);
// Check InfoPage enable bit was set
digitalWrite(_FCSN_, LOW);
SPI.transfer(RDSR);
fsr = SPI.transfer(0x00);
digitalWrite(_FCSN_, HIGH);
if (!(fsr & FSR_INFEN)) {
Serial.println("INFOPAGE ENABLE FAILED");
goto done;
}
// Read InfoPage content so it can be restored after erasing flash
Serial.println("SAVING INFOPAGE...");
digitalWrite(_FCSN_, LOW);
SPI.transfer(READ);
SPI.transfer(0);
SPI.transfer(0);
for (int index = 0; index < 37; index++) {
infopage[index] = SPI.transfer(0x00);
}
digitalWrite(_FCSN_, HIGH);
// Erase flash
Serial.println("ERASING FLASH...");
// Set flash write enable latch
digitalWrite(_FCSN_, LOW);
SPI.transfer(WREN);
delay(1);
digitalWrite(_FCSN_, HIGH);
// Erase all flash pages
digitalWrite(_FCSN_, LOW);
SPI.transfer(ERASE_ALL);
delay(1);
digitalWrite(_FCSN_, HIGH);
// Check flash is ready
do {
delay(60);
digitalWrite(_FCSN_, LOW);
SPI.transfer(RDSR);
fsr = SPI.transfer(0x00);
digitalWrite(_FCSN_, HIGH);
}
while (fsr & FSR_RDYN);
// Restore InfoPage content
// Clear Flash MB readback protection (RDISMB)
infopage[35] = rdismb;
// Set all pages unprotected (NUPP)
infopage[32] = nupp;
Serial.print("RDISMB=");
Serial.println(rdismb);
Serial.print("NUPP=");
Serial.println(nupp);
Serial.println("RESTORING INFOPAGE....");
// Set flash write enable latch
digitalWrite(_FCSN_, LOW);
SPI.transfer(WREN);
delay(1);
digitalWrite(_FCSN_, HIGH);
// Write back InfoPage content
digitalWrite(_FCSN_, LOW);
SPI.transfer(PROGRAM);
SPI.transfer(0);
SPI.transfer(0);
for (int index = 0; index < 37; index++) {
SPI.transfer(infopage[index]);
}
delay(1);
digitalWrite(_FCSN_, HIGH);
// Check flash is ready
do {
delay(10);
digitalWrite(_FCSN_, LOW);
SPI.transfer(RDSR);
fsr = SPI.transfer(0x00);
digitalWrite(_FCSN_, HIGH);
}
while (fsr & FSR_RDYN);
// Verify data that was written
Serial.println("VERFIYING InfoPage....");
digitalWrite(_FCSN_, LOW);
SPI.transfer(READ);
SPI.transfer(0);
SPI.transfer(0);
for (int index = 0; index < 37; index++) {
spi_data = SPI.transfer(0x00);
if (infopage[index] != spi_data) {
Serial.print("INFOPAGE VERIFY FAILED ");
Serial.print(index);
Serial.print(": WROTE ");
Serial.print(infopage[index]);
Serial.print(" READ ");
Serial.println(spi_data);
digitalWrite(_FCSN_, HIGH);
goto done;
}
}
delay(1);
digitalWrite(_FCSN_, HIGH);
// Clear InfoPage enable bit so main flash block is programed
digitalWrite(_FCSN_, LOW);
SPI.transfer(RDSR);
fsr = SPI.transfer(0x00);
digitalWrite(_FCSN_, HIGH);
digitalWrite(_FCSN_, LOW);
SPI.transfer(WRSR);
SPI.transfer(fsr & ~FSR_INFEN);
delay(1);
digitalWrite(_FCSN_, HIGH);
// Check InfoPage enable bit was cleared
digitalWrite(_FCSN_, LOW);
SPI.transfer(RDSR);
fsr = SPI.transfer(0x00);
digitalWrite(_FCSN_, HIGH);
if (fsr & FSR_INFEN) {
Serial.println("INFOPAGE DISABLE FAILED");
goto done;
}
while(true){
// Prompt perl script for data
Serial.println("OK");
// Serial.println(line++);
numChars = Serial.readBytesUntil('\n', inputRecord, 512);
if (numChars == 0) {
Serial.println("TIMEOUT");
goto done;
}
switch (ParseHexRecord(&hexRecord, inputRecord, numChars)){
case HEX_REC_OK:
break;
case HEX_REC_ILLEGAL_CHARS:
Serial.println("ILLEGAL CHARS");
goto done;
case HEX_REC_BAD_CHECKSUM:
Serial.println("BAD CHECKSUM");
goto done;
case HEX_REC_NULL_PTR:
Serial.println("NULL PTR");
goto done;
case HEX_REC_INVALID_FORMAT:
Serial.println("INVALID FORMAT");
goto done;
case HEX_REC_EOF:
Serial.println("EOF");
goto done;
}
// Set flash write enable latch
digitalWrite(_FCSN_, LOW);
SPI.transfer(WREN);
delay(1);
digitalWrite(_FCSN_, HIGH);
// Check flash is ready
do {
delay(10);
digitalWrite(_FCSN_, LOW);
SPI.transfer(RDSR);
fsr = SPI.transfer(0x00);
digitalWrite(_FCSN_, HIGH);
}
while (fsr & FSR_RDYN);
// Program flash
Serial.println("WRITING...");
digitalWrite(_FCSN_, LOW);
SPI.transfer(PROGRAM);
SPI.transfer(highByte(hexRecord.rec_address));
SPI.transfer(lowByte(hexRecord.rec_address));
for (int index = 0; index < hexRecord.rec_data_len; index++) {
SPI.transfer(hexRecord.rec_data[index]);
}
delay(1);
digitalWrite(_FCSN_, HIGH);
// Wait for flash to write
do {
delay(hexRecord.rec_data_len); // Wait 1 millisecond per byte written
digitalWrite(_FCSN_, LOW);
SPI.transfer(RDSR);
fsr = SPI.transfer(0x00);
digitalWrite(_FCSN_, HIGH);
}
while (fsr & FSR_RDYN);
// Read back flash to verify
Serial.println("VERIFYING...");
digitalWrite(_FCSN_, LOW);
SPI.transfer(READ);
SPI.transfer(highByte(hexRecord.rec_address));
SPI.transfer(lowByte(hexRecord.rec_address));
for (int index = 0; index < hexRecord.rec_data_len; index++) {
spi_data = SPI.transfer(0x00);
if ( spi_data != hexRecord.rec_data[index]) {
Serial.print("FAILED ");
Serial.print(hexRecord.rec_address + index);
Serial.print(": ");
Serial.print(spi_data);
Serial.print(" ");
Serial.println(hexRecord.rec_data[index]);
digitalWrite(_FCSN_, HIGH);
goto done;
}
}
digitalWrite(_FCSN_, HIGH);
}
done:
// Take nRF24LE1 out of programming mode
digitalWrite(PROG, LOW);
digitalWrite(_RESET_, LOW);
delay(10);
digitalWrite(_RESET_, HIGH);
SPI.end();
Serial.println("DONE");
}
void setup() {
// start serial port:
Serial.begin(57600);
Serial.setTimeout(30000);
// Reset nRF24LE1
pinMode(PROG, OUTPUT);
digitalWrite(PROG, LOW);
pinMode(_RESET_, OUTPUT);
digitalWrite(_RESET_, HIGH);
delay(10);
digitalWrite(_RESET_, LOW);
delay(10);
digitalWrite(_RESET_, HIGH);
nRF24LE1Serial.begin(NRF24LE1_BAUD);
}
void dump() {
char buf[32];
// start serial port:
Serial.begin(57600);
Serial.setTimeout(30000);
// Initialise SPI
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
SPI.setClockDivider(SPI_CLOCK_DIV4);
SPI.begin();
// Initialise control pins
pinMode(PROG, OUTPUT);
digitalWrite(PROG, LOW);
pinMode(_RESET_, OUTPUT);
digitalWrite(_RESET_, HIGH);
pinMode(_FCSN_, OUTPUT);
digitalWrite(_FCSN_, HIGH);
Serial.println("READY");
// Wait for GO command from Serial
//while (!Serial.find("GO\n"));
Serial.println("READYING");
delay(1000);
Serial.println("SETTING UP");
// Put nRF24LE1 into programming mode
digitalWrite(PROG, HIGH);
digitalWrite(_RESET_, LOW);
delay(10);
digitalWrite(_RESET_, HIGH);
// Set InfoPage bit so InfoPage flash is read
digitalWrite(_FCSN_, LOW);
SPI.transfer(RDSR);
fsr = SPI.transfer(0x00);
digitalWrite(_FCSN_, HIGH);
digitalWrite(_FCSN_, LOW);
SPI.transfer(WRSR);
SPI.transfer(fsr & ~FSR_INFEN);
delay(1);
digitalWrite(_FCSN_, HIGH);
digitalWrite(_FCSN_, LOW);
SPI.transfer(RDSR);
fsr = SPI.transfer(0x00);
digitalWrite(_FCSN_, HIGH);
if (fsr & FSR_INFEN) {
Serial.println("INFOPAGE DISABLE FAILED");
goto done;
}
delay(10);
// Read from MainPage
Serial.println("READING MainPage...");
digitalWrite(_FCSN_, LOW);
SPI.transfer(READ);
SPI.transfer(0);
SPI.transfer(0);
for (int row = 0x00; row < 0x400; row++) {
sprintf(buf, "%04X ", row*0x10);
Serial.print(buf);
for (int index = 0x00; index < 0x10; index++) {
spi_data = SPI.transfer(0x00);
sprintf(buf, "%02X ", spi_data);
Serial.print(buf);
}
Serial.println();
}
digitalWrite(_FCSN_, HIGH);
// Read from NV data (extended endurance)
Serial.println("READING NV (extended)...");
digitalWrite(_FCSN_, LOW);
SPI.transfer(READ);
SPI.transfer(0xFA);
SPI.transfer(0x00);
for (int row = 0x00; row < 0x20; row++) {
sprintf(buf, "%04X ", row*0x10);
Serial.print(buf);
for (int index = 0x00; index < 0x10; index++) {
spi_data = SPI.transfer(0x00);
sprintf(buf, "%02X ", spi_data);
Serial.print(buf);
}
Serial.println();
}
digitalWrite(_FCSN_, HIGH);
// Read from NV data (normal endurance)
Serial.println("READING NV (normal)...");
digitalWrite(_FCSN_, LOW);
SPI.transfer(READ);
SPI.transfer(0xFC);
SPI.transfer(0x00);
for (int row = 0x00; row < 0x40; row++) {
sprintf(buf, "%04X ", row*0x10);
Serial.print(buf);
for (int index = 0x00; index < 0x10; index++) {
spi_data = SPI.transfer(0x00);
sprintf(buf, "%02X ", spi_data);
Serial.print(buf);
}
Serial.println();
}
digitalWrite(_FCSN_, HIGH);
// Read InfoPage contents
Serial.println("READING INFOPAGE...");
digitalWrite(_FCSN_, LOW);
SPI.transfer(READ);
SPI.transfer(0);
SPI.transfer(0);
for (int index = 1; index < 38; index++) {
spi_data = SPI.transfer(0x00);
sprintf(buf, "%02X ", spi_data);
Serial.print(buf);
}
Serial.println();
digitalWrite(_FCSN_, HIGH);
done:
Serial.println("DONE");
// Take nRF24LE1 out of programming mode
digitalWrite(PROG, LOW);
digitalWrite(_RESET_, LOW);
delay(10);
digitalWrite(_RESET_, HIGH);
SPI.end();
}
char serialBuffer;
void loop() {
if (nRF24LE1Serial.available() > 0) {
// Pass through serial data receieved from the nRF24LE1
Serial.write(nRF24LE1Serial.read());
}
if (Serial.available() > 0) {
serialBuffer = Serial.read();
// Check if data received on USB serial port is the magic character to start flashing
if (serialBuffer == FLASH_TRIGGER_WRITEMAINPAGE) {
nRF24LE1Serial.end();
flash();
nRF24LE1Serial.begin(NRF24LE1_BAUD);
}
else if (serialBuffer == FLASH_TRIGGER_DUMP) {
nRF24LE1Serial.end();
dump();
nRF24LE1Serial.begin(NRF24LE1_BAUD);
} else {
// Otherwise pass through serial data received
nRF24LE1Serial.write(serialBuffer);
}
}
}