Do not use lengthy code in an interrupt handler. Sending data over the UART is very slow compared to normal CPU speed.
Do not recurse in an interrupt handler. It is not quite clear due to some missing information if you do something like that.
Every global variable that is changed in an interrupt handler should be declared as "volatile". so you need
volatile uint8 flag = 0;
This will prevent you from compiler optimizing-out redundant accesses to the variable flag. See here.
Can you please post your complete project so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.
Can you address the issue with ref to attached code?