• AVR Freaks

Hot!PIC16F883 FLASH WRITING

Author
daraga
Junior Member
  • Total Posts : 107
  • Reward points : 0
  • Joined: 2006/09/29 03:35:28
  • Location: 0
  • Status: offline
2019/12/02 08:01:03 (permalink)
0

PIC16F883 FLASH WRITING

Hi to all,
 
I'm trying to understand how to write the flash memory of my PIC16F883 and I have the next question:
 
The data explains that: "after writing the first four words on the Buffer Registers sixteen words of flash are erased and then the buffers are transfered to flash automatically."
 
which is the meaning of 16 words of flash are erased?
  • that I could write more words on buffer without writing the address till 16 words?
  • that after the first writing firstly 16 words are erased from flash and the the words are written. So inthat case the next words would be 3FFF?
As you can see I am a little bit lost.... Anyone can help me?
 
Many thanks for you help.
 
Regards,
daraga
 
 
 
 
#1

12 Replies Related Threads

    Jim Nickerson
    User 452
    • Total Posts : 6376
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: PIC16F883 FLASH WRITING 2019/12/02 08:12:07 (permalink)
    0
    Maybe you could give it a try and see what happens
    #2
    NorthGuy
    Super Member
    • Total Posts : 5817
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: PIC16F883 FLASH WRITING 2019/12/02 08:18:48 (permalink)
    +1 (1)
    Before write you need to erase. You erase by pages 16 words at a time. Then you can write it. You can write 4 words at a time.
    #3
    daraga
    Junior Member
    • Total Posts : 107
    • Reward points : 0
    • Joined: 2006/09/29 03:35:28
    • Location: 0
    • Status: offline
    Re: PIC16F883 FLASH WRITING 2019/12/02 08:23:55 (permalink)
    0
    Hi Jim,
     
    I tried writing  the first four words. It worked ok but the next 12 words remainded unchanged.
    I tried writing the second part of a block and the result was the same. the for words were properly written but the before and next words remainded unchanged.
     
    There are other PICs as the 16F1827 that have an special secuence: read modify erase write.
     
    So I do not understand really well what means the data with 16 words flash erase. 
    Could anyone explain me a little bit the secuence?
     
    Thanks in advance,
    daraga
     
     
     
     
     
    #4
    daraga
    Junior Member
    • Total Posts : 107
    • Reward points : 0
    • Joined: 2006/09/29 03:35:28
    • Location: 0
    • Status: offline
    Re: PIC16F883 FLASH WRITING 2019/12/02 08:39:38 (permalink)
    0
    Hi NothGuy,
     
    Ok that's clear that the secuence needs to erase the bytes before writing but if only are written 4 words the rest of bytes  till 16 words are erased but where??? are erased from the program memory?( I have not seen that...)
     
    Really tricky this data....
     
    Regards,
     
    daraga
    #5
    NorthGuy
    Super Member
    • Total Posts : 5817
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: PIC16F883 FLASH WRITING 2019/12/02 09:11:01 (permalink)
    +1 (1)
    Writing can only change '1' to '0'.  Erasing sets all bits to '1'.
     
    Thus, you erase the whole page (16 words starting from address which is aligned to 16). Then you write 4 times (4 words each time) to fill the page with your data.
     
    For example, you erase the page starting from 0x80. Then you write 4 times to 0x80, 0x84, 0x88, 0x8c. Each write writes 4 words.
     
    It must be explained in the datasheet quite well.
    #6
    daraga
    Junior Member
    • Total Posts : 107
    • Reward points : 0
    • Joined: 2006/09/29 03:35:28
    • Location: 0
    • Status: offline
    Re: PIC16F883 FLASH WRITING 2019/12/02 09:18:08 (permalink)
    0
    Dear NorthGuy,
     
    Yes yes but what happend when I only write 4 words? What happend with the rest of erased words till 16? 
     
    I checked that they remain similar without any changing... 
     
    This is my headache....
     
    Thaks for your time and help
    daraga
    #7
    1and0
    Access is Denied
    • Total Posts : 10005
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: PIC16F883 FLASH WRITING 2019/12/02 09:41:19 (permalink)
    0
    NorthGuy
    It must be explained in the datasheet quite well.

    Actually it does not explained well. Quoting the datasheet (change to 4-word blocks for the 16F883),

    "When the write is performed on the last word (EEADR<1:0> = 11), a block of sixteen words is automatically erased and the content of the 4-word buffer registers are written into program memory."
     
    Reading that sentence literally, each 4-word write erases 16 words; i.e. the other 12 words are erased each time a write is performed.?!
    #8
    1and0
    Access is Denied
    • Total Posts : 10005
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: PIC16F883 FLASH WRITING 2019/12/02 10:24:49 (permalink)
    +1 (1)
    NorthGuy
    For example, you erase the page starting from 0x80. Then you write 4 times to 0x80, 0x84, 0x88, 0x8c. Each write writes 4 words.

    From educated guess (and my fuzzy logic ;), sixteen words of flash are erased then the four buffers are transferred to flash automatically after the word with address EEADR<3:0> = 0011 is written; i.e. writing address 0x0083 erases 0x0080-0x008F. The following three 4-word writes do NOT perform the erase. This of course will need confirmation by testing with real hardware, since the datasheet is not clear.
     
    post edited by 1and0 - 2019/12/02 10:32:49
    #9
    NorthGuy
    Super Member
    • Total Posts : 5817
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: PIC16F883 FLASH WRITING 2019/12/02 10:36:26 (permalink)
    0
    1and0
    Actually it does not explained well. Quoting the datasheet (change to 4-word blocks for the 16F883),

     
    Sorry, my bad. When you write from the outside of the chip, the row erase operation is a separate operation.
     
    Looks like when you do it from inside, it's automatic, as with EEPROM. This is strange because there are only 4 latches, and the row is 16 words. I think the best way to see how it works is to experiment.
    #10
    ric
    Super Member
    • Total Posts : 24638
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: PIC16F883 FLASH WRITING 2019/12/02 12:20:56 (permalink)
    +1 (1)
    daraga
    Ok that's clear that the secuence needs to erase the bytes before writing but if only are written 4 words the rest of bytes  till 16 words are erased but where??? are erased from the program memory?( I have not seen that...)

    How are you checking this?
    • In the simulator?
    • In a debugger, using a watch window to view program memory? (This is a problem, the watch window is NOT a live view)
    • Running real code, and outputting program memory to a serial port etc?
     

    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!
    #11
    ric
    Super Member
    • Total Posts : 24638
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: PIC16F883 FLASH WRITING 2019/12/02 12:20:57 (permalink)
    0
    daraga
    Ok that's clear that the secuence needs to erase the bytes before writing but if only are written 4 words the rest of bytes  till 16 words are erased but where??? are erased from the program memory?( I have not seen that...)

    How are you checking this?
    • In the simulator?
    • In a debugger, using a watch window to view program memory? (This is a problem, the watch window is NOT a live view)
    • Running real code, and outputting program memory to a serial port etc?
     

    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!
    #12
    daraga
    Junior Member
    • Total Posts : 107
    • Reward points : 0
    • Joined: 2006/09/29 03:35:28
    • Location: 0
    • Status: offline
    Re: PIC16F883 FLASH WRITING 2019/12/03 06:42:53 (permalink)
    0
    Dear ric,
     
    Yes, I check it running real code. Using serial port I send some messages to the chip.
     
    First of all I program my chip without any code protection. I read the program memory and sabe it on an hex file.
     
    I send a message to the chip with to the address and data to be loaded.
     
    I read again the memory of the chip and I compare it (using WinMerge)  with the previous read file.
     
    There I can see which are the changes on the memory.
     
    This morning I have not had time for programming I hope to start again with the program memory update.
     
    Thanks to all, again
    daraga
    #13
    Jump to:
    © 2019 APG vNext Commercial Version 4.5