Factory Default
Factory Default
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.
- 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
Hello
Which memory locations have you overwritten? was it the osccon register or something similar?
Which memory locations have you overwritten? was it the osccon register or something similar?
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Factory Default
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.
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.
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Factory Default
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.
Re: Factory Default
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.
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.