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_eeprom() causing reset.

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



Joined: 05 Jan 2004
Posts: 17
Location: hamilton, NEW ZEALAND

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

write_eeprom() causing reset.
PostPosted: Mon Jan 17, 2005 7:59 pm     Reply with quote

I have a PIC16LF84 running on a 3V battery and a 32.768kHz crystal

I have written some code which writes to 8 places in eeprom using the CCS pic c compiler write_eeprom() function. I have no watchdog enabled.

Somehow 5 seconds after the calls to this function the PIC resets and runs the code from the start.

Has any one any ideas why this might be happening?
Haplo



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

View user's profile Send private message

PostPosted: Mon Jan 17, 2005 8:07 pm     Reply with quote

Post your code...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 17, 2005 8:33 pm     Reply with quote

In addition to posting your code, you should also post the version
of your compiler. Some older versions had problems:
http://www.ccsinfo.com/forum/viewtopic.php?t=16314
pgaastra



Joined: 05 Jan 2004
Posts: 17
Location: hamilton, NEW ZEALAND

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

PostPosted: Tue Jan 18, 2005 12:56 pm     Reply with quote

Thanks for that reply PCM Programmer.

I had a look at the thread you pointed out. I am not using interrupts. I am using timer 0.

I am using CCS PCM version 2.731. It does save the INTCON and get it back after doing the write eeprom. The routine with the write_eeprom is this:

Code:

void GetParameters(void){
   int IncomingChar = '\0';
   
   
   unsigned Data;
   int ByteCount;
   //int ReceivedInt;
   int EepromAddress;
   int ByteArray[NUMBERBYTEPARAMS];

   


   // LabVIEW application sends raw hex instead of ASCII string of number
   IncomingChar = getc300();               // high byte of LogStartDelay   
   LogStartDelay = (long)IncomingChar*256;  //   
   putchar(IncomingChar);
 
   IncomingChar = getc300();               // lo byte of LogStartDelay
   LogStartDelay = LogStartDelay + (long)IncomingChar;
   putchar(IncomingChar);

   // reading the characters into any array first because writing to eeprom takes forever.

   for(ByteCount = 0 ; ByteCount < NUMBERBYTEPARAMS; ByteCount++){
     ByteArray[ByteCount] = getc300();     
     putchar(ByteArray[ByteCount]);
   }

   //while(1);  // debugging

   EepromAddress = ByteSizedParameterStartAddress;
        write_eeprom(EepromAddress,0);
/*   for(ByteCount = 0 ; ByteCount < NUMBERBYTEPARAMS; ByteCount++){
     
     data = ByteArray[ByteCount];

    // disable_interrupts(global);  // clutching at straws.  the following write_eeprom() line is causing the chip to reset.
     write_eeprom(EepromAddress,data);
    // enable_interrupts(global);
     delayms(2); //Somehow this short delay makes it work.
     EepromAddress++;

 
   }
*/
   
   LogInterval = ByteArray[0];
   MovingThreshold = ByteArray[1];

}



Some of the comments are from different tries at debugging.

If I comment out the write_eeprom(EepromAddress,0); line I get no resets.

It's when it has got out of this routine, and done some more things that the PIC resets.

I have written a bare bones program and called write_eeprom() from main and I have no reset. I will keep on putting things in till it crashes.[/code][/quote]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jan 18, 2005 2:25 pm     Reply with quote

First thing, check your stack usage. It's given near the top of
your .LST file. Compile with code that's known to fail, and then
check the number of stack locations reported used.
pgaastra



Joined: 05 Jan 2004
Posts: 17
Location: hamilton, NEW ZEALAND

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

PostPosted: Tue Jan 18, 2005 4:04 pm     Reply with quote

Code that doesn't work has stack height of 4.

I've been diverted from this job for a while. I'll try to narrow down the problem to see what's wrong before wasting any more of everyone's time.

Thanks
pgaastra



Joined: 05 Jan 2004
Posts: 17
Location: hamilton, NEW ZEALAND

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

PostPosted: Wed Jan 19, 2005 8:01 pm     Reply with quote

I found the problem. Somehow that write_eeprom must not have deal with the interupt control register properly. I just added:

disable_interrupts(global) after my write_eeprom and no more resets.

I don't think it was acutally resetting but because I wasn't using interrupts location 0004 (the start of interrupt servicing) was being used for normal code. I don't know what was causing the jump to the interrupt.

Sorry but I'm a pretty woolly programmer.
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