DS1302 RTC Driver
JBWolf
Posts: 405
I am having trouble finding a working driver for the DS1320 RTC I purchased from the parallax shop.
The driver resource links are to the now disabled old OBEX, and when I search github it returns just a mess of files that crosslink to other files that I cannot identify which is the correct associated one.
for example there are multiple spin files relying on other .c or .h files for which there are many of those all with the same name and no identifying header notes
The driver resource links are to the now disabled old OBEX, and when I search github it returns just a mess of files that crosslink to other files that I cannot identify which is the correct associated one.
for example there are multiple spin files relying on other .c or .h files for which there are many of those all with the same name and no identifying header notes
Comments
It contains all the spin files needed to Demo the DS1302.
The one sold be the parallax shop contains the battery and warns not to enable trickle charge or it will damage the unit
Yes, it does seem that the trickle charge has been turned on using 1 diode in the Demo code.
So I would change the diodeSel value from 1 to 0 to turn-off the Trickle charge.
I overlooked the warning in the DS1302 module's documentation that you noticed, so I didn't realize that the Demo code was turning on the trickle charge which it shouldn't for Parallax's DS1302 module.
I have been running an adaptation of this Demo code with a Parallax Flip Module, OLED Display, DS1302 module and 5-button switch since December 2019. I hadn't noticed any problems, but I went ahead and changed my code to keep the trickle charge off. [If you want a copy of my adapted code, let me know.]
So thank you, for noticing this and helping us both out...
so for turning off trickle charge in this code, should it be:
I've attached an archive of my code using the DS1302 as part of implementing an AC Fan Controller.
The file "AC_Controller.spin" is the main program in the archive.
I haven't finished the AC control/Relay part yet, but the Displaying and Setting of Time/Date is working, enjoy...
Would you be willing to post your schematic and or pictures of your controller?
Sure, I'll post something soon, it is a work in progress and I have been focusing on other things lately.
Thanks for posting your interactive driver for the DS1302 RTC.
I wish it was available a few months ago when I was integrating a RTC into a project.
I eventually used a DS3231, persuaded by the following online notes;
It would be very useful if you extended your interactive driver to cover the DS3231 and variants.
What's so good about the RV3028? Just read the info at the link. This is the chip I use on the P2D2 module and unless you knew what you were looking for your wouldn't spot it, neither the chip nor the supercap. BTW - I very rarely never use a battery to power an RTC. A supercap never leaks, explodes, or fails nor does it require a battery holder. If the unit is off power that long that the cap can no longer maintain power, then it must be out of service and so the clock would be reset in the workshop.
You've got me interested now...
Edited to add: I'm liking the RV3028 a lot. The only nit is the use of an internal crystal without any temperature compensation. The 1 ppm accuracy is at 25c and it falls-off with temperature. At the operational temperature limits of the chip that 1 ppm becomes 110-140 ppm, which is about the same drift as a DS1302 with a modern, garden-variety crystal. In real-world terms this gives the RV3028 a drift of ~12 seconds per day (73 mins/yr) under extreme conditions. In contrast the DS3231 does automatic active correction based on temperature, and the accuracy doesn't change much (like 2 ppm max across the entire temperature profile if I'm reading the data sheet right). So if very high accuracy over a wide temperature range is needed, the DS3231 is a better choice. But lacking that requirement, the RV3208 is about a third the cost of the DS and gives UNIX DT stamp as a bonus.
I ordered a couple from Mouser to play with. Thanks for posting this, Peter.
But the RV3028 is rock stable, I can come back to it days later in standby and it is spot on, and if plugged in for even a brief period, it is totally recharged. The I2C bus seems to work fine at 1MHz too although I normally do a block read of the first 7 bytes (RV3028 can latch 7 bytes internally) to access time & date in one hit rather than do multiple reads. In Tachyon on the P1 it has an RTC driver that handles all the most common I2C devices and basically does a read at boot time, then a general-purpose background task maintains that time in software, only refreshing it once every 24 hours. That way software does not have to wait for any I2C bus transfers, it just reads the time from memory or as a FAT32 or millisecond timestamp.
I can set the clock on my P2D2 from a Linux terminal even while the serial port is already being used by a serial terminal emulator, since it allows multiple write access to the device. This is my script and usage which resets the RTC time and date from Linux.
and this is how it looks on the serial terminal emulator.
Oh, I almost forgot, here is some interaction with the chip from TAQOZ.
TAQOZ is amazing. I havent even scratched the surface yet, but its very cool what you have done.
Ah, I wish I had a service, but until I know that the first few I do are right, there isn't much point, plus the run is too small and there aren't any margins, at least for these modules that are being sold to aid P2 development. Maybe with a larger production run and knowing that the design is stable I wouldn't have any hesitation in getting them assembled. I'm not doing this for business, that's for sure.
That shot was of a prototype I made up myself and I wasn't happy with the quality of the solder paste so I had gone around with the soldering iron touching it up.
simply trying to set the date/time and read out with basic display on pst to confirm its working.
ive tried every object in the github obex and the ones provided here. tried as is, also modified to strip down to basics... here the kind of output i keep getting
Your above code works fine on my DS1302 setup, I get the output below for July 26, 2020 11:16:xx. Granted my DS1302 was already initialized with the current Time & Date.
Your posted code only reads the current Time & Date from the DS1302, you don't have anything that actually sets the initial Time & Date values in the DS1302.
You need to add/use code like:
Now if you already used similar code as above to previously set your DS1302, perhaps your DS1302 is damaged or the battery isn't holding the DS1302 values between being powered-up.
Should all of these values for TC, diode & resist be 0?
Since the parallax module requires trickle charging to be set to OFF or face damage... I went with all 0's
here is the origional as per an obex module that used trickle set to on.
output is:
I am set to:
There certainly appears to be something wrong with your unit/setup. I ran your modified code and everything worked as it should, my DS1302 unit's time changed to the values you have stored.
I even tried adding rtc.write code to change the Config value to other settings and I can't duplicate what you are seeing.
At this point I don't have an answer other than you have some kind of hardware problem. To be thorough perhaps you should change the propeller pins you are using from 8,9,10 to another set of 3 pins, just to make sure that your propeller doesn't have pin problems. If nothing changes, then I guess your DS1302 is sick.
Figured it out... one of the original obex's said to use resistors between the the RTC and prop... they were the problem!
While changing to different pins as you suggested Francis, I left the resistors behind, it worked and so I removed the resistors and went back to the same old pins and it worked again.
It is now working as expected
Congratulations on finding the issue
@DaveJenson
I've attached a Schematic and other Images/documents about my AC_Controller. It is still a work in progress, eventually I'll get back to finishing it.
The eventual goal is to use Light & Temperature sensors and Time as trigger sources in controlling the turning ON/OFF of AC Devices like Fans.
Did you include the Dual Relay to control multiple AC devices?
Or do you need to break both "Hot" and "Neutral" to control them?
I planned to use the Dual Relay board mainly since that is what I have available in a reasonably small package. I also have one of Parallax's Digital I/O boards (#27113) that can have up to 8 Relays (mechanical or solid state), that could also be used as well if I needed more switching abilities.
But you are right, the Dual Relay could be used to either control two AC devices or break two lines on the same AC device.
We have an enclosed Sun/Patio room that frequently gets over 125 deg. F, so we have window fans to help move air from the outside into the inside to try and keep things cooler. I have had trouble finding good room/window fans (that last more than a year) that can automatically turn ON/OFF based upon Temperature. So the plan was to create my own AC controller that will have the ability to use a number of different triggers (i.e. Temperature, Time and/or Light Levels, in any combination) that I could plug-in any Fan. Of course the AC Controller could be used for other AC devices too.
Eventually once I get everything fully implemented in hardware/software, I'll post the finished project...