+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Ds1305

  1. #1
    Licensed User pic-ignorant's Avatar
    Join Date
    Oct 2007
    Location
    Sunny Kent
    Posts
    2,125

    Default Ds1305

    Just wondering if anybody has some code for a DS1305?
    I know we're supposed to do our own homework, and not expect a freebie etc, but I need to get one running quickly, so any help would be greatly appreciated

    Thanks

    Hi, its great to see you visiting our forum. Why not try Proton Compiler for FREE?

    Download the FREE version of Proton Compiler, Its called Amicus18 and its available from HERE

    Already using proton Compiler??? Get rid of these pesky messages... get LICENSED USER STATUS




    John


  2. If you're a Licensed user of PROTON DEVELOPMENT SUITE, apply for Licensed User Status to remove these pesky messages
     and get access to additional forum areas, Beta test downloads and more!

  3. #2
    Moderator RGV250's Avatar
    Join Date
    Aug 2005
    Location
    Kent.
    Posts
    1,711


    Default Re: Ds1305

    Hi John,
    Looking at the datasheet it is SPI, it looks very much like the code for a DS1302 would work so I would compare both datasheets for the addressing and communication to see if that would work. There is a 1302 example in the samples and I think there are a lot of examples on here.

    Regards,
    Bob

  4. #3
    Licensed User pic-ignorant's Avatar
    Join Date
    Oct 2007
    Location
    Sunny Kent
    Posts
    2,125


    Default Re: Ds1305

    Thanks Bob,
    I always forget about the samples folder!

  5. #4
    Licensed User pic-ignorant's Avatar
    Join Date
    Oct 2007
    Location
    Sunny Kent
    Posts
    2,125


    Default Re: Ds1305

    This is driving me nuts now. Can anybody see where I am going wrong?


    'SET INTERNAL TO 8MHZ
    OSCCON.4 = 1
    OSCCON.5 = 1
    OSCCON.6 = 1
    OSCTUNE.6 = 0
    Xtal = 8
    All_Digital = TRUE

    TRISA = %00001111
    TRISB = %00001000
    TRISC = %00010000
    TRISD = %00000000
    'SET UP MSSP MODULE FOR SPI
    SSPSTAT = 0xC0 'SPI MASTER: DATA SAMPLED AT END :TRANSMIT OCCURS ON TRANSITION FROM ACTIVE TO IDLE STATE
    SSPCON1 = 0x22 '00100010 MSSP ENABLED:CLOCK IDLES LOW : SPI MASTER MODE FOSC/64
    Dim GetTIME[6] As Byte
    Symbol
    CE =
    LATC.2
    Symbol SSP1IF =
    PIR1.3
    Symbol SECONDS = GetTIME[0}
    Symbol MINUTES = GetTIME[1]
    Symbol HOURS = GetTIME[2]
    Symbol DATE = GetTIME[3]
    Symbol MONTH = GetTIME[4]
    Symbol YEAR = GetTIME[5]
    Dim INDEX As Byte
    Float_Display_Type = Fast
    Declare LCD_DTPin
    LATD.4 'PIN 11-14
    Declare LCD_ENPin LATD.3 'LCD PIN 6 PIC.23
    Declare LCD_RSPin LATD.2 'LCD PIN 4 PIC.21
    Declare LCD_Lines 2
    Declare
    LCD_Type ALPHA
    DelayMS 100
    Cls
    Print At
    1,1,
    " DS1305 TEST"
    DelayMS 2000
    Cls
    GoSub
    ds1305_SetTIME
    LOOP:
    ' GoSub DS1305_READ
    Print At 1,1, "Time ", Hex2 GetTIME[2],":",Hex2 GetTIME[1],":",Hex2 GetTIME[0]
    Print At 2,1,
    "Date ", Hex2 GetTIME[3],"/",Hex2 GetTIME[4],"/",Hex2 GetTIME[5]
    Toggle
    PORTD.1
    DelayMS 250
    GoTo LOOP
    'READ TIME DATA IN FROM DS1305
    DS1305_READ:
    High CE
    DelayCS 1
    SSP1IF = 0
    'CLEAR FLAG
    SSPBUF = 0x00 'START AT 0x00. SECONDS REG
    Repeat
    Until
    SSP1IF = 1 'BUFFER WRITE COMPLETE
    SSP1IF = 0
    For INDEX = 0 To 5
    Repeat
    Until
    SSP1IF = 1
    GetTIME[INDEX] =
    SSPBUF
    SSP1IF = 0
    Next INDEX
    Low CE
    Return
     
    ds1305_SetTIME:
    'WP BIT IN CONTROL REG MUST BE CLEAR BEFORE WRITING TO DS1305 REG's
    '************************************************* *****************
    High CE 'ENABLE DS1305
    DelayCS 1

    SSP1IF = 0
    'CLEAR FLAG
    SSPBUF = 0x8F 'START AT CONTROL REG
    Repeat
    Until
    SSP1IF = 1 'BUFFER WRITE COMPLETE
    SSP1IF = 0 'CLEAR FLAG
    SSPBUF = 0x00 'CLEAR ALL BITS (INCLUDING WP BIT)
    Repeat
    Until
    SSP1IF = 1 'BUFFER WRITE COMPLETE
    Low CE 'DISABLE CHIP
    'SET TIME
    '************************************************* *****************
    High CE 'ENABLE DS1305
    DelayCS 1
    SSP1IF = 0
    'CLEAR FLAG
    SSPBUF = 0x80 'START AT 0x80. SECONDS REG
    Repeat
    Until
    SSP1IF = 1 'BUFFER WRITE COMPLETE
    SSP1IF = 0 'CLEAR FLAG
    SSPBUF = 0x47 'SET SECONDS TO 47
    Repeat
    Until
    SSP1IF = 1 'BUFFER WRITE COMPLETE
    SSP1IF = 0 'CLEAR FLAG
    SSPBUF = 0x32 'SET MINUTES TO 32
    Repeat
    Until
    SSP1IF = 1 'BUFFER WRITE COMPLETE
    SSP1IF = 0 'CLEAR FLAG
    SSPBUF = 0x20 'SET HOURS TO 20
    Repeat
    Until
    SSP1IF = 1 'BUFFER WRITE COMPLETE
    SSP1IF = 0 'CLEAR FLAG
    SSPBUF = 0x01 'SET DAY TO 1 (MONDAY)
    Repeat
    Until
    SSP1IF = 1 'BUFFER WRITE COMPLETE
    SSP1IF = 0 'CLEAR FLAG
    SSPBUF = 0x13 'SET DATE TO 13TH
    Repeat
    Until
    SSP1IF = 1 'BUFFER WRITE COMPLETE
    SSP1IF = 0 'CLEAR FLAG
    SSPBUF = 0x02 'SET MONTH TO FEBRUARY
    Repeat
    Until
    SSP1IF = 1 'BUFFER WRITE COMPLETE
    SSP1IF = 0 'CLEAR FLAG
    SSPBUF = 0x12 'SET YEAR TO 2012
    Repeat
    Until
    SSP1IF = 1 'BUFFER WRITE COMPLETE
    Low CE 'DISABLE DS1305
    Return

  6. #5
    Licensed User pic-ignorant's Avatar
    Join Date
    Oct 2007
    Location
    Sunny Kent
    Posts
    2,125


    Default Re: Ds1305

    The problem appears to be in reading the data back in. The program loop goes to DS1305_READ, then writes to seconds register OK, but hangs on reading the registers back.

  7. #6
    Licensed User pic-ignorant's Avatar
    Join Date
    Oct 2007
    Location
    Sunny Kent
    Posts
    2,125


    Default Re: Ds1305

    Well, I got it to come out of the read routine with this, but its still not right.

    'READ TIME DATA IN FROM DS1305
    DS1305_READ:
    High CE
    DelayCS 1
    SSP1IF = 0
    SSPBUF = INDEX
    Repeat
    Until
    SSP1IF = 0
    For INDEX = 0 To 5
    SSP1IF = 0
    SSPBUF = INDEX
    Repeat
    Until
    SSP1IF = 0
    Repeat
    Until
    SSP1IF = 1
    GetTIME[INDEX] =
    SSPBUF
    SSP1IF = 0
    Next INDEX
    Low CE
    Return

  8. #7
    Licensed User Roshan's Avatar
    Join Date
    Oct 2003
    Location
    India
    Posts
    478


    Default Re: Ds1305

    use shin & shout command to read & write.

    it is software based spi communication, but works perfect.
    ROSHAN
    Still have to Learn

  9. #8
    Licensed User pic-ignorant's Avatar
    Join Date
    Oct 2007
    Location
    Sunny Kent
    Posts
    2,125


    Default Re: Ds1305

    thank you Roshan,
    do you have some example code?

  10. #9
    Licensed User pic-ignorant's Avatar
    Join Date
    Oct 2007
    Location
    Sunny Kent
    Posts
    2,125


    Default Re: Ds1305

    I have got the minutes working, but not reliably. Once I get them running they are ok. However, on a reset it doesnt always start counting. I'm wondering if using a breadboard might be a problem? the xtal is soldered directly onto pins 3 & 4

  11. #10
    Licensed User pic-ignorant's Avatar
    Join Date
    Oct 2007
    Location
    Sunny Kent
    Posts
    2,125


    Default Re: Ds1305

    I finally go this working with the hardware MSSP module in SPI mode. I was trying to write the the config reg and clear the write protect in 1 go. It needs to be written to first, then clear it.
    I've searched the web, there isnt a lot of useful code in Basic format. I will fully comment the code, and post it here tomorrow, but now its Miller time!

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Crystal for DS1305 RTC
    By analogdevice in forum The Lounge
    Replies: 27
    Last Post: 28th September 2009, 09:33

Members who have read this thread since 15th March 2012, 13:54 : 1

Actions :  (Set Date)  (Clear Date)

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