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

PIC18F1320 write_rogram_eeprom problem

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



Joined: 29 Dec 2003
Posts: 81

View user's profile Send private message

PIC18F1320 write_rogram_eeprom problem
PostPosted: Thu Aug 12, 2004 2:03 am     Reply with quote

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








PostPosted: Thu Aug 12, 2004 2:26 am     Reply with quote

I suggest you erased first then write a new data to the program memory...

Hope this helps...
garyzheng



Joined: 22 Jul 2004
Posts: 25

View user's profile Send private message

two consideration:)
PostPosted: Thu Aug 12, 2004 10:00 am     Reply with quote

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 0Smile

2. maybe you can check the assemble list to see whether the procession is under your control.
chingB



Joined: 29 Dec 2003
Posts: 81

View user's profile Send private message

PostPosted: Thu Aug 12, 2004 6:23 pm     Reply with quote

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...
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