-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArduino-RN2483-programmer.ino
More file actions
97 lines (85 loc) · 2.06 KB
/
Arduino-RN2483-programmer.ino
File metadata and controls
97 lines (85 loc) · 2.06 KB
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
// Arduino RN2483 low-voltage programmer
// Implemented using http://ww1.microchip.com/downloads/en/DeviceDoc/41398B.pdf
#include "RN2483LVP.h"
#define USBSERIAL SerialUSB
#define MCLR 4
#define PGD 5
#define PGC 6
int testseq[SIZE] = {0xFE, 0xED, 0xFD, 0xAA, 0xDA, 0x01, 0x01, 0x02, 0x13, 0x37, 0x19, 0x93, 0x4E, 0xFA};
bool serialcomplete = false;
String input = "";
RN2483LVP programmer;
void setup()
{
// put your setup code here, to run once:
USBSERIAL.begin(57600);
// Wait for USBSERIAL or start after 30 seconds
while ((!USBSERIAL) && (millis() < 30000))
;
USBSERIAL.write("USBSERIAL set up\r\n");
// Initialize LED
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
// Initialize pins
pinMode(MCLR, OUTPUT);
pinMode(PGD, OUTPUT);
pinMode(PGC, OUTPUT);
digitalWrite(MCLR, LOW);
digitalWrite(PGD, LOW);
digitalWrite(PGC, LOW);
// Wiggle MCLR
digitalWrite(MCLR, HIGH);
delay(10);
digitalWrite(MCLR, LOW);
delay(10);
digitalWrite(MCLR, HIGH);
delay(10);
// Initialize RN2483 low-voltage programmer object
programmer.initRN2483LVP(PGD, PGC, MCLR, USBSERIAL);
// Entering low-voltage program/verify mode
programmer.enterLVP();
}
void loop()
{
while (USBSERIAL.available())
{
char c = USBSERIAL.read();
if (c == '\n' || c == '\r' || c == 'X')
{
if (input != "")
{
serialcomplete = true;
}
break;
}
input += c;
}
if (serialcomplete)
{
int response;
switch (input.charAt(0))
{
case 'W':
USBSERIAL.print("Writing\r\n");
programmer.writeFlash(testseq);
USBSERIAL.print("Done writing\r\n");
break;
case 'R':
USBSERIAL.print("Reading\r\n");
programmer.printCodeMemory(0, 31);
break;
case 'D':
USBSERIAL.print("Reading device ID\r\n");
programmer.readDeviceID();
break;
case 'E':
USBSERIAL.print("Bulk erasing\r\n");
programmer.bulkErase();
break;
default:
USBSERIAL.write("Invalid serial command\r\n");
}
serialcomplete = false;
input = "";
}
}