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 CCS Technical Support

Write Program EEPROM Question

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



Joined: 05 Aug 2006
Posts: 149
Location: Redditch, UK

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

Write Program EEPROM Question
PostPosted: Wed Feb 14, 2007 11:44 pm     Reply with quote

I am using write_program_eeprom() as shown below to write a 4 byte unique ID number into memory (they are actually written as RETLW's to patch the code). I am sometimes seeing a corruption problem with the values when I check them by reading the chip back with my ICD or a bit of dump code.

I have a TIMER0 interrupt running will this be causing the problem ? I thought I had seen here somewhere that internally the function disables interrrupts while it does its writes. Is this true or should I always use the GLOBAL enable/disable interrupt around the write function ?

Now I am using PCM v3.249 with the 16F876A (therefore getenv(“FLASH_ERASE_SIZE”) = (“FLASH_WRITE_SIZE”)) and so the write_program_eeprom() should be erasing the two byte value before it writes.

Code:


#define ROM_UID_BASE   0x1FF7
#define   RETLW_INST      0x3400

void writeEepromUid(uint16 adr, uint16 *dat)
{
   int i ;
   for (i = 0 ; i < 4 ; i++, adr++) {
      write_program_eeprom (adr, dat[i]) ;
      delay_us(50) ;
   }
}

void BuildEepromUid(uint32 val, uint16 *dat)
{
   int i ;
   uint8 b ;

   for (i = 0 ; i < 4 ; i++) {
      b = val & 0x000000FF ;
      // Use RETLW instruction (3400 = 00)
      dat[i] = RETLW_INST | b ;
      val >>= 8 ;
   }
}

.....the bits from main........

uint16 uid_dat[4] ;
uint32 val32 ;

if (change) {
   BuildEepromUid(val32, uid_dat) ;
   writeEepromUid(ROM_UID_BASE, uid_dat) ;
   printf(myputc, "New UID Set\r\n") ;

} else {
   printf(myputc, "No change made\r\n") ;
}



Last edited by nurquhar on Thu Feb 15, 2007 1:36 am; edited 3 times in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 15, 2007 12:41 am     Reply with quote

Your posted code is corrupted because you didn't disable HTML.
Please edit your post and paste in a fresh copy of the code.
Then select the tickbox just below the posting window to disable
HTML before pressing the Submit button.
nurquhar



Joined: 05 Aug 2006
Posts: 149
Location: Redditch, UK

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

PostPosted: Thu Feb 15, 2007 1:19 am     Reply with quote

It looked ok when I previed it. However I have re-posted the code and and disabled HTML as you suggested.
Regards
Neil
Got any perls of wisdom on write_program_eeprom() ?
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