My rtc(DS1307) cannot remain the information(either date or time). I have connected the 3V Li-battery to pin3(vbat) and 5v to pin8(Vcc) together.
When I disconnect the 5v supply and then re-connect it, the rtc only starts to which I set to. Why happens this issue??
Not much info there (such as the RTC model, circuit diagram) but if (as you say) it is starting at the value to which you set it to,
then that points to a code issue (you shouldn't be setting the value after microcontroller reset).
Not much info there (such as the RTC model, circuit diagram) but if (as you say) it is starting at the value to which you set it to,
then that points to a code issue (you shouldn't be setting the value after microcontroller reset).
Is you mean that it is no longer setting the information after I have set the information for one time? (The information has been stored in rtc when I set it one time??)
---------- Post added at 23:42 ---------- Previous post was at 23:39 ----------
Not much info there (such as the RTC model, circuit diagram) but if (as you say) it is starting at the value to which you set it to,
then that points to a code issue (you shouldn't be setting the value after microcontroller reset).
Is you mean that it is no longer setting the information after I have set the information for one time? (The information has been stored in rtc when I set it one time??)
I'm just saying you only need to set the RTC once. If after power loss the time is still the same value that you set it to and has not increased,
then it is likely that your code is reprogramming the RTC once the power is reconnected. I could be wrong. But worth checking out anyway.
If you have connected a separate battery to the Vbat pin,then you must initialize the rtc in your code only once.In your case,the code is initializing the rtc value every time it is powered up through the Vcc pin.
Initialize the rtc only once on power up and develop some logic to skip the initialization code during subsequent runs through the code.
This will surely solve your problem.....
---------- Post added at 21:50 ---------- Previous post was at 21:49 ----------
If you have connected a separate battery to the Vbat pin,then you must initialize the rtc in your code only once.In your case,the code is initializing the rtc value every time it is powered up through the Vcc pin.
Initialize the rtc only once on power up and develop some logic to skip the initialization code during subsequent runs through the code.
This will surely solve your problem.....
?Initialize the rtc only once on power up I do not understand this. Do I comment the initialization of rtc after the rtc has been initialized once ?
Also, please refer to the following code,,,
Your battery backup is for the rtc, _not_ the microcontroller. So, after the circuit is restarted, then the microcontroller will rerun the
system_init() function that you've shown. So since you're executing the settime() function, it explains the problem you're experiencing.
Line Anish says, you need to implement some scheme not to execute this each time the microcontroller reboots. For example - only execute
the function if a specific switch is pressed.