• AVR Freaks

Hot!PIC24FJ256GA106 flash write

Author
FerrariLuigi
Starting Member
  • Total Posts : 63
  • Reward points : 0
  • Joined: 2015/07/16 11:19:30
  • Location: 0
  • Status: offline
2020/07/05 03:50:46 (permalink)
0

PIC24FJ256GA106 flash write

Dear all,


I'm developing a simple program to write data in the PIC24FJ256GA106 CPU flash memory.
The program is very short and does not exceed 64k Byte.

I just copy and paste the example from the datasheet ( EXAMPLE 5-2 and EXAMPLE 5-4 from DS30009905F document) replacing the

unsigned long progAddr = 0xXXXXXX; // Address of row to write


with


unsigned long progAddr = 0x18000; // Address of row to write


In the example the ram buffer (unsigned int progData[2*NUM_INSTRUCTION_PER_ROW];) is not initialized so the flash should be filled with 0 (zero).


I compiled and uploaded the code in the CPU and I executed it in debug (I'm using ICD3 tool). Then I reloaded memory back the memory by using read device memory main project button in the toolbar of MPLAB-X and I selected Window -> Target Memory View -> Program Memory and fo to 0x18000 address.

I expected to read 0 (zero) but the memory was filled with 0xff

Did you have similar problem ?

How did you fixe it ?

Thank you very nuch for your help and cooperation

regards


Luigi Ferrari
#1

4 Replies Related Threads

    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3984
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: PIC24FJ256GA106 flash write 2020/07/05 04:49:18 (permalink)
    1.33 (3)
    0xFF means that it is erased.
    Sounds like nothing was written.
     
    What makes you think that un-initialized data will
    contain zero?
     
    "I expected to read 0 (zero) but the memory was filled with 0xff"
    Something you've done wrong.
     
    Why not read the datasheet?
     
    Anyhow, it's line 256.

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #2
    ric
    Super Member
    • Total Posts : 27952
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC24FJ256GA106 flash write 2020/07/05 05:53:52 (permalink)
    0
    FerrariLuigi
    In the example the ram buffer (unsigned int progData[2*NUM_INSTRUCTION_PER_ROW];) is not initialized so the flash should be filled with 0 (zero).

    WHERE is the RAM buffer defined?
    If it is an auto variable (not global), then uninitialised means exactly that, it could ocntain anything.
    Only global buffers are zeroed. Best not to rely on defaults at all.
    As Gort said, if you got 0xFF, then most likely no write happened at all.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #3
    FerrariLuigi
    Starting Member
    • Total Posts : 63
    • Reward points : 0
    • Joined: 2015/07/16 11:19:30
    • Location: 0
    • Status: offline
    Re: PIC24FJ256GA106 flash write 2020/07/05 08:10:06 (permalink)
    0
    Dear all,
    I'm sorry for my uncomplete code
     
     
    unsigned long progAddr = 0x18000; // Address of row to write
    unsigned int offset;

    void testErase() {
        //Set up pointer to the first memory location to be written
        TBLPAG = progAddr >> 16; // Initialize PM Page Boundary SFR
        offset = progAddr & 0xFFFF; // Initialize lower word of address
        __builtin_tblwtl(offset, 0x0000); // Set base address of erase block
        // with dummy latch write
        NVMCON = 0x4042; // Initialize NVMCON
        asm("DISI #5"); // Block all interrupts with priority <7
        // for next 5 instructions
        __builtin_write_NVM(); // C30 function to perform unlock
        // sequence and set WR
    }

    #define NUM_INSTRUCTION_PER_ROW 64

    unsigned int progData[2 * NUM_INSTRUCTION_PER_ROW]; // Buffer of data to write

    void testwrite() {
        // C example using MPLAB C30
        unsigned int offset;
        unsigned int i;
        unsigned long progAddr = 0x18000; // Address of row to write

        //Set up NVMCON for row programming
        NVMCON = 0x4001; // Initialize NVMCON
        //Set up pointer to the first memory location to be written
        TBLPAG = progAddr >> 16; // Initialize PM Page Boundary SFR
        offset = progAddr & 0xFFFF; // Initialize lower word of address
        //Perform TBLWT instructions to write necessary number of latches
        for (i = 0; i < 2 * NUM_INSTRUCTION_PER_ROW; i++) {
            __builtin_tblwtl(offset, progData[i++]); // Write to address low word
            __builtin_tblwth(offset, progData[i]); // Write to upper byte
            offset = offset + 2; // Increment address
        }
    }


     
    regards
    #4
    FerrariLuigi
    Starting Member
    • Total Posts : 63
    • Reward points : 0
    • Joined: 2015/07/16 11:19:30
    • Location: 0
    • Status: offline
    Re: PIC24FJ256GA106 flash write 2020/07/05 08:27:12 (permalink)
    4 (1)
    Ok I solved the problem
    I just added to my code the following instructons:
     
     
            asm("DISI #5"); // Block all interrupts with priority < 7
            // for next 5 instructions
            __builtin
     
    _write_NVM(); // Perform unlock sequence and set WR

    Thank you for your help
    regards!
     
    #5
    Jump to:
    © 2020 APG vNext Commercial Version 4.5