View previous topic :: View next topic |
Author |
Message |
nurquhar
Joined: 05 Aug 2006 Posts: 149 Location: Redditch, UK
|
Write Program EEPROM Question |
Posted: Wed Feb 14, 2007 11:44 pm |
|
|
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
|
|
Posted: Thu Feb 15, 2007 12:41 am |
|
|
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
|
|
Posted: Thu Feb 15, 2007 1:19 am |
|
|
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() ? |
|
|
|