Frequently Asked Questions

Why do I get a 'Interrupts disabled to prevent re-entrancy' warning?


Due to the limited hardware stack of the PIC a limitation of the CCS compiler is the disability to use recursion in functions. This drawback will affect customers if they try to call a function in an interrupt that is also called outside of an interrupt. When you see this warning message, the compiler is letting you know that you are calling a function inside an interrupt that is also called outside of the interrupt. To prevent accidental recursion the compiler will disable interrupts when you call that specific function outside of that interrupt.


Review the following code:


void ISR_RDA(void)

void SomeFunc(void)


As you see in the above example StuffByte() is called inside the interrupt, and also inside SomeFunc(). If StuffByte() was executing and an interrupt occured, this would cause all scratch and registers modifyed by StuffByte() to be corrupted when it returns to SomeFunc().


Here are some work-arounds:

  • Make StuffByte() inline using the #inline pre-processor command.

  • Copy StuffByte() into a new function, called StuffByteISR(), and call this new function in the ISR.


Both workarounds work because you created two instances of StuffByte() in code, so if the ISR happens while you are inside StuffByte() the program will not recursively call the same code.

C-Aware IDE Demo
Embedded C Learners Kit
C Workshop Compiler