DFR0151 RTC not keeping time

Hello,
I have a Gravity DFR0151 RTC that I have connected to a DFRobot Nano which is on a I/O Nano Shield. I am able to set the time and record the time onto a datalogger, however, after a period of time the clock resets itself.
I have new battery. I have been switching the #define updata_flag 0 //1 updata time,0 only show time
Is the DFR0151 compatible with the Nano? Is the problem that it is getting 3.3V but needs 5V?
I don't understand why it works sometimes and not others.
Any help appreciated.
This is the RTC part of my code:
//Datalogger
#define SPIN 6 //Connect to the module Pin S, trigger to save files at low level
uint16_t i = 0;
//RTC
#include <DFRobot_DS1307.h>
//Note: #define updata_flag 0 //1 updata time,0 only show time
#define updata_flag 0 //1
DFRobot_DS1307 DS1307;
}
void setup() {
//Datalogger
Serial.begin(115200);
delay(2000); //To aviod data lost, delay a period of time to wait for the module to start
pinMode(SPIN, OUTPUT);
digitalWrite(SPIN, HIGH);
//RTC
//Serial.begin(115200);
// Initialize sensor
while (!(DS1307.begin())) {
Serial.println("Communication with device failed, please check connection");
delay(3000);
}
DS1307.start();
DS1307.setSqwPinMode(DS1307.eSquareWave_1Hz);
Serial.print("Time");
Serial.print(",");
Serial.print("Date");
Serial.print(",");
delay(100);
}
void loop() {
Serial.print(DS1307.getTypeTime(DS1307.eHR));
Serial.print(":");
Serial.print(DS1307.getTypeTime(DS1307.eMIN));
Serial.print(":");
Serial.print(DS1307.getTypeTime(DS1307.eSEC));
Serial.print(",");
Serial.print(DS1307.getTypeTime(DS1307.eMTH));
Serial.print("/");
Serial.print(DS1307.getTypeTime(DS1307.eDATE));
Serial.print("/");
Serial.print(DS1307.getTypeTime(DS1307.eYR));
Serial.print(",");
delay(1000);
}
