View previous topic :: View next topic |
Author |
Message |
pgaastra
Joined: 05 Jan 2004 Posts: 17 Location: hamilton, NEW ZEALAND
|
write_eeprom() causing reset. |
Posted: Mon Jan 17, 2005 7:59 pm |
|
|
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
|
|
Posted: Mon Jan 17, 2005 8:07 pm |
|
|
Post your code... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
pgaastra
Joined: 05 Jan 2004 Posts: 17 Location: hamilton, NEW ZEALAND
|
|
Posted: Tue Jan 18, 2005 12:56 pm |
|
|
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
|
|
Posted: Tue Jan 18, 2005 2:25 pm |
|
|
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
|
|
Posted: Tue Jan 18, 2005 4:04 pm |
|
|
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
|
|
Posted: Wed Jan 19, 2005 8:01 pm |
|
|
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. |
|
|
|