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

write program eeprom

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



Joined: 30 Oct 2003
Posts: 24
Location: skegness

View user's profile Send private message Visit poster's website

write program eeprom
PostPosted: Sun Jun 20, 2004 1:01 pm     Reply with quote

having dificulty writing to program eeprom
i have a routine that
reads the code space into a buffer
copies the bits needed to be updated into it
and then writes it back with write_program_eeprom
then loads the next block of code in to the buffer
and does so until all data is updated

if i make the buffer large enough for all the data in one hit it works wonderfull
if i make the buffer small, sections get erased and it is most confusing
i have tried 32 byte 64 byte both of which cause loss of data
but 128 ( big enough for one hit ) it works.

im using icd2 ccs 3.202 & 18f252 processor with 8mhz clock + PLL

anybody got any idea's.

the code is pretty simple, cant understand why it wont work.
( at my wits end )
lewis.
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Sun Jun 20, 2004 5:08 pm     Reply with quote

Post your code...
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Sun Jun 20, 2004 7:54 pm     Reply with quote

What your doing is very much like a boot loader. You may find some technics that work looking at the code that they use. I have never used a bootloader but that is how I would aproach the problem.
lewiseley



Joined: 30 Oct 2003
Posts: 24
Location: skegness

View user's profile Send private message Visit poster's website

ok heres my code
PostPosted: Wed Jun 23, 2004 12:11 pm     Reply with quote

// a routine to store a meter control block.


int8 store_mcb ( int8 *mccb )
{
int8 const bufsize=64;
int8 i,bnk,ctr,signal,written; //general purpose counter
int8 tempx[bufsize]; //temporary storage
int32 addr,adr,ending,starting; //address where it lives.
int32 add_spec;
//disable_interrupts(global);
i=mccb[0]; //search for this mcb
fetch_mcb( &tempx[0],i,addr); //fetch the last address
// we know have the addr of the last byte of any mcb's
// test for already existent mcb and abort if exist

if ( tempx[0]==mccb[0])
if (tempx[1]!=mccb[1]) //if they differ in size
return mcb_size_wrong; //sizes differ so exit

//although may already exist if sizes are same then ok to overwrite

read_program_memory(0x280,tempx,bufsize); //read in the first block.

starting=addr; //calculate the start address
ending=starting+mccb[1]; //calculate the end address
signal=0;
bnk=0;
tempx[0]++; // increase the number of defined blocks
written=1; //to cause the write back of new maxblocks
for ( adr=0x280;adr<0x400;adr++) // do for each byte of the address
{
signal=0; //default to no replacement
if ( adr>=starting)
signal=1;
if ( adr>ending)
signal=0; // turn off the copying process
if (signal==1)
{
tempx[(adr&(bufsize-1))]=mccb[adr-starting];
written=1;
} //end of signal

//-----------------------------------
if ( (adr&(bufsize-1))==(bufsize-1))
{ // now we write back the block and fetch the next one
if (written==1)
{
//add_spec=(0x280+(bnk*bufsize));
if (bnk==0)
write_program_memory(0x280,tempx,bufsize);
if (bnk==1)
write_program_memory(0x2c0,tempx,bufsize);
if (bnk==2)
write_program_memory(0x300,tempx,bufsize);
//write_program_memory(add_spec,tempx,bufsize); //write the bank in place
written=0;
}

bnk++; // inc bank number


//add_spec=0x280+(bnk*bufsize);
if (bnk==0)
read_program_memory(0x280,tempx,bufsize);
if (bnk==1)
read_program_memory(0x2c0,tempx,bufsize);
if (bnk==2)
read_program_memory(0x300,tempx,bufsize);
}
} // end of the for loop
// delay_ms(1000);
// enable_interrupts(global);
return ok;
} // end of store meter control block.


fetch_mcb just looks through memory and returns the address where it
already lives if updating or the next spare address to start writing at.
it should work, i have messed with it somewhat, but can not get it to work
as intended, i start writing from 0x280 i have a problem if i am trying to write over two blocks of 64, 0x2b0 .. 0x2c0 blocks, it seems to write the 0x2b0 block and and 0x2c0 block, but say - if the next address spare to write at ( the next time the routine is called ) say 0x2c8 the write from 0x2c8 onwards is o.k but the bytes from 0x2c0 .. 0x2c7 get turned into
0xff, and it shouldnt do that. the blocks that i write can vary in size, but forcing them to always be an even size makes no difference.

what do you think
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