Oh dear. Strange things with a DS3231


Yesterday 22:13
Forum: Proton Plus Compiler v3
Starter: gdesantis
Views: 0
Replies: 0
Yesterday 18:35
Forum: The Lounge
Starter: Les
Views: 0
Replies: 11
+ Reply to Thread
Results 1 to 5 of 5

Thread: Oh dear. Strange things with a DS32311039 days old

  1. #1
    Daniel
    Guest Daniel's Avatar

    0 Not allowed!

    Default Oh dear. Strange things with a DS3231

    I am using a DS3231 with an 877. It is receiving data, but the seconds are counting 1,2,3,4,5,6,7,8,9,16,17,18,19,20,22,23,24,25,32--------to 90 before the minutes increment.

    Any thoughts on this please?Daniel.

  2. #2
    Prolific Poster hadv215's Avatar
    Join Date
    Sep 2009
    Posts
    1,090
    Thumbs Up
    Received: 102
    Given: 23
    Total Downloaded
    1.51 GB

    0 Not allowed!

    Default Re: Oh dear. Strange things with a DS3231

    Values are BCD, you'll have to convert them to decimal before using them.

    So the results you write down here make sense: 16 is 0x10, but that's BCD, so decimal would be 10: presto!

    Here a piece of code to do the conversion. DSData[cMin] is the value for minutes received from the DS3231.
    Code:
        iTemp1 = DSData[cMin] & 0xF0
        iTemp1 = iTemp1 >> 4
        iTemp2 = DSData[cMin] & 001111        
        iMin = iTemp2 + (10 * iTemp1)
    Last edited by hadv215; 7th February 2016 at 12:10.

  3. #3
    Daniel
    Guest Daniel's Avatar

    0 Not allowed!

    Default Re: Oh dear. Strange things with a DS3231

    Thank you for the reply.

    I did try it and with no luck.

    I know it is probably the wrong way to go about it, but I did it using the getbit statement. I have plenty of memory with the 877.

    Thanks again.

    Daniel.

  4. #4
    Member VaGyver's Avatar
    Join Date
    Oct 2002
    Posts
    223
    Thumbs Up
    Received: 3
    Given: 7
    Total Downloaded
    9.17 MB

    1 Not allowed!

    Default Re: Oh dear. Strange things with a DS3231

    I have to use it for a long time but i think this piece of code does works for ds3231.
    If you want, give it a try.


    Code:
    Dim Seconds As Byte 
    Dim minutes As Byte 
    Dim Hours  As Byte 
    Dim Day  As Byte 
    Dim Date As Byte 
    Dim Month As Byte 
    Dim Year As Byte 
    Dim BIN_TO_BCD_VALUE As Byte
    
    
    Dim BCD_OUTPUT As Byte
    Dim BCD_TO_BIN_VALUE As Byte
    Dim BIN_OUTPUT As Byte
    Dim temp11 As Byte
    Dim temp22 As Byte
    
    
    MAIN_LOOP:
    GoSub read_time            
    Print At 1,1,Dec2 Hours," ",Dec2 minutes, " ",Dec2 Seconds 
    DelayMS 500
    GoTo MAIN_LOOP   
    
    
    
    
    GoTo ds3231
    
    
    set_time:
    BIN_TO_BCD_VALUE = Seconds
    GoSub BIN_TO_BCD
    BusOut $D0,$00,[BCD_OUTPUT] 'Save Mins
    
    
    BIN_TO_BCD_VALUE = minutes
    GoSub BIN_TO_BCD
    BusOut $D0,$01,[BCD_OUTPUT] 'Save Mins
    
    
    BIN_TO_BCD_VALUE = Hours
    GoSub BIN_TO_BCD
    BusOut $D0,$02,[BCD_OUTPUT] 'Save Hours
    
    
    
    
    BIN_TO_BCD_VALUE = Day
    GoSub BIN_TO_BCD
    BusOut $D0,$03,[BCD_OUTPUT] 'Save day
    
    
    
    
    BIN_TO_BCD_VALUE = Date
    GoSub BIN_TO_BCD
    BusOut $D0,$04,[BCD_OUTPUT] 'Save date
    
    
    
    
    BIN_TO_BCD_VALUE = Month
    GoSub BIN_TO_BCD
    BusOut $D0,$05,[BCD_OUTPUT] 'Save month
    
    
    
    
    BIN_TO_BCD_VALUE = Year
    GoSub BIN_TO_BCD
    BusOut $D0,$06,[BCD_OUTPUT] 'Save year
    Return
    '--------------------------------------------
    '--------------------------------------------
    read_time: 
    BusIn $D1,$0,[Seconds,minutes,Hours,Day,Date,Month,Year]    '$3F
    BCD_TO_BIN_VALUE=Seconds:GoSub BCD2BIN:Seconds=BIN_OUTPUT
    BCD_TO_BIN_VALUE=minutes:GoSub BCD2BIN:minutes=BIN_OUTPUT
    BCD_TO_BIN_VALUE=Hours:GoSub BCD2BIN:Hours=BIN_OUTPUT
    BCD_TO_BIN_VALUE=Date:GoSub BCD2BIN:Date=BIN_OUTPUT
    BCD_TO_BIN_VALUE=Month:GoSub BCD2BIN:Month=BIN_OUTPUT
    BCD_TO_BIN_VALUE=Year:GoSub BCD2BIN:Year=BIN_OUTPUT
    '----------------------------------
    BIN_TO_BCD:
    temp11 = Dig BIN_TO_BCD_VALUE, 0
    temp22 = Dig BIN_TO_BCD_VALUE, 1
    temp22 = temp22 << 4 ' MOVE NUMBER OVER TO 2ND NIBBLE
    BCD_OUTPUT = temp11 ^ temp22
    Return
    
    
     
    BCD2BIN:
    temp11 = BCD_TO_BIN_VALUE & $F ' CONVERT THE VALUES FROM BCD TO BIN
    temp22 = BCD_TO_BIN_VALUE & $F0 ' MASK OF EITHER SIDE
    temp22 = temp22 >>4 ' DIVIDE BY 16
    temp22 = temp22 * 10 ' X BY 10
    BIN_OUTPUT = temp11 + temp22 ' NOW ADD THE FIRST NUMBER YOU THOUGHT OF
    Return
    
    
    ds3231:
    VaGyver
    :)

  5. #5
    Daniel
    Guest Daniel's Avatar

    0 Not allowed!

    Default Re: Oh dear. Strange things with a DS3231

  6. With a little juggling, it worked.

    Thank you very much for your help.

    Daniel.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Hardware I2C and DS3231 RTC Problems
    By SimonJA in forum Proton Plus Compiler v3
    Replies: 3
    Last Post: 9th June 2010, 21:44
  2. DS3231 RTC to replace DS1307 - Can't get it working
    By SimonJA in forum Proton Plus Compiler v3
    Replies: 10
    Last Post: 20th January 2009, 11:25

Members who have read this thread : 42

Actions :  (Set Date)

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

Tags for this Thread

Posting Permissions

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