Going to the start of loop after an Interrupt

Hello,

I went jump to the loop() so the program starts from de beginning after an software interrupt.
( Arduino DUE )

The program I have added does not works.

Please a tip what I need to change so that it works.

Thanks in advance,

Leen

#include <DueTimer.h>

volatile byte state = LOW;

int LED_1 = 41;
int LED_2 = 53;

void setup() {
pinMode(LED_1,OUTPUT);
pinMode(LED_2,OUTPUT);

Timer3.attachInterrupt(MSec).start(1000); // Every ms
}

void(* resetFunc) (void) = 0; // Declare reset function @ address 0

void loop() {

digitalWrite(LED_2, HIGH); // Short pulse

while (1){
digitalWrite(LED_2, LOW); // Reset pulse
}
}
void MSec(){
state = !state;
digitalWrite(LED_1, state);

resetFunc(); // Return to loop
}

An interrupt returns to the position the program was at when it was called . If you return elsewhere you are likely to have problems caused by incompleted routines . Not good practice and can’t see why you would want to do that.
You could set a flag in the interrupt service routine and check for that on exit , and not preform any further actions in loop ( by checking if the flag is set) until you again reach the top of loop , where you reset the flag.

No idea what’s wrong with the rest of it... looks a bit odd tho

This does not "return to loop", it reboots the Arduino.

   resetFunc();                     //   Return to loop

If you leave out the while {}, the loop function will exit and immediately be reentered.

Please use code tags when posting code ("</>" editor button).

Hello,

This program is only to test the jump back from the interrupt to first step of program code.

Thanks for the information.

Leen