View previous topic :: View next topic |
Author |
Message |
chingB
Joined: 29 Dec 2003 Posts: 81
|
PIC18F1320 write_rogram_eeprom problem |
Posted: Thu Aug 12, 2004 2:03 am |
|
|
I need your help on the problem I encountered....
Code: |
romCheck = read_program_eeprom(0x1FF4);
if (romCheck != 0xA0A0){
disable_interrupts(global);
write_program_eeprom(0x1FF4,0xA0A0); // write 0xA0A0
#asm nop #endasm
delay_ms(100);
write_program_eeprom(0x1FF0,GADGETID); // write the MP device address
#asm nop #endasm
delay_ms(100);
enable_interrupts(global);
}
// get slave address for this device
macAddr = read_program_eeprom(0x1FF0);
#asm nop #endasm
|
the code above is located at my main program and it store the correct device address.
The code below is a routine that will change the content stored on location 0x1FF0 to a new macAddr.... via serial interrupt....
Code: |
void allocateSlaveAddr() // set a new slave address for this device
{
unsigned int16 newAddr;
newAddr = asciiHex2int16(9); // get the new slave address
if (rcvAddr != 0x00){
if ((newAddr != 0x00) && (newAddr != macAddr)){
// write the slave address to program eeprom
write_program_eeprom(0x1FF0,newAddr);
macAddr = newAddr; // update macAddr to reflect new
// slave address
TXAck(); // send acknowledge
}
}
}
|
This code above will only be executed if the PC Host sends a command that will allocate a new device address but unfortunately, it does not reflect the new address when I added a code that will display to serial monitor the previous device address and the current device address.. with this the two does not match...
Are their any special procedure that u need to follow before you can update the content of the program eeprom?
BTW, I am using PIC18F1320 at 20MHz with PCWH v3.188.
I need your suggestions and help on this....
Thank u. |
|
|
Guest
|
|
Posted: Thu Aug 12, 2004 2:26 am |
|
|
I suggest you erased first then write a new data to the program memory...
Hope this helps... |
|
|
garyzheng
Joined: 22 Jul 2004 Posts: 25
|
two consideration:) |
Posted: Thu Aug 12, 2004 10:00 am |
|
|
1. check the OERR of RCSTA register, if you use baudrate=9600, maybe the speed of RS232 transmission will more faster than the data writing procession for EEprom, although you will think that you had disable the global interrupt, but this situation still happen. if OERR=1, you can clear and set CREN flag to reset the OERR flag to 0
2. maybe you can check the assemble list to see whether the procession is under your control. |
|
|
chingB
Joined: 29 Dec 2003 Posts: 81
|
|
Posted: Thu Aug 12, 2004 6:23 pm |
|
|
Thanx for d reply....
I solve the problem by using the built-in function of CCS which the erase_program_eeprom()...
dis does the trick... |
|
|
|