bug? in setup()

void setup() {
  [ Specific non essential other code ]
  
  newLogFile();                                         
}


void newLogFile()
{
  sprintf(name, "%04d%02d%02d.CSV", year(), month(), day());
  fileWrite.open(root, name, O_CREAT | O_APPEND | O_WRITE);

  if (!fileWrite.isOpen()) {
    error ("file create failed ",5);
  }
  Serial.println("Logging to: " + String(name));
}


void loop()
{
  [ Specific non essential other code ]
 
  if ( hour() == 0 && minute() == 0 ) {
   
    newLogFile();
  } 
}

When I use the above code setup() is rerun on 00:00! :-?

when I rewrite setup() to initialize the first filepointer to this it works :o

void setup() {
  [ Specific non essential other code ]
  
 sprintf(name, "%04d%02d%02d.CSV", year(), month(), day());
  fileWrite.open(root, name, O_CREAT | O_APPEND | O_WRITE);

  if (!fileWrite.isOpen()) {
    error ("file create failed ",5);
  }
  Serial.println("Logging to: " + String(name));
                                        
}

If you post the ENTIRE Sketch (please use code tags), you'll get more / better answers.

when I rewrite setup() to initialize the first filepointer to this it works

Perhaps you would be so kind as to highlight the differences that cause the different behavior. I can't see anything different.

Of course, I don't understand exactly what your problem is, or what you need help with.

sorry for the missing code tags :slight_smile:

the other code is for the question really non essential

@paulS

the difference is in the first setup() I call the newLogFile routine (initializing the filepointer) in the second setup (works) I initialize the (same) pointer in the setup routine.

and the error I got was: when the newLogFile() routine was recalled (at 00:00) the board was reset (setup is rerun)

the other code is for the question really non essential

That really is not for you to decide. The name variable you are sprintf'ing into is undefined. The year(), month(), and day() functions are undefined. The presence/absence of Serial.print() statements in setup() and loop() is impossible to determine.

There are so many possibilities where the error could be occurring that not posting all the code makes it impossible to help you.

Good luck.

As Paul points out the error is NOT in the code you've shown. I'd suspect, from the little you've said, that something totally unexpected is happening--stack overflow or otherwise a buffer overflowing and overwriting the location in RAM where millis are stored.

Guys thanks for the help, while writing the proof of concept I found my error... (I was recalling the newLogFile routine while the fp was being closed)
Sorry guys for being so cryptic but during my daytime job I would be flamed for posting all code :o