Factory Default

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
jcooper
Posts: 23
Joined: Tue Jul 08, 2008 7:29 pm
Contact:

Factory Default

Post 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.
No trees were harmed in the posting of this message. However, a large number of electrons were terribly inconvenienced.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Factory Default

Post by Benj »

Hello

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

jcooper
Posts: 23
Joined: Tue Jul 08, 2008 7:29 pm
Contact:

Re: Factory Default

Post 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.
No trees were harmed in the posting of this message. However, a large number of electrons were terribly inconvenienced.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Factory Default

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

jcooper
Posts: 23
Joined: Tue Jul 08, 2008 7:29 pm
Contact:

Re: Factory Default

Post 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.
No trees were harmed in the posting of this message. However, a large number of electrons were terribly inconvenienced.

jcooper
Posts: 23
Joined: Tue Jul 08, 2008 7:29 pm
Contact:

Re: Factory Default

Post 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.
No trees were harmed in the posting of this message. However, a large number of electrons were terribly inconvenienced.

Post Reply