Shop OBEX P1 Docs P2 Docs Learn Events
Having trouble getting Seiko RTC working on Propeller DNA board — Parallax Forums

Having trouble getting Seiko RTC working on Propeller DNA board

Don MDon M Posts: 1,652
edited 2012-10-24 04:12 in Propeller 1
I have copied some of the code that Beau wrote for the Spinneret but can't seem to make it work. It just shows "Mon Jan 01, 2012 12:00:00 AM". Once it's started the clock counts up but I can't seem to set the time.

Here's my main code:
con

  _clkmode = xtal1 + pll16x
  _clkfreq = 80_000_000

  MS_001   = 80_000_000 / 1_000   

obj

  term   : "fullduplexserialplusdecn"                   ' for terminal output
  clock  : "s-35390A_GBSbuild_02_09_2011"               ' Seiko RTC driver
  
var

  long  MM_DD_YYYY, DW_HH_MM_SS
  byte  dig2[2] 
              
pub main  | d, l ,s

  term.start(31, 30, %0000, 115_200)                    ' start terminal (use PST)
  clock.start
  
  pause(1000)
  
  term.tx(0)

  term.str(@version)

  repeat
    d := term.rxcheck
    case d
      "c": SetClock
      "t": term.str(clock.FmtDateTime)
        term.tx(13)     

pub SetClock 

  Prompt(String("Enter year (2000-2099)"),true)
  MM_DD_YYYY[0] := getSerVal(4)
  Prompt(String("Enter month (01-12)"),true)
  MM_DD_YYYY[3] := getSerVal(2)
  Prompt(String("Enter date (01-31)"), true)
  MM_DD_YYYY[2] := getSerVal(2)
  Prompt(String("Enter day of week where 0=SUN 1=MON 2=TUE 3=WED 4=THU 5=FRI 6=SAT"), true)
  DW_HH_MM_SS[3] := getSerVal(1)
  Prompt(String("Enter hour 0-23 "),true)
  DW_HH_MM_SS[2] := getSerVal(2)
  Prompt(String("Enter minute (01-59)"),true)
  DW_HH_MM_SS[1] := getSerVal(2)
  DW_HH_MM_SS[0] := 0                                   ' Set seconds to 0
  
  clock.SetDateTime(byte[@MM_DD_YYYY][3],   { <- Month
                  } byte[@MM_DD_YYYY][2],   { <- Day
                  } word[@MM_DD_YYYY][0] - 2000,   { <- Year
                  } byte[@DW_HH_MM_SS][3],  { <- (day of week)
                  } byte[@DW_HH_MM_SS][2],  { <- Hour
                  } byte[@DW_HH_MM_SS][1],  { <- Minutes
                  } byte[@DW_HH_MM_SS][0])  { <- Seconds }
                       
  term.tx(13)
  term.str(clock.FmtDateTime)                       

pub getSerVal(lim) : value | bytesread, tmp, x, place

  term.RxFlush
  bytesread := 0
  value := 0
  place := 1
  
  repeat while bytesread < lim
    tmp := term.Rx
    if ((tmp == 10) OR (tmp ==13) OR (tmp == "*"))
      QUIT
    if (tmp => ("0")) and (tmp =< ("9"))  
      dig2[bytesread] := tmp
      bytesread++
  
  repeat x from (bytesread - 1) to 0
    value := value + ((dig2[x]-"0") * place)       
    place := place * 10        
                                                   
pub pause(ms) | t

  t := cnt
  repeat ms
    waitcnt(t += MS_001)

pri Prompt(msg, CR)

  term.str(msg)
  if CR
    term.tx(13)

dat

  version byte  "DNA Board Clock Play", 13, 0  




Any help appreciated.

Thanks
Don

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2012-10-23 16:32
    MM_DD_YYYY[3] := getSerVal(2)
    MM_DD_YYYY is a single long, any index you add to it will be treated as a long index (even though MM_DD_YYYY is not explicitly declared as an array). IOW fred[3] will access the long from address @fred + 12. If you want to access the individual bytes you should use MM_DD_YYYY.byte[3].

    For the year (occupying 2 bytes) use MM_DD_YYYY.word[0] instead.
  • Don MDon M Posts: 1,652
    edited 2012-10-24 04:12
    kuroneko wrote: »
    MM_DD_YYYY is a single long, any index you add to it will be treated as a long index (even though MM_DD_YYYY is not explicitly declared as an array). IOW fred[3] will access the long from address @fred + 12. If you want to access the individual bytes you should use MM_DD_YYYY.byte[3].

    For the year (occupying 2 bytes) use MM_DD_YYYY.word[0] instead.

    kuroneko- Thanks so much! As always you are a great help in learning this stuff.

    New code below:
    pub SetClock 
    
      Prompt(String("Enter year (2000-2099)"),true)
      MM_DD_YYYY.word[0] := getSerVal(4)
      Prompt(String("Enter month (01-12)"),true)
      MM_DD_YYYY.byte[3] := getSerVal(2)
      Prompt(String("Enter date (01-31)"), true)
      MM_DD_YYYY.byte[2] := getSerVal(2)
      Prompt(String("Enter day of week where 0=SUN 1=MON 2=TUE 3=WED 4=THU 5=FRI 6=SAT"), true)
      DW_HH_MM_SS.byte[3] := getSerVal(1)
      Prompt(String("Enter hour 0-23 "),true)
      DW_HH_MM_SS.byte[2] := getSerVal(2)
      Prompt(String("Enter minute (01-59)"),true)
      DW_HH_MM_SS.byte[1] := getSerVal(2)
      DW_HH_MM_SS.byte[0] := 0                                   ' Set seconds to 0
      
      clock.SetDateTime(byte[@MM_DD_YYYY][3],   { <- Month
                      } byte[@MM_DD_YYYY][2],   { <- Day
                      } word[@MM_DD_YYYY][0] - 2000,   { <- Year
                      } byte[@DW_HH_MM_SS][3],  { <- (day of week)
                      } byte[@DW_HH_MM_SS][2],  { <- Hour
                      } byte[@DW_HH_MM_SS][1],  { <- Minutes
                      } byte[@DW_HH_MM_SS][0])  { <- Seconds }
                           
      term.tx(13)
      term.str(clock.FmtDateTime)
      term.tx(13)                        
    
    
Sign In or Register to comment.