Shop OBEX P1 Docs P2 Docs Learn Events
need help with SERIN for DS1302 application — Parallax Forums

need help with SERIN for DS1302 application

ArchiverArchiver Posts: 46,084
edited 2004-07-22 15:39 in General Discussion
Hi everyone,
I'm working on my voice-activated clock design. Basically, it has a
voice chip, a basic stamp 2 and a time chip DS1302. I'm trying to
send the time data (in hex) into the BS2+DS1302 to reset the time of
the clock. This is the code that I use:

Loop0:
SERIN 4, 84, [noparse][[/noparse]HEX1 Hours.HIGHNIB, HEX1 Hours.LOWNIB, HEX1
Minutes.HIGHNIB, HEX1 Minutes.LOWNIB]
Temp = Hours
RTCCmd = HrsReg
GOSUB WriteRTC
Temp = Minutes
RTCCmd = MinReg
GOSUB WriteRTC
DEBUG HEX2 Hours,":", HEX2 Minutes
GOTO Loop0

WriteRTC:
'Write to DS1202 RTC
HIGH RTCReset
SHIFTOUT Dta, Clk, LSBFIRST, [noparse][[/noparse]%0\1,RTCCmd\5,%10\2,Temp]
LOW RTCReset
RETURN

But seems like the BS2+DS1302 doesn't recognize the time data
transferred in.
I'm new to PBasic, I would really appreciate any help/idea.
Thanks.

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2004-07-22 11:25
    In a message dated 7/22/2004 10:09:00 AM Eastern Daylight Time,
    allan.lane@h... writes:


    > The 1302 uses 'BCD' -- that is binary coded decimal.
    > This means the HEX value it accepts goes from
    > 0x00 to 0x09, then 0x10 through 0x19. So you have
    > to convert from binary to BCD.

    I use nothing but HEX - no BCD - and my 1302 works just fine.

    Sid

    >
    >



    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2004-07-22 13:07
    We have working DS1302 code in several places at Parallax. StampWorks
    is the first place that comes to mind for me.

    -- Jon Williams
    -- Applications Engineer, Parallax
    -- Dallas Office


    Original Message
    From: amser99 [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=Fi0yTvdk0RF6xRYc7B-VxRmNjW70_45Ry3KBNJp3gf680nm_Pfya80lmBr4DRd69Us6XuwRlbH8W]amser99@y...[/url
    Sent: Wednesday, July 21, 2004 11:16 PM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] need help with SERIN for DS1302 application


    Hi everyone,
    I'm working on my voice-activated clock design. Basically, it has a
    voice chip, a basic stamp 2 and a time chip DS1302. I'm trying to
    send the time data (in hex) into the BS2+DS1302 to reset the time of
    the clock. This is the code that I use:

    Loop0:
    SERIN 4, 84, [noparse][[/noparse]HEX1 Hours.HIGHNIB, HEX1 Hours.LOWNIB, HEX1
    Minutes.HIGHNIB, HEX1 Minutes.LOWNIB]
    Temp = Hours
    RTCCmd = HrsReg
    GOSUB WriteRTC
    Temp = Minutes
    RTCCmd = MinReg
    GOSUB WriteRTC
    DEBUG HEX2 Hours,":", HEX2 Minutes
    GOTO Loop0

    WriteRTC:
    'Write to DS1202 RTC
    HIGH RTCReset
    SHIFTOUT Dta, Clk, LSBFIRST, [noparse][[/noparse]%0\1,RTCCmd\5,%10\2,Temp]
    LOW RTCReset
    RETURN

    But seems like the BS2+DS1302 doesn't recognize the time data
    transferred in.
    I'm new to PBasic, I would really appreciate any help/idea. Thanks.
  • ArchiverArchiver Posts: 46,084
    edited 2004-07-22 14:47
    Using HEX1 as a SERIN modifier tells SERIN to treat the incoming
    byte as an ASCII representation of a hexadecimal digit (as opposed
    to a hexadecimal digit), and to convert and store accordingly. Is
    that consistent with what your external device is sending?

    I'd suggest a couple of DEBUG statements after the SERIN so you can
    see what values are actually stuffed into your Hours and Minues
    variables.

    You could also try storing some hard-coded, you-pick-em values into
    the '1302's hours and minutes registers to see if they are
    stored and reported correctly.

    Without seeing the rest of your program (variable declarations, etc.)
    it's hard to divine where things may be amiss.


    Regards,

    Steve

    On 22 Jul 04 at 4:15, amser99 wrote:

    > Hi everyone,
    > I'm working on my voice-activated clock design. Basically, it has a
    > voice chip, a basic stamp 2 and a time chip DS1302. I'm trying to
    > send the time data (in hex) into the BS2+DS1302 to reset the time of
    > the clock. This is the code that I use:
    >
    > Loop0:
    > SERIN 4, 84, [noparse][[/noparse]HEX1 Hours.HIGHNIB, HEX1 Hours.LOWNIB, HEX1
    > Minutes.HIGHNIB, HEX1 Minutes.LOWNIB]
    > ...
  • ArchiverArchiver Posts: 46,084
    edited 2004-07-22 15:03
    Check out the ds1302.bs2 file in the 'files' area.
    It has a complete and working program for using
    the 1302.

    Gotchas: the 1302 uses SHIFTIN/SHIFTOUT to send data,
    you MUST use the correct MSBFIRST settings.

    The 1302 uses 'BCD' -- that is binary coded decimal.
    This means the HEX value it accepts goes from
    0x00 to 0x09, then 0x10 through 0x19. So you have
    to convert from binary to BCD.

    (in other words, a decimal value of '10' is stored
    in the BS2 as 0x0A. You have to convert that to
    0x10 before sending it to the 1302.)

    --- In basicstamps@yahoogroups.com, "amser99" <amser99@y...> wrote:
    > Hi everyone,
    > I'm working on my voice-activated clock design. Basically, it has a
    > voice chip, a basic stamp 2 and a time chip DS1302. I'm trying to
    > send the time data (in hex) into the BS2+DS1302 to reset the time
    of
    > the clock. This is the code that I use:
    >
    > Loop0:
    > SERIN 4, 84, [noparse][[/noparse]HEX1 Hours.HIGHNIB, HEX1 Hours.LOWNIB, HEX1
    > Minutes.HIGHNIB, HEX1 Minutes.LOWNIB]
    > Temp = Hours
    > RTCCmd = HrsReg
    > GOSUB WriteRTC
    > Temp = Minutes
    > RTCCmd = MinReg
    > GOSUB WriteRTC
    > DEBUG HEX2 Hours,":", HEX2 Minutes
    > GOTO Loop0
    >
    > WriteRTC:
    > 'Write to DS1202 RTC
    > HIGH RTCReset
    > SHIFTOUT Dta, Clk, LSBFIRST, [noparse][[/noparse]%0\1,RTCCmd\5,%10\2,Temp]
    > LOW RTCReset
    > RETURN
    >
    > But seems like the BS2+DS1302 doesn't recognize the time data
    > transferred in.
    > I'm new to PBasic, I would really appreciate any help/idea.
    > Thanks.
  • ArchiverArchiver Posts: 46,084
    edited 2004-07-22 15:39
    To end the confusion -- or perhaps compound it -- BCD is a method of
    using four bits to represent a decimal digit, 0 - 9. To represent the
    decimal value 99 in BCD, it would be $99 -- the upper nibble is the tens
    digit; the lower nibble is the ones digit. So, in PBASIC we use the can
    use the HEX modifier for BCD values.

    Converstion (byte values, 0 - 99):

    bcdVal = (decVal / 10) << 4 + (decVal // 10)

    decVal = (bcdVal.NIB1 * 10) + bcdVal.NIB0


    -- Jon Williams
    -- Applications Engineer, Parallax
    -- Dallas Office



    Original Message
    From: Newzed@a... [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=IR9dPlTEEV3DWtLqga8d3hVS8IbdAYq4-JPfMhMLbMM5eRHAkI8E31T65suE0LYJbXk4q17Q_g]Newzed@a...[/url
    Sent: Thursday, July 22, 2004 9:25 AM
    To: basicstamps@yahoogroups.com
    Subject: Re: [noparse][[/noparse]basicstamps] Re: need help with SERIN for DS1302
    application


    In a message dated 7/22/2004 10:09:00 AM Eastern Daylight Time,
    allan.lane@h... writes:


    > The 1302 uses 'BCD' -- that is binary coded decimal.
    > This means the HEX value it accepts goes from
    > 0x00 to 0x09, then 0x10 through 0x19. So you have
    > to convert from binary to BCD.

    I use nothing but HEX - no BCD - and my 1302 works just fine.

    Sid
Sign In or Register to comment.