PDA

View Full Version : RTC date problem



Peder
- 17th January 2006, 11:56
Hi, I am working with a PCF 8583 real time clock. I can read and write to the device correctly, but as soon as the time changes to 00:00:00, the day and month gets incremented by the RTC automatically. I have tried changing the RTC, but the same thing happens.

Can anyone help me?

Thanks

ardhuru
- 18th January 2006, 06:10
Are you sure you are masking off the unused bits in the month and date registers while reading/writing?

You can expect bizarre things if you are simply reading (or writingto) the whole register(s).

Regards,

Anand

Peder
- 18th January 2006, 06:59
Yes, I have masked it ( I2CWrite DPIN,CPIN, RTC,$00,[ $09 ] ).

Could it be because I'm reading the RTC every second, it is confuses the RTC when it wants to update the date the same time as I'm trying to read it?

ardhuru
- 18th January 2006, 08:10
Hi Peder,

I dont think reading the chip every second should be an issue; I have used a PCF 8563 in a propeller clock that gets polled far more frequently, and there is no problem.

I am attaching a snippet using PBP with the PCF8583 that I had downloaded some time ago; this might lead you in the right direction.

Regards,

Anand

Peder
- 18th January 2006, 10:28
Thanks man, by checking your code and comparing it to mine, I realised that I made my "DAY" variable WORD instead of BYTE. It works perfectly now...

Thank you for your help and time.

Cheers

BobK
- 19th January 2006, 02:39
Hi ardhuru,

Would it be possible for you to post the rest of the code for the RTC including time setting? I think many people on this forum would be interested as there have been some posts requesting specifically this chip.

Thank you very much!

BobK

ardhuru
- 19th January 2006, 05:35
Hi Bob,

Actually, I used the PCF8563, which is virtually identical to the PCF8583 except for a few features.

Anyway, here are the RTC read and RTC write segments that I use. Since my RTC works on a battery (a CR2032, now in its second year, expected to go on for at least a year more!), I have also extracted the low battery indiactor bit.

'READ FRESH VALUES FROM THE RTC and convert BCD to decimal

I2CREAD SDA,SCL,$A2,2,[S,m,h,D,W,MN,Y] 'Read all parameters from the RTC

LOBATT = S & %10000000 ' Mask off all bits unimplemented in RTC registers
S = S & %01111111 '
M = M & %01111111 '
h = H & %00111111 '
D = D & %00111111 '
Mn = Mn & %00011111 '

TMP=S ' Convert BCD to decimal
S=((tmp>>4)*10)+(tmp & $0F) '
tmp=M '
M=((tmp>>4)*10)+(tmp & $0F) '
tmp=H '
H=((tmp>>4)*10)+(tmp & $0F) '
tmp=D '
D=((tmp>>4)*10)+(tmp & $0F) '
tmp=MN '
MN=((tmp>>4)*10)+(tmp & $0F) '
tmp=Y '
Y=((tmp>>4)*10)+(tmp & $0F) '


'Convert Decimal Seconds,Minutes & Hours values to BCD equivalents and write to RTC

tmp=S
S=(tmp dig 1<<4)+(tmp dig 0)
tmp=M
M=(tmp dig 1<<4)+(tmp dig 0)
tmp=H
H=(tmp dig 1<<4)+(tmp dig 0)
tmp=D
D=(tmp dig 1<<4)+(tmp dig 0)
tmp=MN
MN=(tmp dig 1<<4)+(tmp dig 0)
tmp=Y
Y=(tmp dig 1<<4)+(tmp dig 0)

I2CWRITE SDA,SCL,$A2,2,[S,M,H,D,W,MN,Y] 'Write parameters to RTC

Hope this helps!

Regards,

Anand

BobK
- 19th January 2006, 12:33
Hi Anand,

Thank you!

BobK