Writing to Program code space using Writecode command.A


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2011
    Location
    Hawaii
    Posts
    21

    Default Writing to Program code space using Writecode command.A

    Using a 18F26J11 device and having problems loading a byte or word into the program memory space. Program details below:

    #CONFIG
    CONFIG WDTEN = ON
    CONFIG STVREN = ON
    CONFIG XINST = OFF
    CONFIG DEBUG = OFF
    CONFIG CP0 = OFF
    CONFIG OSC = INTOSC ; For 8MHz clock set CONFIG OSC = INTOSC. For 32MHz clock set to INTOSCPLL.
    CONFIG T1DIG = ON
    CONFIG LPT1OSC = ON
    CONFIG FCMEN = OFF
    CONFIG IESO = OFF
    CONFIG WDTPS = 512 ; 2.1 sec.
    CONFIG DSWDTOSC = INTOSCREF
    CONFIG RTCOSC = INTOSCREF
    CONFIG DSBOREN = OFF
    CONFIG DSWDTEN = OFF
    CONFIG DSWDTPS = 2048 ; 2.1 sec.
    CONFIG IOL1WAY = OFF
    CONFIG MSSP7B_EN = MSK5
    CONFIG WPEND = PAGE_WPFP
    CONFIG WPCFG = OFF
    CONFIG WPDIS = OFF

    DEFINE OSC 8
    DEFINE USE_LFSR 1
    DEFINE HSER_CLROERR 1
    DEFINE HSER2_CLROERR 1
    DEFINE WRITE_INT 1

    a VAR BYTE

    ERASECODE $F400
    WRITECODE $F400, $55
    READCODE $F400, a

    The value of "a" always comes back as $FF. I have tested the READCODE at other locations in memory and it works. I first erase block 62. One block equals 1024 bytes then follow with the WRITECODE command. Program code protection is turned off as shown in the configuration setting. Does anything stand out here ?

    - Martin

  2. #2
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default Re: Writing to Program code space using Writecode command.A

    So You have a few problems in your code but you need to read the datasheet carfully and understand what options you have.

    You must erase before you can write a new value to the chip.

    PBP supports block erase and block write but not the ONE WORD write support this device has.


    If you do block block write you must write the variables you want to change + dummy writes to complete an entire block and THEN the flash is written.

    Read all of chapter 7 in the datasheet especially the Notes in the right side of page 109.

    It is not that hard as it seems but it is way more complicated than an EE-prom and remember you can only get 10 000 writes to the flash.. compared to 1 million if you use a standard external Microchip EEprom



    Chapter 7.0 in the datasheet

    The program memory space is 16 bits wide, while the
    data RAM space is 8 bits wide


    A read from program memory is executed on 1 byte ata time. A write to program memory is executed onblocks of 64 bytes at a time or 2 bytes at a time.Program memory is erased in blocks of 1024 bytes at
    a time.

    7.4 Erasing Flash Program Memory
    The minimum erase block is 512 words or 1024 bytes.
    Only through the use of an external programmer, or
    through ICSP control, can larger blocks of program
    memory be bulk erased. Word erase in the Flash array
    is not supported.


    7.5.2 FLASH PROGRAM MEMORY WRITE
    SEQUENCE (WORD PRORAMMING).
    The PIC18F46J11 family of devices has a feature that
    allows programming a single word (two bytes). This
    feature is enabled when the WPROG bit is set.

    Last edited by Jumper; - 26th January 2012 at 11:23.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Writing to Program code space using Writecode command.A

    I think the 26J11 has the same kind of Flash memory as the 26J50.

    Try this code, which let's you write 1-word at a time.
    http://www.picbasic.co.uk/forum/show...438#post104438
    DT

  4. #4
    Join Date
    Jul 2011
    Location
    Hawaii
    Posts
    21


    Did you find this post helpful? Yes | No

    Default Re: Writing to Program code space using Writecode command.A

    Darrel,

    Thanks for the tip. The routine works very well !

    - Martin

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts