English Help: Flash Program Memory

Thread Starter

jpanhalt

Joined Jan 18, 2008
11,087
I am trying to store calibration data generated during program execution in Flash Program Memory of a Pic16F1519. Language = MPASM Programmer = ICD3

The datasheet has an example for writing to Flash Memory (Example 11-3) which states:
; This write routine assumes the following:
; 1. 64 bytes of data are loaded, starting at the address in DATA_ADDR
; 2. Each word of data to be written is made up of two adjacent bytes in DATA_ADDR,
; stored in little endian format
; 3. A valid starting address (the least significant bits = 00000) is loaded in ADDRH:ADDRL
; 4. ADDRH and ADDRL are located in shared data memory 0x70 - 0x7F (common RAM)
I have spent two hours searching for a clear meaning of "DATA_ADDR." The only reference to it in the entire data sheet is in this example. Moreover, Google returns mostly hits to other datasheets with the same example. There is no reference to it in the example of how to read the data.

The point of my confusion is whether DATA_ADDR contains an address or data? Where is DATA_ADDR defined? (Steps #3 and 4 seem clear.) If defined, can it be in General Purpose Ram or must it be in Common Ram? Or, is it really a duplicate of the address in ADDRH/L? NB: I intend to save the calibration data near the end of program memory, as recommended by Microchip.

A simple example in Assembly would be most appreciated, but even something clarifying what it is would be helpful. Also, does the endian comment refer to the byte order or the bit order? I assume grammatically, it refers to the byte order.

John
 

MrChips

Joined Oct 2, 2009
34,629
DATA_ADDR is the address where the data to be written is found. The low and high portions of the address are written separately to the indirect address registers FSR0L and FSR0H.

Code:
MOVLW LOW DATA_ADDR ; Load initial data address
MOVWF FSR0L ;
MOVLW HIGH DATA_ADDR ; Load initial data address
MOVWF FSR0H
Little Endian refers to the byte format, i.e. low byte is written into low address, high byte into the next address.
 

Thread Starter

jpanhalt

Joined Jan 18, 2008
11,087
My datasheet should be current (DS40001452D, ©2010-2013). I downloaded it yesterday, after being confused by some obvious typos in that chapter of an earlier datasheet.

Example 11-2 is how to erase a row of memory. I want to write to it first ;) , which is Example 11-3. The frustrating part to me is that I have worked through the datasheet and the memory diagrams, which seem to make sense. I will be using CFGS=o. The amount of data I need to store is only is only a single 10-b it value, so a single 14-bit word (PMDATH:L) will suffice.

John
 

MrChips

Joined Oct 2, 2009
34,629
If you are writing a single word then there is no need for the indirect addressing mode.
Simply load the data into PMDATH-PMDATL.
 

Thread Starter

jpanhalt

Joined Jan 18, 2008
11,087
Thanks for that. The endian part was kind of an addon. The code example made it pretty clear that it referred to the bytes. I will now play with treating Data_Addr as the address with the data.

I know that must seem pellucidly obvious, but it is easy to get too close to the subject and confuse oneself.

John
 

Thread Starter

jpanhalt

Joined Jan 18, 2008
11,087
Thanks for that. The endian part was kind of an addon. The code example with indirect addressing made it pretty clear that it referred to the bytes. I will now play with treating Data_Addr as the address with the data.

I know that must seem pellucidly obvious, but it is easy to get too close to the subject and confuse oneself.

John
Edit: I will try just loading those registers. Although, using the indirect addressing will be foolproof.
 

Thread Starter

jpanhalt

Joined Jan 18, 2008
11,087
This could be a new thread, but it is closely related to this thread as well.

Short story: Is 3F80h the first valid address for flash memory in the 16F1519 device? Is 3FE0h the beginning of the last row of usable addresses?

Long Story:
At first, I thought I understood the PMADR (Program Memory Address) register and Figure 11-5 in the datasheet. It is on Page 98 and is too big to post in its entirety here. Here is a snippet showing one point of confusion:
upload_2014-11-12_2-26-52.png

That looks like a 15-bit H:L register packed with 5-bit and 10-bit information. It is also described elsewhere as 15-bit. Figure 11-5 shows flash memory locations up to 7FFFh, which don't exist in any of the devices covered by that datasheet. (Rant: Why describe a memory organization for a device to which the datasheet does not apply?) HOWEVER, sample program Example 11-2 treats it like a 14-bit pair:

upload_2014-11-12_2-34-50.png

Now, if you go back to table 3-1 shown immediately below (memory organization section), it seems to show that the usable range for this flash memory begins at 3F80h and ends at 3FFF. In contrast, Figure 11-5 seems to show that usable flash memory begins at 0000h. Which is correct? Does this mean that although lower addresses (e.g., 0080h) may not be HEF, they can be used for program flash memory as implied by Figure 11-5?
upload_2014-11-12_2-41-28.png

And finally, the concept of row designations is needed to calculate the beginning of accessible memory locations, but are row designations themselves ever used to address a location in memory?

John
 

Attachments

Top