PIC24E writing address and increment for ICSP programming

addressingmicrochipmicrocontrollerpicprogramming

I am trying to program my Microchip PIC24EP512GU814 in ICSP mode. The resource I'm using to do this is the Microchip dsPIC33E/PIC24E Flash programming Specifications (70619B) and the Microchip dsPIC33EP/PIC24EP Data Sheet (70616g). So far I've programmed an Arduino to enter ICSP mode, and erase everything on the chip, but I am currently stuck at writing on the chip.

Section 6.6 has a table 6-5 on page 31 which shows steps on how to write onto the chip. Step #6 has the following snippet:

MOV #DestinationAddress<15:0>, W2
MOV #DestinationAddress<23:16>, W3

In context: these instructions are to be executed once 128 instructions have been inputted into the write latches. This snippet define the location in the code memory into which the instructions from the write latches are copied.

I currently can't figure out which address I should start with, and how much does the address increment by for the next 128 instructions?

I've looked at the Section 4.1, Figure 4-1 of the Data Sheet (70616g) and Section 2.3, Figure 2-2 of the Programming Specifications (70619B). Is the code memory the same thing as the User Program Flash Memory in these figures? As such, should the destination address in the above snippet start at 0x000200?

Since this establishes a write for 128 instructions, does it increment by 128 = 0x80? Or does it increment by the number of bits written (24×128= 3072 = 0xC00)?

Best Answer

You'd start at 0x0, because the stuff there (IVT, etc) are part of what you want to upload. PIC addressing is always confusing because of their insistence on weird architectures with 14 or 24 bit words, but I believe the destination address would increment by 0x100 for 128 instructions -- this is supported by the comment in 5.2.9 of the programming spec, "The destination address should be a multiple of 0x100", as well as the flow chart shown in figure 3-4.