PDA

View Full Version : Pcf8563p Rtc Trouble



-Dan-
- 23rd November 2007, 17:03
Hi,

I'm using the PCF8563P rtc, i can not get it to work

ive never used the i2c protocol before, so maybe ive messed it up?

ive looked through the posts already present on the forum concerning the subject
and cannot figure it out.

i would be grateful of any help

just using the basic 16f84 mcu




'rtc pins

clk_pin var portb.5
data_pin var portb.4



'register address's

reg_seconds CON $02
reg_minutes con $03
reg_hours con $04
reg_days con $05
reg_weekdays con $06
reg_months_century con $07
reg_years con $08
reg_minute_alarm con $09
reg_hour_alarm con $0A
reg_day_alarm con $0B
reg_weekday_alarm con $0C

rtc_write var byte
rtc_read var byte

rtc_write=$a2
rtc_read=$a3



'time variables

seconds var byte
minutes var byte
hours var byte
days var byte
years var byte


'-----------------------------------------------------
'initial time variable values

seconds=0
minutes=0
hours=18
days=23
years=7

' -------------------------------------------------------

init:
pause 500
lcdout $fe,1
lcdout "Real Time Clock"
pause 1000


I2CWrite data_pin,clk_pin,rtc_write,reg_seconds,[seconds]
pause 10
I2CWrite data_pin,clk_pin,rtc_write,reg_minutes,[minutes]
pause 10
I2CWrite data_pin,clk_pin,rtc_write,reg_hours,[hours]
pause 10
I2CWrite data_pin,clk_pin,rtc_write,reg_days,[days]
pause 10
I2CWrite data_pin,clk_pin,rtc_write,reg_years,[years]
pause 10


main:

I2CRead data_pin,clk_pin,rtc_read,reg_seconds,[seconds]
pause 10
I2CRead data_pin,clk_pin,rtc_read,reg_minutes,[minutes]
pause 10
I2CRead data_pin,clk_pin,rtc_read,reg_hours,[hours]
pause 10
I2CRead data_pin,clk_pin,rtc_read,reg_days,[days]
pause 10
I2CRead data_pin,clk_pin,rtc_read, reg_years,[years]
pause 10


pause 500
lcdout $fe,1 ' clear lcd
lcdout dec2 hours,":",dec2 minutes,":", dec2 seconds," "
pause 500
goto main

inse
- 23rd November 2007, 22:09
Hello Dan,

I had started a project using the PCF8563 a bout a year ago (not yet finished).
Without deeper analysing your code, I noticed, that you are using different addresses for read and write.
PBP handles this for you, read/write always to the address $A2.
You could also shorten your code by using multiple reads/writes like
I2CRead data_pin,clk_pin,rtc_read,reg_seconds,[seconds, minutes, hours...]

Regards,

Ingo

BrianT
- 23rd November 2007, 22:19
I have not used the Philips RTC but I am sure the basic device will be similar to the DS 1629 that I use.

I notice you are writing to the chip in single bytes. You should be able to write an entire string and save on the eerom write delays.

Here is a code snip.

ConfigureClock:
i2cwrite sda, scl, %10011110, $AC, [$A0]
' Write to Configuration Register $AC with value $A0.
' See page 10 of DS1629 data sheet. Disables all alarms.
SetClock:
' Set up current time parameters - MUST be in BCD format
' note HEX is the same as BCD for this application
' Set for UTC which is AEST - 10 hours
' debug 13, 10, " Writing to clock", 13, 10
RTCSec = $00 ' Seconds NOTE 00 enables, 80 halts oscillator
read 49, RTCMin ' Minutes
read 50, RTCHour ' Hours
read 51, RTCDate ' Date
read 52, rTCMonth ' Months
read 53, RTCYear ' Year
RTCWDay = $04 ' Weekday - arbitrary number 1-7 (not used)
WriteClock: ' Write setup info.
I2Cwrite SDA,SCl,%10011110,$C0,$00,[RTCSec,RTCMin,RTCHour,_
RTCWDay,RTCDate,RTCMonth,RTCYear]
' set DS1629 into 'convert on demand' mode to save power
' write to $AC -
' No Alarm, active LOW, single conversion on command
' MSB = %00000101
i2cwrite SDA, SCl, %10011110, $AC, [ %10100000]
gosub lowestpower
end

And another snip.

ShowTime:
'fetch current time
I2CRead SDA,SCl,%10011110,$C0,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,_
RTCDate,RTCMonth,RTCYear]
'display current time
debug $0D, $0A, "200", #rtcyear & $0F, "/", #rtcmonth >> 4 & $0F,_
#rtcmonth & $0F , "/", #RTCDate>> 4 & $0F, #RTCDate& $0F, ", ",_
#rtchour >> 4 & $0F, #rtchour & $0F, ":", #rtcmin >> 4 & $0F,_
#rtcmin & $0F,":", #rtcsec >> 4 & $0F, #rtcsec & $0F


HTH
Brian

-Dan-
- 23rd November 2007, 23:02
Hello Dan,

I had started a project using the PCF8563 a bout a year ago (not yet finished).
Without deeper analysing your code, I noticed, that you are using different addresses for read and write.
PBP handles this for you, read/write always to the address $A2.
You could also shorten your code by using multiple reads/writes like
I2CRead data_pin,clk_pin,rtc_read,reg_seconds,[seconds, minutes, hours...]

Regards,

Ingo

hi

did you get the pcf8563 to work then ?

in the datasheet it had different addresses for writing and reading so i just used them both in my code to be safe, ive changed a few things now i get 08:08:08 displayed i don't no we re those values come from, because there not the ones i'm writing to the registers

confuuuuusion!

-Dan-
- 24th November 2007, 12:12
anyone have any idea's then

one thing i forgot to do was add pull up resistors on the data and clock lines so i added 10k resistors to them and i get the values 16 for hours minutes and seconds, whether connected to the rtc or not.

with the data line being bi directional i don't no what to do in means of setting it as an input or an ouput, or do i just not define it as either.

Thanks

Dan

Jerson
- 24th November 2007, 13:56
- Dan -

I don't have exactly what you want, but I have worked on a PCF8583 from Philips. Perhaps they are similar. You figure it out. Use it as a guideline if you may. Part of init is to set the SDA and SCL lines as outputs via the TRIS command.



'================================================= ===============================
' I2C RTC PCF8583 CODE using I2C_read and I2C_write routines of compiler
'================================================= ===============================
' RTC registers are defined
' 0 - Command / Status register
' .0 timer flag
' .1 alarm flag
' .2 alarm enable 1 - enabled
' .3 mask flag
' .54 function 00 clock 32.768KHz/01 clock 50Hz/10 evt counter/11 test
' .6 hold last count flag
' .7 stop counting, reset divider
' 1 - 1/10 s | 1/100s
' 2 - 10s | 1s seconds
' 3 - 10m | 1m minutes
' 4 - 10h | 1h hours
' .3..0 unit hours BCD
' .54 10s hours 0..2 binary
' .6 1 PM
' .7 1 12 hour format
' 5 - 10d | 1day Day & Year
' .3..0 unit days BCD
' .54 ten days 0..3 binary
' .76 year 0..3 binary (read 0 if mask)
' 6 - 10mo | 1month month
' .3..0 unit months BCD
' .4 ten months
' .7..5 weekdays 0..6 binary (read 0 if masked)
'
' 0x10 to 0xff RAM

' If RTC is not running, start it
TimerOff:
I2CWRITE SDA, SCL, $A2, ControlReg, [0]
return

' Read the time in BCD format
RTC_GetTime:
I2Cread SDA, SCL, $A2, SecondsReg+0, [Time[2],Time[1],Time[0]]
return

' Set time in BCD format
RTC_SetTime:
I2Cwrite SDA, SCL, $A2, SecondsReg+0, [Time[2],Time[1],Time[0]]
goto TimerOff

inse
- 26th November 2007, 20:01
Hi Dan,

i hope you got ahead with your code in the meantime.
My project is a clock (who could guess it?) with electromechanic seven segment displays.
The clock is running (1/2 hour behind by now) but the code for setting the time is still missing - as well as the buttons to be used for it.

You don't have to initialize the pins you use for I2C, it is done by the i2cread/i2cwrite commands.

I don't see what is causing the communication problems in your code - so i propose you check your hardware wiring.

Best wishes,

Ingo

-Dan-
- 30th November 2007, 01:41
Hi Dan,

i hope you got ahead with your code in the meantime.
My project is a clock (who could guess it?) with electromechanic seven segment displays.
The clock is running (1/2 hour behind by now) but the code for setting the time is still missing - as well as the buttons to be used for it.

You don't have to initialize the pins you use for I2C, it is done by the i2cread/i2cwrite commands.

I don't see what is causing the communication problems in your code - so i propose you check your hardware wiring.

Best wishes,

Ingo

hey

yer i got it working in the end, it turned out to be the 32.768 crystal i had, any way i swapped it out and it works ok now, apart from when it gets to say 9 seconds it skips to 16 but thats probably because i have no bcd conversions in my code?

Dan