RTC "works" but won't display time

I’m having a little bit of trouble with an old DS3231 RTC on a Mega, which I think might be just a bad connection. It is just a test sending time to the serial monitor.

Everything worked fine a few years ago. The module is soldered down on a little shield.

The code is kosher. It works on a DS1307 on another Mega.

The red light on the jam side of the ZS-042 works, as does the Tx LED on the Mega, and the display on the monitor is OK, but it won’t advance from 0:0:0.

While I don’t need the backup battery, it makes no difference if it’s there or not.

The code is just a little clock timed with delay(1000), I recognise that the pulse on the Tx LED is all down to the Mega, but I don’t know about the red LED on the ZS-042.

The readout on the monitor is 1/1/0 0:0:0. The “1”s make me feel this is a return from the RTC.

Does anybody know where the problem might lie?

Maybe... an uninitialized variable or one used in an unintended scope.

I would have thought that would show up in the compile. More to the point, the same code works on another Mega with a different clock shield.

I might point out that this is a test of the RTC. The real intent is to have it time a loop with 1Hz square wave. I failed at that so I just wanted it to display the time. In the main game, I didn’t see the red LED under the board either, so I think the problem there is me - hence the simple clock test. I have not yet attempted to run the real job off the DS107.

Post a picture of your solder joints. Then we can have a look.
Did you measure voltage at the RTC?

I guess I would not expect code written for a DS1307 to work with a DS3231. But I haven't tried it.

Is there an example sketch for the DS3231 and Mega that you could try?

If you just want the time, DS1037 code is exactly the same as DS3231. It is all I have ever used. DS3231 can do things a DS1307 can't, but I don't know what they are. That said, I think a DS1307 can be used to do anything a DS3231 can be used for, but it will need the right code.

Ok, well we haven't seen either your code or your circuit, so it's kinda hard to know what to suggest.

As I said, I'm sure the code is kosher and, just in case of accidents, I have tried it on another Mega.

As I said, the RTC is on a little shield that had been in use before. The circuit is
SDA > SDA
SCL > SCL as one would expect, and the red LED under the module flashes. It also displays on the monitor.


@build1971, I recognise that the soldering is slack, but it looks wet, and worked continuously for several years. It occurred to me that the module is totally stuffed, but it seems to be delivering something. I believe this is confirmed by the output on the monitor being always
1/1/0 0:0:0 i.e. a/a/b b:b:b whereas, if the shield is removed, the monitor displays
165/165/165 45:165:165 i.e. a/a/a b:a:a.
God only knows what the red LED is actually telling me, but the fact that it flashes @ 1Hz surely suffices.

I don't suppose I am the first to experience this problem, so I'm not looking for a critique on code or wiring, I'm just looking for somebody who has experienced the same thing and can simply say, "Ah yes, that's because of dadedah..."
In the meantime, I guess I can get out an unused DS1307 and put it over a breadboard to see if I can improve things.

#include "Wire.h"
#define DS1307_ADDRESS 0x68
void setup(){
Wire.begin();
Serial.begin(9600);
}
void loop(){
printDate();
delay(1000);
}

byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}

void printDate(){
Wire.beginTransmission(DS1307_ADDRESS);
byte zero = 0x00;
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);

int second = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
int monthDay = bcdToDec(Wire.read());
int month = bcdToDec(Wire.read());
int year = bcdToDec(Wire.read());
//print the date EG 3/1/11 23:59:59

Serial.print(month);
Serial.print("/");
Serial.print(monthDay);
Serial.print("/");
Serial.print(year);
Serial.print(" ");
Serial.print(hour);
Serial.print(":");
Serial.print(minute);
Serial.print(":");
Serial.println(second);
}

That issue has shown its face before. Search results for '165/165/165 order:latest' - Arduino Forum

You unfortunately have to do the digging. From memory some were solved.

Thank you, I'll do some trawling. Once I had my standard code going, I had not the slightest problem for years. Now I have two DS1307s and a DS3231 going, and all are giving me grief of one sort or another.

Correction: I now have a DS1307 running. It had no default time because it was bought with no battery, and it just showed nothing but 80 seconds and no advance. I'm not actually interested in time per se, but you have to set it with something. This does not apply to the other ones, which were indeed set yesterday

I will take a SWAG and say it is a bad or missing solder joint.

According to the schematic from here, there is only one led on the DS3231 module and it is a power led: Adapting the DS3231 charging circuit

If that is indeed the led referred to here:

Then that requires some investigation. A power led is not expected to flash. What shield is between the Mega and your shield carrying the DS3231 module?

Thank you for your comment. I haven't used this stuff for quite a while but I did did muse ".. gee, I don't recall that LED flashing...". But, it was doing it in synch with LED on Mega Tx, so I thought it was OK. The LIR2032 seems reluctant to take a charge, so maybe the flashing has something to do with that.

BUT I have now just put that shield back into service with the battery removed. The red LED is still flashing, so the battery is evidently not the villain!

There is no intermediate shield, the shield for clock and Bluetooth was made specifically for the back end of a Mega, as shown in post #8.

OK 6v6GT, You have definitely pointed me to a mechanical problem.
I now understand the red LED should NOT be flashing.

It was flashing in synch with TX, not necessarily on the same clock cycle but 1Hz nevertheless.

I commented out the printdate command and reloaded.

I now have no 1Hz flashing LEDs, but there is nothing to suggest the code isn't working.

I accidentally dropped the Mega on the desk, and the red Led flashed. I now find I can consistently flash the LED by tapping Mega on the desk. Stupid mechanical problem.

The battery being in or out has no bearing on what it flashing - or isn't.

I will retire the shield for the moment, and concentrate on other gear, some of which is also giving me grief, but I only need one that works.

Thanks again....

Some resoldering may do the trick.
Some are pretty ugly.
May conduct or may not...
After a hit, one may be loose now...

Yes. I'm not looking forward to this. I'll put it aside till the weekend! I need batteries for my close-up glasses....

Tip: more solder does not improve the joint...
Use flux, to let the solder flow...

Yes, I have a shiny new solder roll AND a flux pen ( for the first time)

Thanks, I’ll do some digging. My standard code ran flawlessly for years, but now I’ve got two DS1307s and a DS3231, and all are giving me different issues.

Update: one DS1307 is working now turns out it had no default time since it came without a battery, so it was stuck showing 80 seconds with no advance. I’m not really concerned with keeping accurate time, but you still have to set it to something. The others, which I set yesterday, are still acting up.

I hope I am talking to the right person here.
Some of the configuration settings that you be relying on for this application such as the 1Hz square wave, talked about on post #3 , have to be set explicitly and will get lost when the power is removed and there is no back-up battery. The code you have posted thus far in post #8 is too thin to do this configuration. Is it possible that you used another sketch originally to configure the DS3231 module then this configuration died with the backup battery.

Probably it would be best to start again with a "trusted" DS3231 library and ensure that in setup() any missing configuration, such as the square wave is corrected. I believe the oscillator will start on its own, though, provided the correct voltages are present on Vcc but there is a mechanism to stop the back up battery being used in a new module until the device is connected for the first time.