CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Writing to program memory....

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Trampas



Joined: 04 Sep 2004
Posts: 89
Location: NC

View user's profile Send private message MSN Messenger

Writing to program memory....
PostPosted: Mon Oct 25, 2004 7:24 am     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Mon Oct 25, 2004 7:50 am     Reply with quote

Looks ok. A couple of comments. When finished you did not disable the write enable
Code:
   bcf   EECON1, WREN


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

View user's profile Send private message MSN Messenger

PostPosted: Mon Oct 25, 2004 8:13 am     Reply with quote

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;
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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