Is there a way in which I can run a segment of code or perhaps a function, finish that segment or function then go into the interrupt routine immediately after if the interrupt is triggered in the middle of the function?
I have several critical functions that run in the main loop which use values from sensors in which I read from the sensors only when PCINTx is triggered. However if the interrupt occurs while the processor is in the middle of a function, jumps out of the function and back in, it will not give me the desired value if the function running is using values from the sensor that triggerd the interrupt as they may change mid process. What I want is for the function to finish and then immediately enter the interrupt after completion if the interrupt occurs while running the function.
I have no idea how to do this. The only thing I know is that I can disable and enable interrupt service to ensure the function is completed without values being changed externally before its finished using cli(); an d sei();. But if I do that I may miss the new value to be read if the interrupt should occur during that time . Only thing I can think of is if there is an interrupt flag that I can read even if the interrupt is disabled to check after completion of each function and then enter the interrupt if the flag is set(or what ever value indicates an pin has changed value and the interrupt should have been triggered).