DS1307 returns incorrect data ???


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    Join Date
    Jul 2008
    Posts
    38


    Did you find this post helpful? Yes | No

    Default

    Although i'm NOW writing as hex data to keep things clear for me, i think my main problem is Reading/converting the 'read data' into correct decimal form.

    getting closer ;-)
    Marty.

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


    Did you find this post helpful? Yes | No

    Default

    Look at the DS1307 registers and format your data accordingly. The values you write should be packed BCD values wherever needed.

    eg: To write 21 minutes, you need to write HEX 21 to the minutes register. Same for the other registers like hours and seconds. Only make sure to write to the bits needed by the registers.

    I haven't used PBP to write a DS1307 yet, but have some C code that works with the IC. Let me know if you wish to look at it for inspiration

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    This is for a DS1337C but it might give you an idea...

    Routine to set the RTC:
    Code:
    <font color="#0000FF"><b>SET_RTC</b></font>:
    <font color="#0000FF"><b>yr </b></font>= <font color="#800000"><b>$09
    </b></font><font color="#0000FF"><b>mon </b></font>= <font color="#800000"><b>$03
    </b></font><font color="#0000FF"><b>date </b></font>= <font color="#800000"><b>$07
    </b></font><font color="#0000FF"><b>sec </b></font>= <font color="#800000"><b>$00
    </b></font><font color="#0000FF"><b>mins </b></font>= <font color="#800000"><b>$28
    </b></font><font color="#0000FF"><b>hr </b></font>= <font color="#800000"><b>$05
    </b></font><font color="#FF0000"><b>I2CWRITE </b></font><font color="#0000FF"><b>DS_SDA</b></font>, <font color="#0000FF"><b>DS_SCL</b></font>, <font color="#0000FF"><b>RTC</b></font>, <font color="#0000FF"><b>SecReg</b></font>, [<font color="#0000FF"><b>sec</b></font>,<font color="#0000FF"><b>mins</b></font>,<font color="#0000FF"><b>hr</b></font>,<font color="#0000FF"><b>day</b></font>,<font color="#0000FF"><b>date</b></font>,<font color="#0000FF"><b>mon</b></font>,<font color="#0000FF"><b>yr</b></font>]
    <font color="#FF0000"><b>RETURN 
    </b></font>
    To READ and send to terminal:
    Code:
    <font color="#FF0000"><b>I2CREAD </b></font><font color="#0000FF"><b>DS_SDA</b></font>, <font color="#0000FF"><b>DS_SCL</b></font>, <font color="#0000FF"><b>RTC</b></font>, <font color="#0000FF"><b>SecReg</b></font>, [<font color="#0000FF"><b>sec</b></font>,<font color="#0000FF"><b>MINs</b></font>,<font color="#0000FF"><b>hr</b></font>,<font color="#0000FF"><b>day</b></font>,<font color="#0000FF"><b>date</b></font>,<font color="#0000FF"><b>mon</b></font>,<font color="#0000FF"><b>yr</b></font>] 
    <font color="#FF0000"><b>PAUSE </b></font><font color="#800000"><b>100
    </b></font><font color="#FF0000"><b>SEROUT2 </b></font><font color="#0000FF"><b>PORTC</b></font>.<font color="#800000"><b>6</b></font>, <font color="#800000"><b>16572</b></font>, [ <b>&quot;TIME &quot;</b>, <font color="#FF0000"><b>HEX2 </b></font><font color="#0000FF"><b>hr</b></font>, <b>&quot;:&quot;</b>, <font color="#FF0000"><b>HEX2 </b></font><font color="#0000FF"><b>MINs</b></font>, <b>&quot;:&quot;</b>,<font color="#FF0000"><b>HEX2 </b></font><font color="#0000FF"><b>sec</b></font>,<font color="#800000"><b>$d</b></font>, <font color="#800000"><b>$a</b></font>]
    <font color="#FF0000"><b>SEROUT2 </b></font><font color="#0000FF"><b>PORTC</b></font>.<font color="#800000"><b>6</b></font>, <font color="#800000"><b>16572</b></font>, [ <b>&quot;DATE &quot;</b>, <font color="#FF0000"><b>HEX2 </b></font><font color="#0000FF"><b>mon</b></font>,<b>&quot;-&quot;</b>,<font color="#FF0000"><b>HEX2 </b></font><font color="#0000FF"><b>date</b></font>,<b>&quot;-&quot;</b>,<font color="#FF0000"><b>HEX2 </b></font><font color="#0000FF"><b>yr</b></font>,<font color="#800000"><b>$d</b></font>, <font color="#800000"><b>$a</b></font>]
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Jul 2008
    Posts
    38


    Did you find this post helpful? Yes | No

    Talking

    Thanx Dave, i'll try that when time allows....

    I tried some things from other examples recently, but anything with a DEC2 or HEX2 command in it wouldn't compile for me.

    I was using PBP 2.40 with Code Designer lite 1.7, although today i've just purchased PBP 2.60 upgrade (& manual) from local supplier.

    Does it sound possible that v2.4 didn't support DEC/HEX commands?

    Anyway, back to it
    Marty.

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gtvmarty View Post
    Does it sound possible that v2.4 didn't support DEC/HEX commands?
    Not sure, could be.
    Make sure your local supplier does not sell you an old version. Get 2.6.
    Last edited by mackrackit; - 7th October 2009 at 12:01.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Jul 2008
    Posts
    38


    Did you find this post helpful? Yes | No

    Default

    Yep, it IS v2.6 from Dontronics (Aus).

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


    Did you find this post helpful? Yes | No

    Default

    hello

    a good example of converting binary bcd
    http://www.picaxeforum.co.uk/showthr...307+Correction

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 : 0

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