With the example sketch: ds1307 (RTCLib) "installed" in the Arduino Mega, after i send one time with this line uncommented:
rtc.adjust(DateTime(2019, 5, 13, 22, 35, 0));
and comment this line sending from the second time, when i reset the arduino (pressing the red button on it) the time seens to work fine. BUT when i disconnect the USB cable, the date/time resets and i receive the message "rtc not running".
//writeNVRAM(0x00, B00000000);//enable oscillator and set seconds to 0
//writeNVRAM(0x00, B10000000);//disable oscillator set CH bit
for (int a = startRegister; a <= endRegister; a++)
{
byte b = readNVRAM(a);
Serial.print("0X");
if (a < 16)
Serial.print("0");
Serial.print(a, HEX);
Serial.print("\t");
Serial.print("\t");
for (int i = 7; i >= 0; i-- )
{
Serial.print((b >> i) & 0X01);//shift and select first bit
}
Serial.println();
}
}
void writeNVRAM(byte location, byte data)
// writes data to DS1307 NVRAM location
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(location);
Wire.write(data);
Wire.endTransmission();
}
byte readNVRAM(byte location)//// reads data from DS1307 NVRAM location
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(location);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 1);
return Wire.read();
}
The more I experiment with my DS1307 I am convinced that your experience looks like there is no battery. You have measured voltage on the battery you have installed, but the battery holder may be defective or the module board. Can you verify that the battery voltage is seen at the Vbat pin of the chip. You will need to look at a data sheet for the device. https://datasheets.maximintegrated.com/en/ds/DS1307.pdf
cattledog:
The more I experiment with my DS1307 I am convinced that your experience looks like there is no battery. You have measured voltage on the battery you have installed, but the battery holder may be defective or the module board. Can you verify that the battery voltage is seen at the Vbat pin of the chip. You will need to look at a data sheet for the device. https://datasheets.maximintegrated.com/en/ds/DS1307.pdf
Battery is ok, i measured with multimeter. But i'm making some tests here and get this point: I removed the "BAT" wire (connected from RTC pin bat to AnalogIn) and now even removing the USB, the date/time is not lost anymore.
Maybe the bat pin is problematic ?
EDIT----
Yeah, i've made so many tests here, and when i connect some to analogPin to know what is the batt voltage, the data/time is lost.
I removed the "BAT" wire (connected from RTC pin bat to AnalogIn) and now even removing the USB, the date/time is not lost anymore.
Maybe the bat pin is problematic ?
Use a high value resistor between +battery and A0.
Something like 1Megohm.
Add a 100n cap from A0 to ground for stable readings.
It's very unusual for the Vbat pin to be connected to anything. Many modules don't even have this output broken out.
Post the complete sketch you're using and a wiring diagram of your setup!
I did not realize that connection between Vbat and A0. The wiring diagram asked for may have helped us move along quicker.