DS3231 Loses time

Hi,

So i have a common DS3231 on a project when i power the project from USB, when i next connect the USB the time is correct

But the finished project has a meanwell 240v to 12v as i have 12v stepper motors then 12v to 5v that powers all arduino, rtc, sd card, a4988 stepper drivers. But as soon as i reconect the project to mains it loses the time.

I cant work out why its started to lose the time, tried a different LIR battery and rtc module

I have read that maybe the RTC needs a 3.3v circuit, but tbh when powered by usb it will be getting 5v

so to sum up

usb off / usb on time ok
usb off / mains on time reset
mains off / usb on time ok
mains off / mains on time reset

Is there a battery on the back of that so it can keep time when other power sources go away?

Does your code happen to reset the time when the code starts up?

Hi,

battery is in, as when when u disconnect power from either source, it retains time when powered by usb after, but connecting mains then loses the time to the default one

Its as if the battery has been disconnected

CAH1982:
Hi,

but connecting mains then loses the time to the default one

Its as if the battery has been disconnected

What is the default one?
How do you set the time to start with?

I know some Arduino (Uno among others) will reboot every time the USB is connected, this may be the difference.

Please show your code, maybe someone can then see an issue.

Does your code set the clock from computer time on startup?

i cant see it been the code, ad when i power via the USB it retains the time

the time is set vian buttons / oled then runs the following

rtc.adjust(DateTime(NEWYEAR, NEWMONTH, NEWDAY, NEWHOUR, NEWMINUTE, NEWSECOND));

as i said it remembers the time when power off via usb / mains, but only when power is restored on mains it loses the time, default time is 00.00.00 01-01-2000

Found the issue, on the PCB the 5v was last in the line, so run a additional 5v direct from regulator and it works everytime now