Has anyone used the DS1306 before and do you have a working Demo Code that I co
sam_sam_sam
Posts: 2,286
·Hi Every One
I order some free samples and I get them in a few days
Has anyone used the DS1306 before
Dose·anyone ·have a working Demo Code that I could use for this Time Chip
Or a link to a post that was posted before
Here is the link to the Data Sheet for this Chip
http://datasheets.maxim-ic.com/en/ds/DS1306.pdf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 3/29/2008 1:54:39 AM GMT
I order some free samples and I get them in a few days
Has anyone used the DS1306 before
Dose·anyone ·have a working Demo Code that I could use for this Time Chip
Or a link to a post that was posted before
Here is the link to the Data Sheet for this Chip
http://datasheets.maxim-ic.com/en/ds/DS1306.pdf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 3/29/2008 1:54:39 AM GMT
Comments
- - - 8< - - -
' DS2306_RTC.BSP
' {$PBASIC 2.5}
' This program programs a DS1306 RTC to generate interrupts on pin
' 11 once every second. It then polls pin 11 for a low state, which
' signals that a second has passed. The program then reads the time
' and date from the RTC and shows them in the debug window.
' Finally, it clears the interrupt flag, and waits until another
' second has passed and repeats the process.
' {$STAMP BS2p}
CE PIN 8 ' DS1306 Chip Enable, pin 10
SCLK PIN 9 ' DS1306 Synchronous Clock, pin 11
SDIO PIN 10 ' DS1306 Serial Data In/Out, pins 12 and 13
INT0 PIN 11 ' DS1306 Interrupt 0, pin 5
RdSec CON $00
RdMin CON $01
RdSecAlarm0 CON $07
RdTrChrgReg CON $11
RdUserRAM0 CON $20
WrSec CON $80
WrSecAlarm0 CON $87
WrCtrlReg CON $8F
WrStatReg CON $90
WrTrChrgReg CON $91
WrUserRAM0 CON $A0
Seconds VAR BYTE ' All in BCD(!) format
Minutes VAR BYTE
Hours VAR BYTE ' Bit 6 selects between 12/24h mode
Day VAR BYTE ' 1-7, 1:Sunday, 2:Monday, 3:..
Date VAR BYTE
Month VAR BYTE
Year VAR BYTE
Init:
Seconds = $45 ' Set time and date to 02:03:45 21/01/09
Minutes = $03
Hours = $02
Day = $4
Date = $21
Month = $01
Year = $09
GOSUB Conf_RTC
Main:
DO
IF INT0 = 0 THEN
GOSUB Get_Time
DEBUG HOME, HEX2 Hours, ":", HEX2 Minutes, ":", HEX2 Seconds
DEBUG HOME, CR, HEX2 Date, "/", HEX2 Month, "/", HEX2 Year
GOSUB Reset_INT0
ENDIF
LOOP
END
'
Subroutines
Conf_RTC:
HIGH CE
SHIFTOUT SDIO, SCLK, LSBFIRST, [noparse][[/noparse]WrCtrlReg]
SHIFTOUT SDIO, SCLK, LSBFIRST, [noparse][[/noparse]%00000000] ' Disable WP, 1Hz, AIE0 and AEI1
LOW CE
PAUSE 1
HIGH CE
SHIFTOUT SDIO, SCLK, LSBFIRST, [noparse][[/noparse]WrSec]
SHIFTOUT SDIO, SCLK, LSBFIRST, [noparse][[/noparse]Seconds]
SHIFTOUT SDIO, SCLK, LSBFIRST, [noparse][[/noparse]Minutes]
SHIFTOUT SDIO, SCLK, LSBFIRST, [noparse][[/noparse]Hours]
SHIFTOUT SDIO, SCLK, LSBFIRST, [noparse][[/noparse]Day]
SHIFTOUT SDIO, SCLK, LSBFIRST, [noparse][[/noparse]Date]
SHIFTOUT SDIO, SCLK, LSBFIRST, [noparse][[/noparse]Month]
SHIFTOUT SDIO, SCLK, LSBFIRST, [noparse][[/noparse]Year]
LOW CE
PAUSE 1
' HIGH CE
' SHIFTOUT SDIO, SCLK, LSBFIRST, [noparse][[/noparse]WrTrChrgReg] ' Select Trickle Charge Register
' SHIFTOUT SDIO, SCLK, LSBFIRST, [noparse][[/noparse]%10100101] ' Select 1 diode, 2k resistor
' LOW CE
' PAUSE 1
HIGH CE
SHIFTOUT SDIO, SCLK, LSBFIRST, [noparse][[/noparse]WrSecAlarm0] ' Generate INTO every second:
SHIFTOUT SDIO, SCLK, LSBFIRST, [noparse][[/noparse]%10000000] ' Alarm seconds, set mask bit
SHIFTOUT SDIO, SCLK, LSBFIRST, [noparse][[/noparse]%10000000] ' Alarm minutes, set mask bit
SHIFTOUT SDIO, SCLK, LSBFIRST, [noparse][[/noparse]%10000000] ' Alarm hours, set mask bit
SHIFTOUT SDIO, SCLK, LSBFIRST, [noparse][[/noparse]%10000000] ' Alarm days, set mask bit
LOW CE
PAUSE 1
HIGH CE
SHIFTOUT SDIO, SCLK, LSBFIRST, [noparse][[/noparse]WrCtrlReg]
SHIFTOUT SDIO, SCLK, LSBFIRST, [noparse][[/noparse]%00000001] ' Enable AIE0 (INT0)
LOW CE
PAUSE 1
RETURN
Get_Time:
HIGH CE
SHIFTOUT SDIO, SCLK, LSBFIRST, [noparse][[/noparse]RdSec] ' Prepare to read time and date..
SHIFTIN SDIO, SCLK, MSBFIRST, [noparse][[/noparse]Seconds]
SHIFTIN SDIO, SCLK, MSBFIRST, [noparse][[/noparse]Minutes]
SHIFTIN SDIO, SCLK, MSBFIRST, [noparse][[/noparse]Hours]
SHIFTIN SDIO, SCLK, MSBFIRST, [noparse][[/noparse]Day]
SHIFTIN SDIO, SCLK, MSBFIRST, [noparse][[/noparse]Date]
SHIFTIN SDIO, SCLK, MSBFIRST, [noparse][[/noparse]Month]
SHIFTIN SDIO, SCLK, MSBFIRST, [noparse][[/noparse]Year]
LOW CE
PAUSE 1
RETURN
Reset_INT0:
HIGH CE
SHIFTOUT SDIO, SCLK, LSBFIRST, [noparse][[/noparse]RdSecAlarm0] ' Reset IRQF0 (INT0 flag)
LOW CE
PAUSE 1
RETURN
- - - 8< - - -
A few comments about the code:
- I used a BS2p24, but any BS2 should do. Having said that, the BS2p does have some handy features, like the POLLWAIT command, which allows the BS2p to go to sleep between polling for the 1-second interrupt.
- I made use of 3-wire mode instead of SPI. This saves a BS2 pin. Both single and burst mode are used.
- I had a 5.5V 0.47F supercap as backup power for the DS1306. The latter's trickle charger needed to be programmed. The relevant code is included, but commented out.
Hope this helps.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
Right. The source is attached.
SRLM:
Sure, the DS1306 needs an external·32.768kHz watch crystal.·It's also·important not to forget·the pull-up resistor on the INT0 pin, which is an open-drain output.