-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathProgramming-flash-and-EEPROM
49 lines (41 loc) · 1.35 KB
/
Programming-flash-and-EEPROM
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
These are notes about programming flash and EEPROM via software on the chip,
not via ICSP.
I'm thinking about how much knowledge of the required sequence to put into the
chat code on the chip, and how much, for "safety's sake", to keep on the host
side.
Here are the sequences:
To read EEPROM:
- put address into EEADR
- clear EEPGD and CFGS in EECON1
- set RD in EECON1
- data is available in next instruction
- read EEDATA
To write EEPROM:
- put address into EEADR
- put data byte into EEDATA
- clear EEPGD and CFGS in EECON1
- set WREN in EECON1
- write 55 then AA to EECON2
- set WR in EECON1
- poll WR until it goes to 0
To erase a page of flash:
- set TBLPTRU/H/L
- clear CFGS
- set EEPGD, WREN, FREE in EECON1
- write 55 then AA to EECON2
- set WR in EECON1
CPU will stall until erase is finished.
To program a page of flash:
- set TBLPTRU/H/L
- fill write buffer
- write byte to TABLAT
- store byte via TBLWR*, TBLWR+*, or TBLWR*+
- clear CFGS
- set EEPGD, WREN in EECON1
- write 55 then AA to EECON2
- set WR in EECON1
CPU will stall until programming is finished.
NOTE: TBLPTR needs to point _within_ block to program, so using TBLWR*+ may not
work, as it will have incremented to point to the _following_ block.
Example code in datasheet uses TBLWR+* instead, so TBLPTR points to last byte
loaded during programming. Try this both ways and see which works?