PDA

View Full Version : Erasecode,Writecode,Readcode - again



Charles Linquis
- 20th March 2007, 15:33
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

Darrel Taylor
- 20th March 2007, 18:05
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>

Charles Linquis
- 20th March 2007, 18:25
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)

Darrel Taylor
- 20th March 2007, 21:28
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.
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>

Charles Linquis
- 20th March 2007, 23:01
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

Darrel Taylor
- 21st March 2007, 00:16
OK, after those results, I'm compelled to go out on a limb.

That limb is to say that...

PBP is wrong, by declaring BLOCK_SIZE as 64 bytes. But I can't blame them, because....
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...
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>

Charles Linquis
- 21st March 2007, 01:49
WORKS!

Thanks again!



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

skimask
- 21st March 2007, 02:19
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...

Darrel Taylor
- 21st March 2007, 02:53
WORKS!

Oh thank God!
It's always so hard to get the feathers out of my teeth. :)
http://www.pbpgroup.com/files/NoCrow.gif

Charles Linquis
- 21st March 2007, 21:54
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 !

Darrel Taylor
- 21st March 2007, 23:02
And let that be a lesson to everyone. :eek:

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. :D

Archangel
- 22nd March 2007, 05:30
And let that be a lesson to everyone. :eek:

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. :D

I'll trade ya some spaghetti for some of that crow:)

Darrel Taylor
- 22nd March 2007, 20:12
Spaghetti sounds good.

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

Charles Linquis
- 23rd March 2007, 00:26
Hey! Who put that picture on my post! Strangely enough, it DOES look a little like me.

ImAnEE
- 4th May 2012, 23:10
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