DS1307 returns incorrect data ???


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    Join Date
    Jul 2008
    Posts
    38

    Default DS1307 returns incorrect data ???

    Hi All,

    I know how much we dread the DS1307 RTC discussions, but here goes.....


    I recently added a DS1307 to my pic16f877 for a data logging project.
    I read a serial string into the pic, and send out some serial data with an added time/date stamped onto it for loggin purposes......fairly simple stuff

    I can write to the RTCC, and READ from the RTCC with good results...

    However, for some reason it displays 90 (yes, NINETY!) seconds before it will increment the minutes.

    Also, when the minutes reaches certain numbers, it will jump by 6 mins on the next increment.
    For example 12:37:00 will change to 12:43:00 when the next 'minute increment' occurs.

    I'm NOT using a 12pf 32,768khz Xtal at the moment, however i thought having the wrong Xtal would only make my clock run slow/fast.

    I can't understand where i get 90secs from?

    I am writing DECIMAL numbers into the RTCC, not hex etc, as i've seen people writing/reading in 2 different number formats which confused them.

    Anyone seen this before?

    Thanx,
    Marty.

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    I use the DS1307 regularly and do not find this behaviour. Perhaps some interrupt routine is disturbing your RTC read? I am not underestimating your skill, but, maybe something is wrong with the code. It will be better if you can post it here for review.

  3. #3
    Join Date
    Jul 2008
    Posts
    38


    Did you find this post helpful? Yes | No

    Default

    HI there,

    Here's the basic code i use, which seems to work, except for the odd figures i mentioned initially.

    Code:
    I2CWrite PORTC.2,PORTC.3,$D0,$00,[0, 15, 15, 5, 1, 10, 9, 10]	
    'WRITE time and date e.g. this dsets clock to 15:15:00 (3:15pm) on 
    'Thur (5), 1st (1), October (10), 2009 (9), with control set to "10" for 
    'a 1Hz pulseout on pin7.
    
    'and later i send this to serial port....
    SerOut TX,T9600,["Logged at",#RTCHour,":",#RTCMin,":",#RTCSec,",13,10]

    Obviously later, i remmed out the WRITE line, so the pic doesnt keep restarting at the same time/date.


    Happy to be pointed out any wrong byte(s) i'm using or missing
    Marty.
    Last edited by gtvmarty; - 1st October 2009 at 09:44.

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Bit 7 of the seconds register in a 1307 is the "CH" bit, or "Clock Halt".

    If that bit is set, you could easily get values of 90+ seconds.
    Except that if that bit is set, the clock isn't running.

    On initial power-up of a 1307 the internal registers are "undefined", so you actually have to set that bit to 0 to make sure the clock is running.

    But if it's counting, and you get 90+ .... OMG.
    <br>
    DT

  5. #5
    Join Date
    Feb 2006
    Location
    france
    Posts
    47


    Did you find this post helpful? Yes | No

    Default corect

    Hello

    Your routine is correct, try this program
    Attached Files Attached Files

  6. #6
    sinoteq's Avatar
    sinoteq Guest


    Did you find this post helpful? Yes | No

    Default formats

    Hi
    I wounder if you have not done a mistake in how you use the RTC, the DS has a "funny" way to handle numbers. They are BCD coded and can not be written as Decimal numbers straight. You say you write I2CWrite PORTC.2,PORTC.3,$D0,$00,[0, 15, 15, 5, 1, 10, 9, 10]. Please look at the datasheet Timekeeper registers. If you want to load 15 minutes in the DS you have to write it as 21DEC. Why? Becasue the low 4 bits are minutes and the higher 3 bits are 10 minutes so.... Low bits should be 5 (%0101) and then we need 1 ten-minutes thus getting %00010101

    Minutes and Hours are kind of straight forward BCD but the Hours register you have to setup for 12pm or 24 hours function and on top of this use BDC codes.

    You can not use almost any register from the DS without convering it from BCD code and you get 90 and the strange jumps becasue of this.

Similar Threads

  1. Using Nokia LCD
    By BobP in forum mel PIC BASIC Pro
    Replies: 300
    Last Post: - 3rd May 2018, 04:47
  2. Read/Write Problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th February 2010, 01:51
  3. Big characters on HD44780 4x20
    By erpalma in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 7th January 2007, 02:21
  4. LCD + bar graph
    By DynamoBen in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 5th October 2005, 14:50
  5. Sinus calculating !
    By Don Mario in forum mel PIC BASIC Pro
    Replies: 29
    Last Post: - 28th November 2004, 23:56

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts