|
|
View previous topic :: View next topic |
Author |
Message |
Trampas
Joined: 04 Sep 2004 Posts: 89 Location: NC
|
Writing to program memory.... |
Posted: Mon Oct 25, 2004 7:24 am |
|
|
I am trying to get a boot loader working. I am writting my own write to program memory function as that the CCS function is not truely inline, it actually calls a subroutine. I am working with the 18F series parts if it makes a difference. So far here is my code but it does not appear to work...
Code: |
UBYTE PgmFlash(UDWORD address, UBYTE *data) //8 bytes
{
UBYTE i;
TBLPTRU=(UBYTE)(address>>16);
TBLPTRH=(UBYTE)(address>>8);
TBLPTRL=(UBYTE)(address);
for(i=0; i<8; i++)
{
TABLAT=data[i];
#asm
TBLWT+*
#endasm
}
disable_interrupts(GLOBAL);
#asm
BCF EECON1, 4//FREE // disable Row Erase operation
BSF EECON1, 7 //EEPGD //point to Flash program memory
BCF EECON1, 6//CFGS //access Flash program memory
BSF EECON1, 2//WREN // enable write to memory
MOVLW 0x55
MOVWF EECON2 // write 55h
MOVLW 0xAA
MOVWF EECON2 // write 0AAh
BSF EECON1, 1 //WR //start erase (CPU stall)
NOP
#endasm
return 0;
}
|
Does anyone have an idea why the code does not work? By the way the address is on a 8 byte boundry...
Trampas |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Mon Oct 25, 2004 7:50 am |
|
|
Looks ok. A couple of comments. When finished you did not disable the write enable
you have disable global interrupts but not re-enabled them. It might be better if you copy the current interrupt status, disable interrupts, execute your code then restore the current interrupt status.
Do you have the WDT enabled? If so you should add a reset wdt in the programming loop.
Try testing your code writing to a fixed target address instead of passing the target address |
|
|
Trampas
Joined: 04 Sep 2004 Posts: 89 Location: NC
|
|
Posted: Mon Oct 25, 2004 8:13 am |
|
|
OK with a little work I figured it out...
I had two major problems, first was I needed to predecrement the TBLPTR, second was the TBLPTR incremented and the program was happening 8 bytes off from where I wanted. Here is the code that works for other poor suckers like me...
UBYTE PgmFlash(UDWORD address, UBYTE *data) //8 bytes
{
UBYTE i;
TBLPTRU=(UBYTE)(address>>16);
TBLPTRH=(UBYTE)(address>>8);
TBLPTRL=(UBYTE)(address);
#asm
TBLRD*- //dummy read to decrement
#endasm
for(i=0; i<8; i++)
{
//printf("%x ",data[i]);
TABLAT=data[i];
#asm
TBLWT+*
#endasm
}
TBLPTRU=(UBYTE)(address>>16);
TBLPTRH=(UBYTE)(address>>8);
TBLPTRL=(UBYTE)(address);
disable_interrupts(GLOBAL);
#asm
BCF EECON1, 4//FREE // disable Row Erase operation
BSF EECON1, 7 //EEPGD //point to Flash program memory
BCF EECON1, 6//CFGS //access Flash program memory
BSF EECON1, 2//WREN // enable write to memory
MOVLW 0x55
MOVWF EECON2 // write 55h
MOVLW 0xAA
MOVWF EECON2 // write 0AAh
BSF EECON1, 1 //WR //start erase (CPU stall)
NOP
BCF EECON1, 2//WREN
#endasm
return 0;
} |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|