English Help: Flash Program Memory

Discussion in 'Embedded Systems and Microcontrollers' started by jpanhalt, Nov 11, 2014.

  1. jpanhalt

    Thread Starter AAC Fanatic!

    Jan 18, 2008
    5,699
    905
    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:
    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
     
  2. ericgibbs

    AAC Fanatic!

    Jan 29, 2010
    2,503
    380
    jpanhalt likes this.
  3. MrChips

    Moderator

    Oct 2, 2009
    12,446
    3,362
    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 (Text):
    1.  
    2. MOVLW LOW DATA_ADDR ; Load initial data address
    3. MOVWF FSR0L ;
    4. MOVLW HIGH DATA_ADDR ; Load initial data address
    5. MOVWF FSR0H
    6.  
    Little Endian refers to the byte format, i.e. low byte is written into low address, high byte into the next address.
     
    jpanhalt likes this.
  4. jpanhalt

    Thread Starter AAC Fanatic!

    Jan 18, 2008
    5,699
    905
    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
     
  5. MrChips

    Moderator

    Oct 2, 2009
    12,446
    3,362
    If you are writing a single word then there is no need for the indirect addressing mode.
    Simply load the data into PMDATH-PMDATL.
     
  6. jpanhalt

    Thread Starter AAC Fanatic!

    Jan 18, 2008
    5,699
    905
    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
     
  7. jpanhalt

    Thread Starter AAC Fanatic!

    Jan 18, 2008
    5,699
    905
    Edit: I will try just loading those registers. Although, using the indirect addressing will be foolproof.
     
  8. jpanhalt

    Thread Starter AAC Fanatic!

    Jan 18, 2008
    5,699
    905
    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
     
Loading...