1302 vs 1307?
I'm collecting parts for my Proto board and wanted to ask those who know if there is a preference for
the real time clock chip? Parralax stocks the 1302, but most examples I've seen are for the 1307.
Are they code compatible?
Any serious differences?
Thanks
Richard
the real time clock chip? Parralax stocks the 1302, but most examples I've seen are for the 1307.
Are they code compatible?
Any serious differences?
Thanks
Richard
Comments
http://www.8051projects.net/forum-t8997.html
You can Google 'DS1302 versus DS1307' for more discussions.
Personally, I would use the 1-wire I-Button RTO unit as it has an internal battery that is supposed to provide 10 years service and uses only one pin for i/o.
Both the 1307 & 1337 are 3.3v compatible (i2c is open drain). The 1307 requires 5v vcc, but that's no problem with the Protoboard.
As for code compatibility - I can't speak for 1302-1307, but for the 1338 I took Kye's 1307 driver and modified it.
Obivoulsy the I2C commands are the same, but the RAM addresses and control registers are different.
The 1302 is not code compatible with the 1307. I recently took Kye's 1307 driver and modified it for 1302. As I finally finished by SD card adapter over Thanksgiving. I'm using the 1302 that is built into Parallax's Propeller Professional Development Board.
Basically I took code from one of the OBEX 1302 objects and adopted it to Kye's 1307 interface.
I need to go back and add support for burst mode. I dropped it just to get the code to work...
Jay
One of my intended projects is a "ships bell" function.
So a custom board will be used in the end.
Not needing the 5v supply might be a plus.
I'll dig into the 1338 as well.
Thanks for your consideration.
Bruce Prager
Here's my modified code "as is"
''┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ ''│ DS1302 Real Time Clock Engine │ ''│ │ ''│ Author: Jay B. Harlow │ ''│ Updated: 11/27/2010 │ ''│ Designed For: P8X32A @ 80Mhz │ ''│ Version: 1.0 │ ''│ │ ''│ Copyright (c) 2010 Jay B. Harlow │ ''│ See end of file for terms of use. │ ''│ │ ''│ Update History: │ ''│ │ ''│ v1.0 - Original release - 11/27/2010. │ ''│ │ ''│ Modified version of Kwabena W. Agyeman's DS1307 Real Time Clock Engine │ ''│ │ ''│ For each included copy of this object only one spin interpreter should access it at a time. │ ''│ │ ''│ Jay, │ ''└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ CON #1, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday #1, January, February, March, April, May, June, July, August, September, October, November, December CON #0, secondsRegister, minutesRegister, hoursRegister, daysRegister, monthsRegister, dayOfWeekRegister, yearsRegsiter, _ctrl, _tc, #31, _burst VAR byte time[7] byte datar PUB checkSecond '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ '' │ Returns the cached second (0 - 59) from the real time clock. │ '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ return time[secondsRegister] PUB checkMinute '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ '' │ Returns the cached minute (0 - 59) from the real time clock. │ '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ return time[minutesRegister] PUB checkHour '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ '' │ Returns the cached hour (0 - 23) from the real time clock. │ '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ return time[hoursRegister] PUB checkDay '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ '' │ Returns the cached day (1 - 7) from the real time clock. │ '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ return time[dayOfWeekRegister] PUB checkDate '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ '' │ Returns the cached date (1 - 31) from the real time clock. │ '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ return time[daysRegister] PUB checkMonth '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ '' │ Returns the cached month (1 - 12) from the real time clock. │ '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ return time[monthsRegister] PUB checkYear '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ '' │ Returns the cached year (2000 - 2099) from the real time clock. │ '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ return time[yearsRegsiter] + 2000 PUB checkMeridiemHour '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ '' │ Returns the meridiem cached hour (12 - 11) from the real time clock. │ '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ result := (checkHour // 12) ifnot(result) result += 12 PUB checkMeridiemTime '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ '' │ Returns true if the meridiem cached hour is post meridiem and false if the meridiem cached hour is ante meridiem. │ '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ return (checkHour => 12) PUB checkTime '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ '' │ Caches the current real time clock settings. Returns true on success and false on failure. │ '' │ │ '' │ Call "checkSecond" to get the real time clock second after calling this function first. │ '' │ Call "checkMinute" to get the real time clock minute after calling this function first. │ '' │ Call "checkHour" to get the real time clock hour after calling this function first. │ '' │ Call "checkDay" to get the real time clock day after calling this function first. │ '' │ Call "checkDate" to get the real time clock date after calling this function first. │ '' │ Call "checkMonth" to get the real time clock month after calling this function first. │ '' │ Call "checkYear" to get the real time clock year after calling this function first. │ '' │ Call "checkMeridiemHour" to get the real time clock meridiem hour after calling this function first. │ '' │ Call "checkMeridiemTime" to get the real time clock meridiem time after calling this function first. │ '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ time[yearsRegsiter] := bcd2bin( readClock( yearsRegsiter ) ) ' year time[dayOfWeekRegister] := bcd2bin( readClock( dayOfWeekRegister ) ) ' day time[monthsRegister] := bcd2bin( readClock( monthsRegister ) ) ' month time[daysRegister] := bcd2bin( readClock( daysRegister ) ) ' date time[hoursRegister] := bcd2bin( readClock( hoursRegister ) ) ' hour time[minutesRegister] := bcd2bin( readClock( minutesRegister ) ) ' minute time[secondsRegister] := bcd2bin( readClock( secondsRegister ) ) ' second return true PUB changeTime(second, minute, hour, day, date, month, year) '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ '' │ Changes the current real time clock time settings. Returns true on success and false on failure. │ '' │ │ '' │ Second - Number to set the second to between 0 - 59. │ '' │ Minute - Number to set the minute to between 0 - 59. │ '' │ Hour - Number to set the hour to between 0 - 23. │ '' │ Day - Number to set the day to between 1 - 7. │ '' │ Date - Number to set the date to between 1 - 31. │ '' │ Month - Number to set the month to between 1 - 12. │ '' │ Year - Number to set the year to between 2000 - 2099. │ '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ writeClock( yearsRegsiter, bin2bcd( ((year <# 2099) #> 2000) - 2000 ) ) writeClock( dayOfWeekRegister, (day <# 7) #> 1 ) writeClock( monthsRegister, bin2bcd( (month <# 12) #> 1) ) writeClock( daysRegister, bin2bcd( (date <# 31) #> 1) ) writeClock( hoursRegister, bin2bcd( (hour <# 23) #> 0) ) writeClock( minutesRegister, bin2bcd( (minute <# 59) #> 0) ) writeClock( secondsRegister, bin2bcd( (second <# 59) #> 0) ) return true PUB checkSRAM(index) '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ '' │ Returns the selected SRAM value at the specified index on sucess and false on failure. │ '' │ │ '' │ Index - The byte location in SRAM to check. (0 - 30). │ '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ return readRam((index <# 30) #> 0) PUB changeSRAM(index, value) '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ '' │ Changes the selected SRAM value at the specified index to the specified value. │ '' │ │ '' │ Returns true on success and false on failure. │ '' │ │ '' │ Index - The byte location in SRAM to change. (0 - 30). │ '' │ Value - The value to change the byte location to. (0 - 255). │ '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ writeRam((index <# 30) #> 0, (value <# 255) #> 0) PUB pauseForSeconds(number) '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ '' │ Pauses execution for a number of seconds. │ '' │ │ '' │ Number - Number of seconds to pause for between 0 and 2,147,483,647. │ '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ result := cnt repeat (number #> 0) result += clkfreq waitcnt(result) PUB pauseForMilliseconds(number) '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ '' │ Pauses execution for a number of milliseconds. │ '' │ │ '' │ Number - Number of milliseconds to pause for between 0 and 2,147,483,647. │ '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ result := cnt repeat (number #> 0) result += (clkfreq / 1000) waitcnt(result) PUB RTCEngineStart(dataPinNumber, clockPinNumber, chipEnablePinNumber) '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ '' │ Checks out a lock for the driver and changes the I2C Circuit pins. Returns true on success and false on failure. │ '' │ │ '' │ DataPinNumber - Pin to use to drive the IO data line circuit. │ '' │ ClockPinNumber - Pin to use to drive the SCLK clock line circuit. │ '' │ ChipEnablePinNumber - Pin to use to drive the CE clock line circuit. │ '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ RTCEngineStop dataPin := ((dataPinNumber <# 31) #> 0) clockPin := ((clockPinNumber <# 31) #> 0) chipEnablePin := ((chipEnablePinNumber <# 31) #> 0) if((dataPin <> clockPin) and (clockPin <> chipEnablePin) and (chipver == 1)) lockNumber := locknew result or= ++lockNumber dira[chipEnablePin]~~ 'configure chip enable pin outa[chipEnablePin]~ dira[clockPin]~~ 'configure clock pin outa[clockPin]~ PUB RTCConfig writeClock(_ctrl, 0) 'clear write-protect bit writeClock(secondsRegister, readClock(secondsRegister) & %0111_1111) 'clear halt bit writeClock(hoursRegister, readClock(hoursRegister) & %0111_1111) 'set 24hr mode writeClock(_tc, 0) 'disable trickle charger PUB RTCEngineStop '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ '' │ Returns the lock used by the driver. │ '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ if(lockNumber) lockret(-1 + lockNumber~) PRI setLock ' 3 Stack Longs repeat while lockset (lockNumber - 1) PRI clearLock ' 3 Stack Longs lockclr (lockNumber - 1) PRI readClock(register) return read(constant((1<<7) + (0<<6)) + (register<<1) + 1) PRI writeClock(register, data) write(constant((1<<7) + (0<<6)) + (register<<1) + 0, data) PRI readRam(register) return read(constant((1<<7) + (1<<6)) + (register<<1) + 1) PRI writeRam(register, data) write(constant((1<<7) + (1<<6)) + (register<<1) + 0, data) PRI read( cmd ) 'Read a byte of data per command byte setLock outa[chipEnablePin]~~ writeByte( cmd ) dira[dataPin]~ 'set to input readByte outa[chipEnablePin]~ clearLock return(datar) PRI write( cmd, data ) 'Write a byte of data per cmd byte setLock outa[chipEnablePin]~~ writeByte( cmd ) writeByte( data ) outa[chipEnablePin]~ clearLock PRI readByte | i datar~ repeat i from 0 to 7 if ina[dataPin] == 1 datar |= |< i ' set bit outa[clockPin]~~ outa[clockPin]~ PRI writeByte( cmd ) | i dira[dataPin]~~ 'set to output repeat i from 0 to 7 outa[dataPin] := cmd outa[clockPin]~~ cmd >>= 1 outa[clockPin]~ PRI bin2bcd(dataIn) : result | tmp 'Convert a byte of binary data to binary coded decimal tmp:= dataIn/10 result := dataIn - ( tmp * 10 ) + ( tmp << 4 ) return result PRI bcd2bin(dataIn) : result 'Convert a byte of binary coded decimal data to binary result := (dataIn & %00001111) + ((dataIn >> 4) & %00001111)*10 return result DAT ' //////////////////////Variable Array///////////////////////////////////////////////////////////////////////////////////////// dataPin byte 29 ' Default data pin. clockPin byte 28 ' Default clock pin. chipEnablePin byte 27 ' Default chip enable pin. lockNumber byte 00 ' Driver lock number. DAT ''┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ ''│ 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. │ ''└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
I modified it to the point of getting to work, I haven't flushed it out enough to warrent posting it to the OBEX...
Jay