English
Language : 

DSPIC30F3013-30I Datasheet, PDF (51/210 Pages) Microchip Technology – High-Performance, 16-bit Digital Signal Controllers
dsPIC30F2011/2012/3012/3013
5.6 Programming Operations
A complete programming sequence is necessary for
programming or erasing the internal Flash in RTSP
mode. A programming operation is nominally 2 msec in
duration and the processor stalls (waits) until the
operation is finished. Setting the WR bit
(NVMCON<15>) starts the operation and the WR bit is
automatically cleared when the operation is finished.
5.6.1
PROGRAMMING ALGORITHM FOR
PROGRAM FLASH
The user can erase or program one row of program
Flash memory at a time. The general process is:
1. Read one row of program Flash (32 instruction
words) and store into data RAM as a data
“image”.
2. Update the data image with the desired new
data.
3. Erase program Flash row.
a) Set up NVMCON register for multi-word,
program Flash, erase, and set WREN bit.
b) Write address of row to be erased into
NVMADRU/NVMDR.
c) Write 0x55 to NVMKEY.
d) Write 0xAA to NVMKEY.
e) Set the WR bit. This begins erase cycle.
f) CPU stalls for the duration of the erase cycle.
g) The WR bit is cleared when erase cycle
ends.
4. Write 32 instruction words of data from data
RAM “image” into the program Flash write
latches.
5. Program 32 instruction words into program
Flash.
a) Set up NVMCON register for multi-word,
program Flash, program, and set WREN
bit.
b) Write 0x55 to NVMKEY.
c) Write 0xAA to NVMKEY.
d) Set the WR bit. This begins program cycle.
e) CPU stalls for duration of the program cycle.
f) The WR bit is cleared by the hardware
when program cycle ends.
6. Repeat steps 1 through 5 as needed to program
desired amount of program Flash memory.
5.6.2
ERASING A ROW OF PROGRAM
MEMORY
Example 5-1 shows a code sequence that can be used
to erase a row (32 instructions) of program memory.
EXAMPLE 5-1: ERASING A ROW OF PROGRAM MEMORY
; Setup NVMCON for erase operation, multi word write
; program memory selected, and writes enabled
MOV
#0x4041,W0
;
MOV
W0,NVMCON
; Init pointer to row to be ERASED
; Init NVMCON SFR
MOV
#tblpage(PROG_ADDR),W0
;
MOV
W0,NVMADRU
MOV
#tbloffset(PROG_ADDR),W0
; Initialize PM Page Boundary SFR
; Intialize in-page EA[15:0] pointer
MOV
W0, NVMADR
; Initialize NVMADR SFR
DISI #5
; Block all interrupts with priority <7 for
; next 5 instructions
MOV
#0x55,W0
MOV
W0,NVMKEY
MOV
#0xAA,W1
; Write the 0x55 key
;
MOV
BSET
W1,NVMKEY
NVMCON,#WR
; Write the 0xAA key
; Start the erase sequence
NOP
; Insert two NOPs after the erase
NOP
; command is asserted
© 2010 Microchip Technology Inc.
DS70139G-page 51