Void(* resetFunc) (void) = 0; with Nano Every

Hello,
I swapped a "Classic" Nano for a Nano Every. Everything works great and everything is compatible except the function :

void(* resetFunc) (void) = 0;

I was using it to "reboot" the micro-controller, but this seems to freeze the Every more than anything else.
The function no longer works with Every? Is there another function I can use to achieve the same result?
Thank you !!!

That's a srsly ridiculous way to accomplish something that can, without a scintilla of an iota of a fraction of doubt be done with regular straightforward code that would work on any Arduino board.

Post your code and get some help.

a7

I don't have one but you can probably use the watchdog to reset

include this in your code #include <avr/wdt.h>

and have a

void resetFunc() {
  wdt_enable(WDT_PERIOD_8KCLK_gc); // 8 ms watchdog 
 while(true); // infinite loop without feeding the dog, should reset in 8ms
}

Agree. Write good code and you won't need to resort to a hack like that.

depends how it's used. It's not unheard of that system auto-reboot in case of unrecoverable error (like on ESP the heavy use of the String class by some libraries could overtime lead to challenges)

Try this How to Soft Reset [code snippet]

J-M-L
Eventually it will work. I reduced the reaction time with WDTO_500MS. I inserted in my interrupt myDFPlayer.stop(); When the user presses the red button (reset), the device returns to the start and if an mp3 file is playing, the function myDFPlayer.stop(); stop it.

Thank you for your reply !!!

Hello alto777
I am not an experienced programmer. Rather a beginner. I learn little by little.
I used the function

void(* resetFunc) (void) = 0;

in an Interrupt to "reboot" the device.
I made a box with 4 buttons. 3 blue buttons are used to play 3 mp3 tracks. But if the user leaves after track 2, I want the new user to be able to start from the beginning. Then, by pressing the 4th button, the red one [= Interrupt + resetFunc ], the device "restarts" and starts all over again. Here is an example of my code...

const byte buttonInterrupt = 2;
const byte buttonPlay1 = 3;
const byte buttonPlay2 = 4;
const byte buttonPlay3 = 5;

void setup() {
  Serial.begin(9600);

  pinMode(buttonInterrupt, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(buttonInterrupt), myISR_2, LOW);

  pinMode(buttonPlay1, INPUT_PULLUP);
  pinMode(buttonPlay2, INPUT_PULLUP);
  pinMode(buttonPlay3, INPUT_PULLUP);

  Serial.print("Play mp3 Intro");
}
void(* resetFunc) (void) = 0;

void loop() {
  while (digitalRead(buttonPlay1) == HIGH) ;
  Serial.print("Play mp3 #1");

  while (digitalRead(buttonPlay2) == HIGH) ;
  Serial.print("Play mp3 #2");

  while (digitalRead(buttonPlay3) == HIGH) ;
  Serial.print("Play mp3 #3");
}

void myISR_2() {
  resetFunc();
}

the module is probably not receiving a hardware reset.

good you found a workaround !
have fun

That hack assumes the reset vector for the processor is located at address 0. For MANY processors that is incorrect. I have no clue what it is for the processor in question, but very likely it is one that has the reset vector located somewhere other than address 0.

And, that does NOT do an actual reset! The hardware almost certainly does NOT get reset, it simply attempts to re-start the software, which may, or may not, be reliable. Often, with that approach, an interrupt occurring at the wrong point during the re-initialization of the software will cause a crash, or memory corruption. It is a really lousy way to fake a reset.

it works on Nano Every

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.