Assume that the condition is satisfied for an interrupt to occur and interrupt is enabled along with I bit. What will happen if ISR is not written? Is the behavior is undefined or ISR will just return without executing?
I one of my program, I observed strange behavior. In the outline code given below, I had forgot to implement ISR(PCINT2_vect). Because of that code was getting executed until while(!flag) and it was waiting for the flag to set; but then rest of the code was getting skipped. I was trying to use PCINT2 interrupt, but forgot to implement. I was expecting endless wait because flag was not getting set inside ISR, but while(1) was getting entered again and again
while(1) { //Implement first Part while(!flag); // Implement second part } inline void commonCode(void) { // some code here common to all ISRs } ISR(PCINT0_vect) { flag=1; commonCode(); } ISR(PCINT1_vect) { flag=1; commonCode(); } ISR(PCINT2_vect) { flag=1; commonCode(); }
Secondly, if I have some common code to be executed by ISR, is it OK to write an inline function and call it from ISR like the one shown above?