Trying to Reset Arduino NANO 33 IoT programatically

Hi, I have tried some different approaches seen online and in Arduino Forums with no success..
I have tried the

int led = 13;

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

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
  Serial.begin(115200);//initialize the serial port
}



// the loop routine runs over and over again forever:
void loop() {
  //digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  Serial.println("on");
  delay(10000);               // wait for 10 seconds

  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  Serial.println("off");
  delay(5000);               // wait for  5 seconds
  Serial.println("resetting again");
  resetFunc();  //call reset
  
  delay(100);
  Serial.println("never happens");
}

I was expecting the Arduino to reset time after time .. It just stops.
The same with this other approach

int led = 13;
#define HMCRAMC0_SIZE     0x8000UL
#define HMCRAMC0_ADDR    (0x20000000U)
#define MAGIC_VALUE         0x07738135U

void ResetToBoot()
{
    Serial.println("rebooting Now");
    *((volatile uint32_t *)(HMCRAMC0_ADDR + HMCRAMC0_SIZE - 4)) = MAGIC_VALUE;
    NVIC_SystemReset();
    Serial.println("rebooted Not");
}
// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
  Serial.begin(115200);//initialize the serial port
}

// the loop routine runs over and over again forever:
void loop() {
  //digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  Serial.println("on");
  delay(10000);               // wait for 10 seconds

  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  Serial.println("off");
  delay(5000);               // wait for 5 seconds
  Serial.println("resetting again");
  ResetToBoot();  //call reset
  
  delay(100);
  Serial.println("never happens");
}

as planned the Serial.println("rebooted Not") in Reset To Boot function is never triggered
and neither is the Serial.println("never happens").
The Arduino just stops working until it is restarted manually..
Has anybody any working solution to this or any insights in how to get the Arduino NANO to perform a proper reboot from Code.

Hi pelago,

To reset the Nano 33 IoT and restart your sketch, you just need to use the line:

NVIC_SystemReset();                         // Reset the microcontroller

By the way, the code in your second example resets the board, but places the microcontroller into bootloader mode, (simulating a double tap reset).

Thank you MartinL for the clarification. Now i get it to work properly.

:slight_smile:

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