Erasecode,Writecode,Readcode - again


Closed Thread
Results 1 to 15 of 15
  1. #1
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107

    Default Erasecode,Writecode,Readcode - again

    Can someone tell me why the code below doesn't work?

    I'm using an 18F8722. All variables are WORDs.
    I do get the proper output for 4 words, starting at
    $1F38, but all the other bytes are $FF. I'm on an even word boundary, and $1F00 divides evenly by 64, so I should also be on a block boundary.


    For AA = $1F00 to $1F3F STEP 2
    ERASECODE AA
    NEXT AA

    For BB = $1F00 to $1F3F STEP 2
    WRITECODE BB,$5555
    NEXT BB

    For CC = $1F00 to $1F3F STEP 2
    READCODE CC,DD
    HSEROUT [HEX4 CC," ",HEX4 DD,13,10]
    NEXT CC
    Charles Linquist

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


    Did you find this post helpful? Yes | No

    Default

    The FOR AA loop will erase the same block of flash 32 times.
    ERASECODE ignores the lowest 6 bits of the address, and erases the whole 64 byte block.

    The rest seems like it should work. As long as you don't have any interrupts going on at the same time.
    <br>
    DT

  3. #3
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Almost !


    Here is the new code:


    ERASECODE $1F00


    For BB = $1F00 to $1F3F STEP 2
    WRITECODE BB,$5555
    NEXT BB

    For CC = $1F00 to $1F3F STEP 2
    READCODE CC,DD
    HSEROUT [HEX4 CC," ",HEX4 DD,13,10]
    NEXT CC


    And here is the output:

    1F00 FFFF
    1F02 FFFF
    1F04 FFFF
    1F06 FFFF
    1F08 FFFF
    1F0A FFFF
    1F0C FFFF
    1F0E FFFF
    1F10 FFFF
    1F12 FFFF
    1F14 FFFF
    1F16 FFFF
    1F18 FFFF
    1F1A FFFF
    1F1C FFFF
    1F1E FFFF
    1F20 FFFF
    1F22 FFFF
    1F24 FFFF
    1F26 FFFF
    1F28 FFFF
    1F2A FFFF
    1F2C FFFF
    1F2E FFFF
    1F30 FFFF
    1F32 FFFF
    1F34 FFFF
    1F36 FFFF
    1F38 5555
    1F3A 5555
    1F3C 5555
    1F3E 5555


    I get the same result if I use "ERASECODE $7C" ($1F00/$3F)
    Charles Linquist

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


    Did you find this post helpful? Yes | No

    Default

    I might see what's going wrong, and if I'm right, it's a PBP problem.

    I wish I had an 8722, but I don't. If you have a couple minutes, can you try this program. It should zero the area when programmed and displays the memory first. Then erases it and shows memory again. After manually writing 64 bytes, it dumps the memory 1 last time.
    Code:
    AA VAR WORD
    BB VAR WORD
    CC VAR WORD
    DD VAR WORD
    
    Gosub ShowFlash
    ERASECODE $1F00
    Gosub ShowFlash
    
    TBLPTRU = 0
    TBLPTRH = $1F
    TBLPTRL = 0
    For BB = 0 to 63
        TABLAT = BB.Lowbyte
        @ tblwt*+
    NEXT BB
    TBLPTRL = TBLPTRL - 1
    EECON1 = $84
    EECON2 = $55
    EECON2 = $AA
    ASM
        bsf   EECON1, WR
        nop
        bcf   EECON1, WREN
    endasm
    
    Gosub ShowFlash
    
    stop
    ;_____________________________________________
    ShowFlash:
        For CC = $1F00 to $1F3F STEP 2
            READCODE CC,DD
            HSEROUT [HEX4 CC," ",HEX4 DD,13,10]
        NEXT CC
        HSEROUT [10]
    return
    
    ASM                   ; load 0's in the area we want to write to
      org 1F00h
      db  0,0,0,0,0,0,0,0
      db  0,0,0,0,0,0,0,0
      db  0,0,0,0,0,0,0,0
      db  0,0,0,0,0,0,0,0
      db  0,0,0,0,0,0,0,0
      db  0,0,0,0,0,0,0,0
      db  0,0,0,0,0,0,0,0
      db  0,0,0,0,0,0,0,0
    endasm
    If that works, then I'll know where the problem is.
    <br>
    DT

  5. #5
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    Here is the output from your program -


    1F00 FFFF
    1F02 FFFF
    1F04 FFFF
    1F06 FFFF
    1F08 FFFF
    1F0A FFFF
    1F0C FFFF
    1F0E FFFF
    1F10 FFFF
    1F12 FFFF
    1F14 FFFF
    1F16 FFFF
    1F18 FFFF
    1F1A FFFF
    1F1C FFFF
    1F1E FFFF
    1F20 FFFF
    1F22 FFFF
    1F24 FFFF
    1F26 FFFF
    1F28 FFFF
    1F2A FFFF
    1F2C FFFF
    1F2E FFFF
    1F30 FFFF
    1F32 FFFF
    1F34 FFFF
    1F36 FFFF
    1F38 3938
    1F3A 3B3A
    1F3C 3D3C
    1F3E 3F3E


    1F00 FFFF
    1F02 FFFF
    1F04 FFFF
    1F06 FFFF
    1F08 FFFF
    1F0A FFFF
    1F0C FFFF
    1F0E FFFF
    1F10 FFFF
    1F12 FFFF
    1F14 FFFF
    1F16 FFFF
    1F18 FFFF
    1F1A FFFF
    1F1C FFFF
    1F1E FFFF
    1F20 FFFF
    1F22 FFFF
    1F24 FFFF
    1F26 FFFF
    1F28 FFFF
    1F2A FFFF
    1F2C FFFF
    1F2E FFFF
    1F30 FFFF
    1F32 FFFF
    1F34 FFFF
    1F36 FFFF
    1F38 FFFF
    1F3A FFFF
    1F3C FFFF
    1F3E FFFF

    1F00 FFFF
    1F02 FFFF
    1F04 FFFF
    1F06 FFFF
    1F08 FFFF
    1F0A FFFF
    1F0C FFFF
    1F0E FFFF
    1F10 FFFF
    1F12 FFFF
    1F14 FFFF
    1F16 FFFF
    1F18 FFFF
    1F1A FFFF
    1F1C FFFF
    1F1E FFFF
    1F20 FFFF
    1F22 FFFF
    1F24 FFFF
    1F26 FFFF
    1F28 FFFF
    1F2A FFFF
    1F2C FFFF
    1F2E FFFF
    1F30 FFFF
    1F32 FFFF
    1F34 FFFF
    1F36 FFFF
    1F38 3938
    1F3A 3B3A
    1F3C 3D3C
    1F3E 3F3E
    Charles Linquist

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


    Did you find this post helpful? Yes | No

    Default

    OK, after those results, I'm compelled to go out on a limb.

    That limb is to say that...
    1. PBP is wrong, by declaring BLOCK_SIZE as 64 bytes. But I can't blame them, because....
    2. Microchip is wrong, since their datasheet says the Flash must be written 64 bytes at a time.

    It seems apparent that the 18F8722 only has 8 holding registers for flash writes (regardless of what the datasheet says). It does erase 64 bytes at once. But you can only write 8 bytes at a time. Coincidently, that's the same as the 18F8720, it's predecessor.

    I may be eating crow by the next post. But I'm pretty sure this will work...
    Code:
    AA VAR WORD
    BB VAR WORD
    CC VAR WORD
    DD VAR WORD
     X VAR BYTE
     
    ERASECODE $1F00
    
    TBLPTRU = 0
    TBLPTRH = $1F
    TBLPTRL = 0
    for X = 0 to 7
        gosub Write8
    next X
    
    Gosub ShowFlash
    
    stop
    ;_____________________________________________
    Write8:
        For BB = 0 to 7
            TABLAT = BB.Lowbyte
            @ tblwt*+
        NEXT BB
        TBLPTRL = TBLPTRL - 1
        EECON1 = $84
        EECON2 = $55
        EECON2 = $AA
        ASM
            bsf   EECON1, WR
            nop
            bcf   EECON1, WREN
        endasm
        TBLPTRL = TBLPTRL + 1
    return
    
    ShowFlash:
        For CC = $1F00 to $1F3F STEP 2
            READCODE CC,DD
            HSEROUT [HEX4 CC," ",HEX4 DD,13,10]
        NEXT CC
        HSEROUT [10]
    return
    Then, assuming that works. Simply changing BLOCK_SIZE EQU 64 to, BLOCK_SIZE EQU 8 in the 18F8722.INC file should fix it.

    The only thing I have here to test it on is an 18F6720, which is also Erase 64/write 8. And it works here....

    Prepare to feed me my Crow.
    <br>
    DT

  7. #7
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    WORKS!

    Thanks again!



    Anybody from Microchip out there listening? You owe Darrel at least a dinner!
    Charles Linquist

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis View Post
    WORKS!

    Thanks again!



    Anybody from Microchip out there listening? You owe Darrel at least a dinner!
    And I have to wonder how and why my PICKIT2 works with the '8722 if it's actually using the datasheet specifications.
    Apparently, Microchip is holding out on the datasheet info and/or revisions/errata again...

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis View Post
    WORKS!
    Oh thank God!
    It's always so hard to get the feathers out of my teeth.
    DT

  10. #10
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Thanks to a mis-labeled board (it actually had an 8720 on it, rather than an 8722), I really got things screwed up.

    And it turns out that MC's documentation is indeed correct - the 8720 has a block size of 8 bytes, while the 8722 has a block size of 64 bytes.

    Everything is working now. I *would* let Darrel feed me some of that crow, but I'm a vegetarian !
    Charles Linquist

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


    Did you find this post helpful? Yes | No

    Default Omg!

    And let that be a lesson to everyone.

    Never trust your test equipment unconditionally.
    Especially when it's not electronic.

    Ok well, I suppose I'll have a few feathers for dinner, but I can see you're not going to chow down willingly, mr vegan. So just to make sure, I've put a heaping helping in your avatar.
    DT

  12. #12
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    And let that be a lesson to everyone.

    Never trust your test equipment unconditionally.
    Especially when it's not electronic.

    Ok well, I suppose I'll have a few feathers for dinner, but I can see you're not going to chow down willingly, mr vegan. So just to make sure, I've put a heaping helping in your avatar.
    I'll trade ya some spaghetti for some of that crow
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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


    Did you find this post helpful? Yes | No

    Default

    Spaghetti sounds good.

    But some floss for the feathers would be better.
    <br>
    DT

  14. #14
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Hey! Who put that picture on my post! Strangely enough, it DOES look a little like me.
    Charles Linquist

  15. #15
    Join Date
    Apr 2010
    Location
    Walnut Creek, CA
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: Erasecode,Writecode,Readcode - again

    Good golly, this works. I fussed around with PBP WRITECODE for way too long and gave up, modified Darrel's code slightly, and it works! Here's my code. Thanks Darrel!

    Code for PIC18F8722:

    FOR IX = 0 TO 63 ' for DEBUG
    FLASH_WRITE_BUFF[IX] = IX + 64 ' for DEBUG
    NEXT IX ' for DEBUG
    ' DEBUG WRITE FLASH PROGRAM MEM TEST
    ERASECODE FLASH_MEM_START
    FOR IX = 0 TO 63 ' load TBLAT
    TABLAT = FLASH_WRITE_BUFF[IX]
    @ tblwt*+
    NEXT IX
    TBLPTRL = FLASH_MEM_START
    EECON1 = $84
    EECON2 = $55
    EECON2 = $AA
    ASM
    BSF EECON1, WR
    NOP
    BCF EECON1, WREN
    ENDASM
    TBLPTRL = TBLPTRL + 1
    ' DONE WRITING FLASH PROGRAM MEM TEST

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