Programming RTC DS1302 on PPDM
StephenMoore
Posts: 188
I am having a hard time getting a response out of the clock chip on my PPDM. I use the following with the SPI_Asm and Full DuplexSerial objects:
All I get are zeros for data:
Can anyone help?
All I get are zeros for data:
{{ ************************************************ * Propeller SPI Assembly Demo v1.0 * * Author: Beau Schwabe * * Copyright (c) 2009 Parallax * * See end of file for terms of use. * ************************************************ }} CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 OBJ SPI : "SPI_Asm" ''The Standalone SPI Assembly engine Ser : "FullDuplexSerial" ''Used in this DEMO for Debug CON ' DS1302 command definitions readSec = $81 readMin = $83 readHr = $85 readDate = $87 readMonth = $89 readDay = $8B readYear = $8D readWP = $8F readTCS = $91 readRAM = $C1 ' RAM from $C1 to $FD writeSec = $80 writeMin = $82 writeHr = $84 writeDate = $86 writeMonth= $88 writeDay = $8A writeYear = $8C writeWP = $8F writeTCS = $91 writeRAM = $C1 ' RAM from $C0 to $FC readClockBurst = $BF readRAMBurst = $FF writeClockBurst = $BE writeRAMBurst = $FE PUB SPI_DEMO|DQ,CLK,RESET,ClockDelay,ClockState,Sec,Minute,Hr {{ Once the 'SPI.start' command is called from Spin, it will remain running in its own COG. If the SHIFTIN or SHIFTOUT command are called with 'Bits' set to Zero, then the COG will shut down. Another way to shut the COG down is to call the 'SPI.stop' command from Spin. -------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------- DS1302 comm program -------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------- }} '' -----[ Initialization ]-------------------------------------------------- ''Serial communication Setup Ser.start(31, 30, 0, 9600) '' Initialize serial communication to the PC through the USB connector '' To view Serial data on the PC use the Parallax Serial Terminal (PST) program. ''SPI Setup ''SPI.start(ClockDelay, ClockState) SPI.start(15, 1) '' Initialize SPI Engine with Clock Delay of 15 and Clock State of 1 ''DS1302 Setup DQ := 0 '' Set DS1302 Data Pin CLK := 1 '' Set DS1302 Clock Pin Reset := 2 '' Set DS1302 Reset Pin waitcnt(clkfreq * 3 +cnt) Ser.str(string("DS1302 clock")) Ser.tx(13) Ser.tx(13) ' -----[ Program Code ]---------------------------------------------------- repeat HIGH(Reset) '' alert the DS1302 SPI.SHIFTOUT(DQ, CLK, SPI#LSBPRE , 8, readSec) '' Request to read the time Sec := SPI.SHIFTIN(DQ, CLK, SPI#LSBPOST, 8) '' read the time LOW(Reset) '' release the DS1302 Sec := Sec & $0F '' mask seconds value Ser.str(string("Seconds = ")) Ser.dec(Sec) Ser.tx(13) waitcnt(clkfreq + cnt) PUB HIGH(Pin) dira[Pin]~~ outa[Pin]~~ PUB LOW(Pin) dira[Pin]~~ outa[Pin]~ {{ ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ TERMS OF USE: MIT License │ ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation │ │files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, │ │modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software│ │is furnished to do so, subject to the following conditions: │ │ │ │The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.│ │ │ │THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE │ │WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR │ │COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │ │ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │ └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ }}
Can anyone help?
Comments
Good luck.
Hope this helps.
Thank you for taking the time to help.
SM