Using a PIC microcontroller to interface with a DS1302 real time clock

Status
Not open for further replies.
Where does the code look like I'm clearing the whole register.
On the other note, I'm not aware of the ability to change the register content without stopping the clock. I probably never want to stop the clock. I don't recall reading anything about the datasheet whether I have to stop the clock before modifying the contents before they change again.
 
Shouldn't

writebyte(WRITESEC, current_time & (0xfe << 7));

be

writebyte(WRITESEC, current_time & 0x7f);

Mike.
 
I think they are the same. However, your function call is more efficient since there is one less operation. My function call included an extra operation of shifting the 0 in bit 0 to the left seven times.
 
0xfe shifted left 7 times is 0x7f00, I assume WRITESEC requires a byte and therefore it will get passed zero.

Mike.
 
You're still writing over the seconds register no matter how you figure it. You should write the seconds last and let it run. It does all the MDY calcs on its own till year 2100. Are you trying to make it a stopwatch?
 
I'm not trying to make it a stopwatch. Once I set it, I'm probably setting it for good. Using it as a timestamp.
 
Isn't the best way to use burst mode then the registers all get updated at the same time - once the 8th register is written.

Or, write the seconds first. As long as the value written is not 59 then there is no chance of the minutes/hours etc. rolling over during the update.

Mike.
 
How much faster would the burst mode be compared to accessing the register contents one at a time?
 
It's not that it is faster. Burst mode has the advantage that none of the registers are written until you write the eight one, therefore ensuring that a register can't rollover during the update.

Alternatively, writing the seconds register first with a value other than 0x59 will make sure that rollover can't happen during the update.

Mike.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…