Page 1 of 1

Factory Default

Posted: Fri Nov 07, 2008 12:27 am
by jcooper
I accidentally wrote over some memory locations that I shouldn't have, and now my chip doesn't work properly. Is there a way for me to get it back to factory default settings? The chip is a PIC18f258.

Re: Factory Default

Posted: Fri Nov 07, 2008 11:47 am
by Benj
Hello

Which memory locations have you overwritten? was it the osccon register or something similar?

Re: Factory Default

Posted: Fri Nov 07, 2008 5:16 pm
by jcooper
I'm not actually sure what it was. I think what happened was caused by running this code:
void Block_All_Msg(void){
unsigned far char *reg;
unsigned char i;
CANCON=0x80; //Put CAN Module in Configuration Mode
while(CANSTAT!=0x80); //Wait to make sure chip enters Config Mode
reg=&RXF0SIDH;
for(i=0;i<24;i++){ //Set all filter values to 0
*(reg+i)=0x00;
}
for(i=24;i<32;i++){
*(reg+i)=0xFF; //Set all mask values to 0xFF
}
CANCON = 0x00; //Request Normal Mode
while(CANSTAT&0xE0==0x00);
}

It's meant to block all incoming messages on the CAN bus, but I think that somehow the pointer arithmetic was wrong and the wrong location in memory got written. Thus proving how dangerous pointer arithmetic can be. :) Anyway, the program as a whole seems to work fine, except for the CAN receive, which for some reason doesn't work anymore, even though I specifially set all the masks back to zero. I'm not sure what else to try, at this point.

Re: Factory Default

Posted: Fri Nov 07, 2008 5:29 pm
by Benj
Hello

If the masks are set to 0 then is this maybe disabling all of the reception? Masks with a value of 1 normally allow the data to come through. Maybe this will help anyway. If it doesnt then keep me posted and I will have a bit of a better dig in.

Re: Factory Default

Posted: Fri Nov 07, 2008 5:48 pm
by jcooper
According to the datasheet, setting a mask bit to 0 means that it accepts any value, regardless of the filter setting. I think there's something else going on here, but I'm not sure what. How robust is the CAN receive? I was working it pretty hard yesterday.

Re: Factory Default

Posted: Fri Nov 07, 2008 9:29 pm
by jcooper
Hey Ben -

After a few hours of investigation, I figured out what was wrong. It had nothing to do with pointer arithmetic, just a little quirk in the filtering protocol that I hadn't noticed. :) Thanks for the tech support.