PIC18 ISR uses access RAM locations used by main functions and causing corruption
I've been reading and benefiting from advice on this forum for ages but never needed to post a query until now.
I'm using a PIC18F67J94 and developing code in C within MPLAB IDE v5.15 and XC8 compiler v2.05. I've been developing the code for some time now and generally it's been working well until recently when I came upon an issue with my interrupt service routine causing corruption in the main program. I've scoured this forum and others, and consulted the XC8 manual, looking for an answer to the problem but I can't seem to crack it.
The problem seems to be, in a nutshell, that the compiler allocates access RAM locations for temporary variables in the ISR which are also shared with temporary variables in the main functions. So as the program jumps to the ISR and then returns from it, those temporary variables in the main functions are (sometimes) corrupted. It's almost as though the compiler doesn't recognise that the ISR is an interrupt and therefore doesn't try to ring-fence RAM storage for temporary variables away from the rest of the program. However that's not the case - it's clear from the assembly list output that the ISR is recognised and, functionally, the ISR is called at the right times. For information, I'm using in legacy mode (interrupt priorities disabled) and declaring the ISR as "interrupt".
Now this has only happened fairly recently so I'm trying to back-track to find out what it is I may have done to cause this problem. I haven't included code here as it's fairly large and I though I'd start by checking principles to see if I have potentially mis-declared something or else made some other type of schoolboy error.
So if anyone has a few suggestions of things I might check, it would be much appreciated!