RTC_DS1307 now() blocks my interruptions (MsTimer2)

Hello.

I'm currently doing a project (a clock) with an Arduino and a RTC DS1307 (mainly), but I have some problems putting everything together.

I'm using MsTimer2 to create interruptions every 5 seconds, to request the time from the RTC.
But the function rtc.now() seems to lock the interruption. It works fine if I use rtc.now() in the main loop with a delay, but it's active delay (which I try to avoid).

Here is my code :

#include <Wire.h>
#include <RTClib.h>
#include <MsTimer2.h>

RTC_DS1307 rtc;

void setup() {
  #ifndef ESP8266
      while (!Serial); // for Leonardo/Micro/Zero
  #endif
    
  Serial.begin(57600);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
  
  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
  
  rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  now = rtc.now();

  init_interrupt();
}

void loop() {
  // This works, but with active delay
  /*DateTime now = rtc.now();
  Serial.print(now.second(), DEC);
  Serial.println();
  delay(5000);*/
}

void init_interrupt(){
  MsTimer2::set(1000, callback); // 5s period
  MsTimer2::start();
}

void callback(){
  // Here it doesn't work
  now = rtc.now();
  Serial.print("callback ");
  Serial.print(now.second());
  Serial.println();
}

I don't know what I'm missing. Is it possible that rtc.now() must be synchroneous ? (therefore not working in a interruption). What can I do to make it work ?

Thank you for your help.
Lothigo.

I'm using MsTimer2 to create interruptions every 5 seconds, to request the time from the RTC.

Why? It is perfectly OK to ask the RTC for the time on every pass through loop().

Is it possible that rtc.now() must be synchroneous ? (therefore not working in a interruption).

Communication with the RTC is via I2C which is interrupt-driven. So, you can't get the time from the RTC in an ISR.

PaulS:
Why? It is perfectly OK to ask the RTC for the time on every pass through loop().

In my mind, calling the RTC in loop() will use more power than from interruption. Seems not the case.

PaulS:
Communication with the RTC is via I2C which is interrupt-driven. So, you can't get the time from the RTC in an ISR.

That's what I thought. So I will use the loop() to get the time from RTC.

Thank you for your help.

In my mind, calling the RTC in loop() will use more power than from interruption. Seems not the case.

The Arduino is running flat out, 100 % CPU usage, all the time. Whether the code that it is executing is in an ISR, or not, makes no difference.

The TimeLib library already provides a non-interrupt based mechanism to sync the time that the library knows with the time from the RTC. Perhaps a better option than reading data from the RTC on every pass through loop().