PDA

View Full Version : DS3231 works in one config, but does not works with other IC.



CuriousOne
- 28th November 2019, 17:00
Here I had a nice thread about DIY nixie clock, which is now gone. It was using DS1302 RTC, and many people asked to upgrade it to more precise DS3231. So I've bought one.

I took the code for DS1307 from here: http://melabs.com/samples/LABXUSB-18F4550/rtcxu.htm and slightly modified it to run on 16F886 (changed LCD pins and other config info). It works just fine, time can be set and read with great precision. So I decided to move the code to my nixie clock code, which runs on 16F1519. And now strange things happen. No matter what I write to DS3231, it returns "20-20-20" for time-hour-seconds. My complete code is quite long, so I'll post short fragment relating this chip. It is not wiring issue, because if I remove the DS3231, it will return 000000 as it should.



include "modedefs.bas"
OSCCON = %01110010 'SET INTOSC TO 8MHZ
ANSELC=%00000000
ANSELD=%00000000 'disable ADC
ANSELB=%00000000
ANSELA=%00000000
ANSELE=%00000000
TRISC=%00000000 'set PORTC as output all
TRISD=%00000000 'set PORTD as output all
TRISB=%00000000 'set PORTD as output all
TRISA=%00000110 'tried to make 4-5 pins inputs or outputs, no difference
TRISE=%00000000
DEFINE OSC 8 'OSC SPEED

SDA Var PORTA.5 'DS 3231 pins
SCL Var PORTA.4

RTCYear Var Byte
RTCMonth Var Byte
RTCDate Var Byte
RTCDay Var Byte
RTCHour Var Byte
RTCMin Var Byte
RTCSec Var Byte
RTCCtrl Var Byte

settime:
'rtcsec=0 ' this is necessary to make clock tick
I2CWrite SDA, SCL, $D0, $00, [RTCSec, RTCMin, RTCHour, RTCDay, RTCDate, RTCMonth, RTCYear, RTCCtrl]
Return

gettime:
I2CRead SDA, SCL, $D0, $00, [RTCSec, RTCMin, RTCHour, RTCDay, RTCDate, RTCMonth, RTCYear, RTCCtrl]
Return

if DRO<>rtcmin then 'check for time changes, so display only is refreshed when time is changed
cvlileba=1
else
cvlileba=0
endif

DRO=rtcmin
Return

timedecode: 'decode time from RTC into values suitable for nixie digit illumination
t1=rtchour >> 4 'tens of hours digits
t2=rtchour // 16 'ones of hours
t3=rtcMin >> 4 'tens of minutes
T4=rtcMin // 16 'ones of minutes


return



So no matter what I set or red, always T1 and T3=2 and T2 and T4 =0. But I've added a cvlileba variable, to monitor whenever clock is "ticking" so it is indeed ticking, because this variable keeps changing each minute. So what is wrong, my decoding routine?

CuriousOne
- 29th November 2019, 06:14
Fixed it - was caused by wiring issue. I did an error - ordered black PCB's, and traces are very hard to see there, so I've soldered to PORTE.0 instead of PORTA.5 :)

Ioannis
- 3rd December 2019, 19:38
Black is nice but as you said hard to spot errors.

Ioannis

CuriousOne
- 3rd December 2019, 19:52
Yes, so I took sandpaper and removed all the masking paint :D