DS3231 is not accurate as it should be - Page 1
Forum section: electronics / beginners

author: Alptkn
author_rank: Newbie
timestamp: April 18, 2019, 06:41:16 pm
content: I have made a nixie clock with 4 digits (shows only hour & and minute) but is seems like it doesnt keep the time accurate as it should. Clock diviated +2 minutes after 3 days. In the datasheet it is stated:Accuracy ±2ppm from 0°C to +40°CAccuracy ±3.5ppm from -40°C to +85°CWhich to my calculation was about 1-2 min diviation in a year. (0°C to +40°C)I have few things on my mind that might cause this problem:1)I had two ds3231 chip and I desolder one from "DS3231 for pi" module, another I did bought from local electronics shop however I am not certain which one I did solder to the board. Maybe I did some damage when I desolder/solder (I dont exceed 320-330oC unless it isn't an IC ) and use that one in the board.2) In the code I read the time every time SQW pin changes the state (I set SQW pin to 1hz output) maybe reading time that often might cause same problem. However in this case I would except a decrease in time not increase in time. I considered this because these modules usualy have an eeprom on them. I did looked in web but I didnt see anything that mentions this kind of situation so I dont think reading time this often from ds3231 might cause problem...3) I have knock-off or a faulty ds3231 chip (which I am not even sure if it's possible or there is such thing) and it is simply way out of accuracy as it should be.4) I am using 5V adapter (wall plug adapter) to power the circuit it outputs 5.10V (acording to my Multimeter) but I am not sure about any ripple or noise, but I have a input cap (470uF) which should be getting rid of some noise from the adapter which I am sure it has some but not much (I hope)Other than these I dont have any idea what might cause a problem fell free to point them...First and third one can be solved by switching the ds3231 with the other one but I might need to wait couple of weeks to be sure so this one I dont want to try if there is another problemFor the 2. possible cause I will write another code that will read time from ds3231 every min, so that might solve my issue but as I said I am not hopefull about that oneLast one can be solved by 7805 regulator but I have to manually solder it some where in board and make changes and again confirm the accuracy by waiting few days or few weeks... (before sending to a pcb warehouse for some sample boards)Part of the schematic is in the attachments...Thanks in advance

author: rstofer
author_rank: Super Contributor
timestamp: April 18, 2019, 07:48:05 pm
content: Have you read up on the 'aging' register? You can change the internal crystal frequency. If you look at the graph on page 7. The chip is only accurate over a very narrow temperature band and even then the error can be quite sizable depending on the crystal accuracy. It's a real shame that the crystal is internal.BTW, the internal crystal can be damaged by physical shock - like dropping the chip on a workbench.https://datasheets.maximintegrated.com/en/ds/DS3231.pdfYou could do a decent job of calibrating the crystal if you had an accurate frequency counter. They do provide the 32 kHz output. You might also be able to do this by using an oscilloscope to watch the phase change between the internal oscillator and some external source that is known to be accurate.

author: floobydust
author_rank: Super Contributor
timestamp: April 18, 2019, 08:27:34 pm
content: A common mistake with the DS3231 is to run PCB traces under it.DS3231 datasheet:"Avoid running signal traces under the package, unless a ground plane is placed between the package and the signal line. All N.C. (no connect) pins must be connected to ground."High frequency noise from I2C (for example) couple to the internal crystal oscillator and the RTC ends up runningfast. Or nearby nixie boost converter EMI can also affect the part, depending on your circuit layout.edit: I see your boost converter is running off the +5V rail, so it sure to be very noisy.I would add an RC or LC filter for the 5V supply to the DS3231 to ensure it has clean power.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: April 18, 2019, 08:59:24 pm
content: I have a nixie clock with a very similar design and use components removed from cheapo DS3231 modules and have never had any issues. My design is almost identical in that I use SQW (although mine has a 10k pull-up on that line) in the same way... interrupt every second and then read the time from the module. I get accurate time, a few seconds over many months.Perhaps test your DS3231 with just an UNO as a sanity check.

author: Alptkn
author_rank: Newbie
timestamp: April 18, 2019, 09:23:41 pm
content: Well I didn't read up the ds3231 datasheet comprehensively to be honest because I switched to ds1307 to ds3231 couple of days before sending this board to pcb warehouse and I was thinking like "ow this one has internal calibrated osilator and better ppm accuracy let me slap that in here".However I will check 32khz output with my oscilloscope and try to correct it with "agging" register if thats the problem.But before that I should re-route the signals that goes under DS3231... Not sure if those (SDA and SQW) lines would make a problem but if it does reading time every second can definetly ruin the time accuracy. (Part of the board is in attachment). The boost converter is not really nearby and both (top layer ground doesn't show on attachment) layers are filled with ground plane where no signal traceses present. So I doubt that boost converter can couse that*.I will also check it with arduino but that might take a bit time since I throw the rest of the module away...I will look in to those details at work and write back thanks...edit: *Boost converter EMI. Noisy 5V rail: Yes might cause a problem.

author: rf-loop
author_rank: Super Contributor
timestamp: April 18, 2019, 09:43:01 pm
content: Is better also to note what version of DS3231 when talk about it. Specially today when peoples buy these modules from eBay (and not only from chinese sellers). Short time ago I have experience that most of modules are made using DS3231M (pin compatible butnot fully functionally compatibleandless accurate MEMS oscillator)Many eBay sellers description picture they still show DS3231SN but what you get is mostly DS3231M and same even if buy just these IC's.https://blog.heypete.com/2017/09/05/major-differences-between-the-ds3231-and-ds3231m-rtc-chips/Advantage with MEMS oscillator is that its shock resistance is better, so it can use some places where xtal versions may fail. But MEMS is less accurate.Then need also keep in mind how DS3231SN/M works and how it internally adjust related to temp. Short time accuracy may be lot of more bad than bit longer.

author: rstofer
author_rank: Super Contributor
timestamp: April 18, 2019, 10:36:06 pm
content: It appears that all 3 versions -S, -SN and -M are in stock at DigiKey and cost between $8 and $10 (rounded up). It is probably worth the time to compare the datasheets between the -S and -M versions. AFAICT, the -SN is covered by the -S datasheet.The -S and -SN are more accurate than the -M but the -M may be more rugged.I don't buy components from eBay or Chinese sources.

author: floobydust
author_rank: Super Contributor
timestamp: April 18, 2019, 10:45:15 pm
content: Quote from: Alptkn on April 18, 2019, 09:23:41 pmWhere are your decoupling capacitors for the RTC and MCU? I don't see any on 5V.A look inside the DS3231I could not see the crystal wiring but that would be susceptible to pulses on SDA or SCL.

author: wilfred
author_rank: Super Contributor
timestamp: April 18, 2019, 11:02:22 pm
content: I was reading this yesterday. RTC clock chips are susceptible to noise on PCB's. This App Note is for a different RTC chip but there's probably one for yours specifically too. But I imagine they are more alike than different in this regard.https://pdfserv.maximintegrated.com/en/an/AN58.pdfI'd start with disabling the HV powersupply and seeing if that changes anything. Set the time, switch off the HV supply circuit, come back in 24h and check the time. If it is good then you have the source of the problem.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: April 18, 2019, 11:08:41 pm
content: I have plenty of traces under mine and no issues. You should probably look more towards the supply side?

author: schmitt trigger
author_rank: Super Contributor
timestamp: April 18, 2019, 11:47:48 pm
content: I bought a DS3231 module from Adafruit, and employed it as a timebase in a binary clock of my own creation.I only update the module twice a year when the DST kicks in or out, and in the 3 years I've had it, the device has not yet drifted above 1 minute.I don't use SQW, I actually read the registers via I2C.

author: iMo
author_rank: Super Contributor
timestamp: April 19, 2019, 05:59:30 am
content: The DS3231 is the most precise RTC chip you can get. My 2 cheapo ebay modules (SN chip) did 1-2secs in 6 months.The reading the chip may introduce an issue when the "I2C reading sequence takes longer than 1sec", afaik. So if it is shorter it cannot cause issues even you read the chip a few times per second.Wire 100nF ceramics in parallel with 10u ceramics close to your chip's Vcc and GND.Doublecheck your software as well. Try with different libraries. I bet it is a sw bug.

author: Alptkn
author_rank: Newbie
timestamp: April 19, 2019, 02:45:28 pm
content: So far I found nasty ripple in the +5V rail and fixed it I put 7805 and couple of capasitors at output so +5V rail looks much better than before.I configured the ds3231 to output 8.192kHz signal at sqw pin and checked it with my osciloscope but, i figure there is no point to see accuracy of the frequency with my osciloscope.I did update the software now its reading the clock every 60sec and as before only necesary bits needed so this should eliminate unnecesary use of the I2C usage. (Next would be the try other librarys)Also I checked the markings on the IC as some of you suggested and one I am using is DS3231-SN variant other one is also SN variant.I am gonna let is sit for a day and see if there is any drift. I also check seconds so I will know if its drifted or not (when my PC second is at 38sec it displays the next min on my clock).If its drifted like min or so tomorow I will try disable the HV supply circuit and wait another day.Edit: attachment added.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: April 19, 2019, 02:49:59 pm
content: Quote from: Alptkn on April 19, 2019, 02:45:28 pmFWIW That's the same as mine.

author: iMo
author_rank: Super Contributor
timestamp: April 19, 2019, 02:54:14 pm
content: Quote from: Alptkn on April 19, 2019, 02:45:28 pmAlways sync your PC with the "internet time" before the measurements (as the PC clocks are not stable enough).

author: JackJones
author_rank: Regular Contributor
timestamp: April 19, 2019, 03:38:41 pm
content: If you bought them from ali/ebay they are 99% fake. (it's likely that this is the source for your local shop too) I bought a few from different sellers about a year ago and none of them functioned properly. I bought both modules and just the ICs themselves.Cheapest source I found for them was LCSC, something like 1.5€ a piece in small quantities. So far I've had no issues with them, they seem to be genuine.

author: Alptkn
author_rank: Newbie
timestamp: April 20, 2019, 06:45:29 am
content: Well clock is 4-5 min aheadAt this point I dont thing data line or noisy +5v rail supply is the cause of this, because it is worse than beforeand I think the chip is simply fake or HV supply EMI is effecting the chip.I am gonna order some ds3231 over lcsc. While they arrive I will isolate the HV supply...

author: iMo
author_rank: Super Contributor
timestamp: April 21, 2019, 12:41:40 pm
content: The SQW is an open-drain output. Try to wire a pullup there, for example 4k7.PS: when running with arduino libraries - youmustdo not have to read the external RTC once a second - there is a library (I think "Time") which includes a function for syncing the internal system "Time" with the external RTC "provider" with a sync period you may set as you wish.SeesetSyncProvider()setSyncInterval(time_t interval)Set it for 30minutes with a cheapo atmega crystal. It will run the system time for 30minutes based on the atmega's crystal and then it synces the system time with the RTC, and so on, and so on..

author: NivagSwerdna
author_rank: Super Contributor
timestamp: April 23, 2019, 10:27:07 am
content: Quote from: imo on April 21, 2019, 12:41:40 pmAs per the datasheet... needs a pull-up but you can potentially use the INPUT_PULLUP if using a digital pin which you are.Quote from: imo on April 21, 2019, 12:41:40 pmWhy not? That's exactly what I do.

author: Kjelt
author_rank: Super Contributor
timestamp: April 23, 2019, 11:20:49 am
content: Quote from: JackJones on April 19, 2019, 03:38:41 pmReally ? And I paid $0,73 forArduino DS3231 ZS042 AT24C32 IIC Module Precision RTC Real time Clock MemoryA pcb, DS3231, 4k Flash eprom, and passives, you would think it was legit for that price

author: Kjelt
author_rank: Super Contributor
timestamp: April 23, 2019, 11:25:23 am
content: Quote from: NivagSwerdna on April 23, 2019, 10:27:07 amMakes no sense to read it every second.You can only hang your I2C bus, block it for other traffic and cause noise for other components for what ?Your accuracy will not be higher then if you read it once a minute or so, esp if you calibrate the deviation of the clock of your processor once and correct for it.

author: iMo
author_rank: Super Contributor
timestamp: April 23, 2019, 11:28:07 am
content: Quote from: JackJones on April 19, 2019, 03:38:41 pmI can hardly imagine such an economy able to copy/fake almost all chips ever produced by all known chip manufacturers in last 50years..

author: Alptkn
author_rank: Newbie
timestamp: April 23, 2019, 11:41:43 am
content: I am using internal pullup for SQW pin. Which should do the trick. I did research in to the other forums related to the this subject (avrfreaks, forum.arduino etc.) and it seems like every one who had similar problem is due to the cheap ds3231 chips. I think they use QC fail IC on these cheap modules.I also switch the ds3231 with the other one I had in my inventory that one was also cheap, I did test this one about 36 hours and it has similar accuracy (2-3 min ahead as it should be) problems...To day I will test for the EMI; I will sync the ds3231 and leave the clock unpluged and let it run from the little battery which only powers ds3231. Day or two should reveal the drift.If I see a drift again I will wait for the chips from lcsc that I ordered maybe I will order couple from digikey mean while just to be sure.

author: iMo
author_rank: Super Contributor
timestamp: April 23, 2019, 11:52:18 am
content: The internal pullup is weak (ie 50k). It could pick up some noise and therefore it runs fast (because of false triggering).Try with 4k7. You may also wire a small capacitor (ie 1-10nF) from the 4k7 (SQW signal) to GND.You may also run a statistics - count the interrupts coming from the RTC and compare (or timestamp) it with your atmega's crystal time.With false SQW triggers you will see an irregular pattern.With "fast RTC" the pattern will be linear.PS: and it could help to show us your code. I still bet it is a sw bug..PPS: do create a simple sketch reading the RTC once a second (or any other period), get rid of all other stuff.The sketch shall send the RTC time via UART to your PC.

author: PA0PBZ
author_rank: Super Contributor
timestamp: April 23, 2019, 12:25:41 pm
content: Quote from: Alptkn on April 18, 2019, 06:41:16 pmQuote from: Alptkn on April 19, 2019, 02:45:28 pmSo what are you feeding the 7805? Surely the 5.1V from the adaptor is not enough.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: April 23, 2019, 12:53:06 pm
content: Quote from: Kjelt on April 23, 2019, 11:25:23 amDo you think the I2C bus would wear out?IMHO it's a perfectly plausible operating mode

author: Kjelt
author_rank: Super Contributor
timestamp: April 23, 2019, 01:32:31 pm
content: Quote from: NivagSwerdna on April 23, 2019, 12:53:06 pmWell in the past I had a lousy ST I2C peripheral which would indeed hang it self up now and then and you need to clock it loose again.But my point is that the I2C bus is usually a shared multi IC bus and you divide the time between them. In your case you probably have that single chip on it.A RTC is usually a NV backup clock you now and then use to sync your onboard clock to, or the RTC alarm out is also very usefull to save energy and let the uC sleep till it has to do something.Do you have at least sanity checks on your RTC data before you use them ? Or do you just blindly copy the data ?

author: NivagSwerdna
author_rank: Super Contributor
timestamp: April 23, 2019, 02:37:00 pm
content: I really don't want to defend the approach (although it does have an advantage of being simple and potentially allowing deep stateless sleep between wake-ups) rather I just wanted to say it does work (and especially where the bus is not contended as you pointed out). Indeed probably much better to use an MCU with an inbuilt RTC anyway.The reason I didn't like the earlier post regarding using the RTC to discipline the local clock was that I have seen cheapo Uno clones that use resonators that are >10% out so the drift is rapid and then it becomes a case of adjusting rate as well as offset which will only confuse new players.IMHO power droop is the OP's most likely problem as I've used quite a few cheapo DS3231 modules and never seen a problem. Labelling them as 'fake' sounds like clutching at straws... but I may be wrong...

author: floobydust
author_rank: Super Contributor
timestamp: April 24, 2019, 06:49:36 pm
content: DS3231S $7.87 at Digikey and from china $1.28 for entire pcb with DS3231, battery holder, connector, extra 24C32 EEPROM. You gotta wonder.

author: schmitt trigger
author_rank: Super Contributor
timestamp: April 24, 2019, 07:05:25 pm
content: If it is too good to be true;it can't true

author: floobydust
author_rank: Super Contributor
timestamp: April 24, 2019, 07:16:17 pm
content: This pcb $1.28 USD and 7,607 soldEither currency manipulation or Maxim's profit greed, or something I am missing prices the RTC IC alone at over 6X the price of this moduleEven a fake or reject RTC - you have to stuff a crystal in there, it's gonna be expensive. The majority of people find the cheap RTC works fine.

author: iMo
author_rank: Super Contributor
timestamp: April 24, 2019, 07:29:29 pm
content: https://hackaday.com/2017/08/09/get-inside-a-tcxo-clock-chip/https://blog.heypete.com/2017/07/29/a-look-inside-the-ds3231-real-time-clock/And yes, it is the greed of our lovely distributors..

author: johnkenyon
author_rank: Regular Contributor
timestamp: April 24, 2019, 10:40:32 pm
content: Quote from: floobydust on April 24, 2019, 07:16:17 pmIs that the special model which includes a (non-rechargeable) CR2032, but has the added bonus of a diode+resistor to charge up the battery?(I was offered that t-shirt, but I removed the diode before deploying the board...)

author: floobydust
author_rank: Super Contributor
timestamp: April 24, 2019, 11:03:03 pm
content: Quote from: johnkenyon on April 24, 2019, 10:40:32 pmYes, it has a bonus diode and 200R series to VCC, so I estimate ~7mA charging all the time...Other RTC module versions have a mystery yellow rechargeable battery.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: April 25, 2019, 08:50:47 am
content: I just desolder the DS3231 (hot air) and the battery holder (vacuum) and use in my own design. Works fine and cheaper than buying the battery holder.(The TTL to serial MAX232 clones are an entirely different kettle of fish... Those should not be touched with a barge polehttps://www.eevblog.com/forum/chat/fake-chips/msg1552951/#msg1552951)

author: iMo
author_rank: Super Contributor
timestamp: April 25, 2019, 10:01:14 am
content: Quote from: floobydust on April 24, 2019, 11:03:03 pmThere is no need to remove the 200ohm when powered from 3.3Vcc only. With 5Vcc I would rather remove the 200ohm resistor, sure.

author: tooki
author_rank: Super Contributor
timestamp: April 25, 2019, 10:05:37 am
content: Quote from: imo on April 24, 2019, 07:29:29 pmI don't think it's greed so much as it is the cost of overhead. Look at Digi-Key: they have over a million SKUsin stock. The warehousing costs for this, and the logistics to get a few units to you, are huge. (This is why the volume discounts become so large, since sending you an entire reel of 5000 takeslesseffort than counting out and repackaging 3 pieces.)In contrast, the Chinese eBay sellers typically stock around 1000 SKUs, and their labor costs are trivial. So their overhead ismassivelylower. Their module suppliers probably buy 100,000 chips at a time, getting huge discounts, and then sell them to a bunch of different eBay vendors.

author: iMo
author_rank: Super Contributor
timestamp: April 25, 2019, 10:09:23 am
content: Quote from: tooki on April 25, 2019, 10:05:37 amA good topic for a separate thread. It is the greed and cartels..

author: tooki
author_rank: Super Contributor
timestamp: April 25, 2019, 10:18:54 am
content: Quote from: imo on April 25, 2019, 10:09:23 amPerhaps. But I don't like how you just re-state that it's greed (and now cartels!) without providing any evidence or even arguments. I substantiated my claims, you didn't...

author: Kjelt
author_rank: Super Contributor
timestamp: April 25, 2019, 10:36:59 am
content: I am still unsure about all this.If you look at the maxim website they state a price around $4 for 1k pieces. No way that will drop to $0,20 for 100k pieces.https://www.maximintegrated.com/en/products/analog/real-time-clocks/DS3231.html/tb_tab3

author: tooki
author_rank: Super Contributor
timestamp: April 25, 2019, 10:59:37 am
content: Quote from: Kjelt on April 25, 2019, 10:36:59 amNot for us, for sure!!But I wouldn't be surprised at all if they used regional pricing. (And though I have no idea what the price break is for 100K, never mind for e.g. a million, I'm sure it's quite substantial.) Combined, those really could result in them being insanely cheap. :/

author: Kjelt
author_rank: Super Contributor
timestamp: April 25, 2019, 12:44:07 pm
content: Ok let me rephrase, if the published 1k price of the manufacturer is around $4, the prices for the distributors are not that outrageous as stated by some.

author: rf-loop
author_rank: Super Contributor
timestamp: April 25, 2019, 03:37:32 pm
content: Quote from: JackJones on April 19, 2019, 03:38:41 pmeBay China, various selers.All in around same ballpark, worst chip error near 2.5ppm.Tested in normal roomtemp and well stabilized.Here example. So I can not fully confirm this 99% crap. But of course, I have also get "crap" but in my case these all have been so that seller images and description have been DS3231SN but I have get SN3231M (and warning, today perhaps most are M versions independent of pictures in eBay) and these M have some been even far out from genuine M version 5ppm, some have been totally badly outside limits. (perhaps counterfeit or perhaps some use chips what have not passed tests or what ever...)But every sigle DS3231SN have been ok.Perhaps good luck or then I can bit look around from who I buy (experience and intuition).Here tiny example. 3pcs 3231 compared to accurate reference. (DS3231 pin 1 out (32kHz), also 64s period thermal correction works but I have not made real test because I do not have test owen)Traces drift "tails" length is 1second.

author: JackJones
author_rank: Regular Contributor
timestamp: April 25, 2019, 03:47:35 pm
content: The ones I got were DS3231SN. I did shop around too, I bought from sellers with good ratings and with several pieces sold. Yet all of them lost tens of seconds overnight.I soldered one that I got from LCSC into one of the breakout boards I got and it worked fine. I must have been just unlucky.

author: rf-loop
author_rank: Super Contributor
timestamp: April 25, 2019, 09:00:04 pm
content: Quote from: JackJones on April 25, 2019, 03:47:35 pmI do not even believe they are bad counterfeits. But possible failed chips. Perhaps some sell "abandoned lots".This your frequency error is so big that not even any poor copycat IC's can do it exept if it is failed. 10s/day is more than 100ppm error. This is possible if there is broken temperature measurement and/or failure on internal capacitor array or its control (what adjust XTAL freq) or bad xtal. If adjust system still works somehow it can detect with freq measurement and look if it do adjust every 64s when temperature is changing. And you tell error is even more, tens of seconds in day. Perhaps these ic's are "abandoned in tests" but somehow these bad lots turn back to bad business markets.It is also good to note that there is several eBay sellers who have many accounts. Many sellers they just deliver orders to some "grey warehouse - manufacturer", and many sellers use same source. Who can think all sellers days and nights make packages and then go to post office for send. Some do, many do not.Inside China with own eyes this "game" can understand better.My wild quess is that these are from failed IC's lot (abandoned in tests lot) .XTAL versions (S, SN) are also more sensitive for mechanical shocks that MEMS oscillator versions. (I have not tested what it need for XTAL defect)

author: wilfred
author_rank: Super Contributor
timestamp: April 25, 2019, 09:25:30 pm
content: I'm still waiting to hear what results come from switching off the HV power supply. I think that could easily explain the error. Needs to be eliminated as a possible cause and is easy to do.

author: bson
author_rank: Unknown
timestamp: April 26, 2019, 01:57:05 am
content: You don't have to read the RTC every second; when you get an interrupt from SQW you cancount seconds, minutes, hours in RAM. Then read the RTC only on startup to initialize, and maybe once every 6 hours for good measure. This would practically eliminate any potential for interference from the I2C bus.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: April 26, 2019, 09:09:23 am
content: Quote from: JackJones on April 25, 2019, 03:47:35 pmSend them to rf-loop for post mortem?

author: NivagSwerdna
author_rank: Super Contributor
timestamp: April 26, 2019, 09:16:39 am
content: Quote from: bson on April 26, 2019, 01:57:05 amIn my experience reading at 1Hz does not affect the device... you don't have to.... but you can. It's a red herring in this context.

author: iMo
author_rank: Super Contributor
timestamp: April 26, 2019, 09:53:03 am
content: Unless the OP provides some basic measurements/debugging people here had advised we still speculate. We need inputs from him.I've never detected an info the DS3231 on the cheapo $1.5 modules are fakes or broken.I'v heard so far:1. the 200ohm resistor shall be removed with 5Vcc otherwise you charge the CR20322. the I2C EEPROM could be removed to decrease the module's current consumption3. the LED could be removed to decrease the module's current consumption4. I2C sw/driver issues as usual5. wiring issues as usual.

author: Kjelt
author_rank: Super Contributor
timestamp: April 26, 2019, 09:56:02 am
content: I have ordered three cheapo modules, when they arrive I will test them by programming and verifying them synchronised to a DCF77 clock module.Powering down and a day later power up and read out the date/time.Curious what to find, with tens of seconds lost/gained they are completely useless.

author: iMo
author_rank: Super Contributor
timestamp: April 26, 2019, 10:04:42 am
content: One stupid issue I had with my modules (purchased years back) was I had the routines for setting up the initial date/time and the routines reading the time/date in the same source, thus after the fw upload and any mcu reset I always setup up the old date/time and wondered why is my reading way offThe workaround: never ever place the setup (writing the RTC) and reading the RTC in the same fw binary

author: NivagSwerdna
author_rank: Super Contributor
timestamp: April 26, 2019, 10:10:50 am
content: http://blog.dan.drown.org/rtc-comparison/is quite interesting. and the first article I read..https://thecavepearlproject.org/2014/05/21/using-a-cheap-3-ds3231-rtc-at24c32-eeprom-from-ebay/

author: iMo
author_rank: Super Contributor
timestamp: April 26, 2019, 10:20:09 am
content: The another point to note is the Datasheet specifies the params at 3.3Vcc.The 5Vcc is "max".I've never run my modules at 5V but 3.3V.I doubt 5Vcc could cause such an deviation after a day or two, however.

author: JackJones
author_rank: Regular Contributor
timestamp: April 26, 2019, 10:25:59 am
content: Quote from: NivagSwerdna on April 26, 2019, 09:09:23 amI bought them about a year ago and they are long gone. I don't like keeping fakes/rejects so that I don't accidentally mix them up with working ones.I bought them from around 4 different sellers and all had issues. I find it a bit surprising that no one else seems to have had any problems with theirs. I did read some forum threads before I bought them and everyone else agreed back then too that they have worked fine. I don't think I did anything wrong either to cause it, like I said once I soldered a genuine one into the same breakout board it worked fine.

author: iMo
author_rank: Super Contributor
timestamp: April 26, 2019, 10:29:54 am
content: It could be some sellers may rebadge the DS3231M version to DS3231SN (as there is SO16 package M version too). But even with the MEMS version you cannot see almost any diff after 2 days..BTW:https://www.maximintegrated.com/en/products/nla/index.mvp/view/EOL/pg/14Quote

author: floobydust
author_rank: Super Contributor
timestamp: April 26, 2019, 11:04:35 am
content: There are some firmware items to check too. There must be 100 libraries out there.Jeelabs/Adafruitfork of RTClibdoes not seem to check the busy flag BSY, and flukes a power-up delay in the sample code.Datasheet: "Communication with the I²C should be held off at least for the first 2 seconds after a valid power source has been established. It is during the first 2 seconds after power is established that the accurate RTC starts its oscillator, recalls calibration codes, initiates a temperature sensor read, and applies a frequency correction."An RTC cold-boot might be worth trying.DS3231MRev. A1 silicon errata 2010but it does not have much. I do not see a silicon errata for the DS3231S.If the RTC runs slow, you can try change the aging register value, to skew load capacitance. Otherwise, I think factory cal is missing.If the RTC runs fast, I would look for noise sources (Vcc, traces underneath, near SMPS inductors etc.). Check the on-chip temperature sensor which is used for the TCXO, it's +/-3C accuracy.I haven't had problems with the DS3231, even the low cost parts.

author: Kjelt
author_rank: Super Contributor
timestamp: April 26, 2019, 11:15:06 am
content: Quote from: imo on April 26, 2019, 10:04:42 amUsually a product with a RTC offers the user the possibility to set the date/time manually (not automagically at startup).So I find this a very strange advise since every product I know of with a RTC violates your (strange) rule

author: NivagSwerdna
author_rank: Super Contributor
timestamp: April 26, 2019, 11:28:49 am
content: If you manage to read to the very end....https://thecavepearlproject.org/2014/05/21/using-a-cheap-3-ds3231-rtc-at24c32-eeprom-from-ebay/There is some info re -M

author: iMo
author_rank: Super Contributor
timestamp: April 26, 2019, 12:06:25 pm
content: Interesting. It seems the M version is really a cheapo replacement..They do temp compensation every 10secs (in battery mode), therefore 2uA current (against SN: every 64secs, 840nA).Also it seems the MEMS itself is not compensated, the correction is done digitally based on temperature (SN switches the crystal's tuning capacitors based on the temperature).On the other hand you may check out the M version by measuring the 32kHz out and heating it up with your finger:QuoteOr, even a faster check would be the M does not output 8k, 4k, 1k freqs.

author: Alptkn
author_rank: Newbie
timestamp: April 26, 2019, 05:36:20 pm
content: Guys I read all of your posts fast forward (there was quite a lot post thanks for the interest) I wasnt able to check the forum for a couple of days but during this time I unpluged the clock but before I did I set the time on ds3231.I pluged it check the time every time I came from work then unplug it again.No drift or what so ever. It was spot on I was kinda expecting min or so drift again and burn the chip for good measure.However this forced me to write another code which gonna read the time every day only twice to night I will burn the new firmware. And check the it again. If code doesnt solve this problem I am sure it is EMI or power supply related problem which requires me to make changes in board desing so that I leave it last to dig in to.For the people who asked for the code it is in the attachment but I need to say that phrase specific to the code type of mine.......it is spagetti code....

author: NivagSwerdna
author_rank: Super Contributor
timestamp: April 26, 2019, 10:39:31 pm
content: You showed yours... so I'll show mine...Code:...#include <Wire.h>#include <RTClib.h>...RTC_DS3231 rtc;int INTERRUPT_PIN = 3;volatile boolean fired = false;...void alarmFired() {fired = true;//Serial.print("#");}...void setup(){...// RTCpinMode(INTERRUPT_PIN, INPUT_PULLUP);if (! rtc.begin()) {Serial.println("Couldn't find RTC");while (1); // sketch halts in an endless loop}Serial.println("RTC Started");rtc.writeSqwPinMode(DS3231_SquareWave1Hz);attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), alarmFired, FALLING);...}...void loop(){...if (fired) {fired = false;calculateDateTime();displayTime();}...}DateTime tt; //variable of type DateTimevoid calculateDateTime() {tt = rtc.now();}...void displayTime() {int hour = tt.hour();hour %= 12;int minute = tt.minute();int second = tt.second();...}Reading at 1Hz really isn't a problem... you need to sort out the reliability of the reads otherwise you will get errors (just less often!).. Make sure you have 10k pull-ups on the I2C bus (the internal pull-ups are a bit weak) and as per the datasheet have a 10k pull-up on SQW probably isn't a bad plan either.When reading RTC data... make sure your reads are atomic... reading hour, then minute, then second separately won't work well around second/minute boundaries and would produce inconsistent results.Good luck!

author: tooki
author_rank: Super Contributor
timestamp: April 27, 2019, 12:58:08 am
content: Quote from: imo on April 26, 2019, 10:04:42 amWhy would youeverbe setting the time via a statically coded time in the firmware upload? Not only does it mean you have to change the firmware to change the time, but it won't be especially accurate since the time to compile and upload isn't entirely deterministic.Either provide a way to set the time on the clock itself, or via serialafter boot.

author: iMo
author_rank: Super Contributor
timestamp: April 27, 2019, 07:49:09 am
content: This is how it is done on my boards:Code:void setup(){..setSyncProvider(eRTC.get); // the function to get the time from the external RTCif(timeStatus() != timeSet)Serial.println("Unable to sync with the RTC");elseSerial.println("RTC has set the system time");setSyncInterval(3600); // Update Time with RTC every 60minutes}void loop(){..time_t tim = now();..}PS:https://github.com/PaulStoffregen/Time

author: NivagSwerdna
author_rank: Super Contributor
timestamp: April 27, 2019, 11:00:39 am
content: Quote from: tooki on April 27, 2019, 12:58:08 amhttps://github.com/lucadentella/RTCSetupis a simple example of setting via serial. Assuming you are using Windows you can use it as is on the PC side and then incorporate the protocol into your sketch on the Arduino side... and when you outgrow it... look to GPS, Radio, NTP etc.

author: iMo
author_rank: Super Contributor
timestamp: April 27, 2019, 12:06:40 pm
content: The beauty of those external I2C RTC modules is you set the time once and you do not mess with its setting for years. Therefore I set the module's UTC time with a "set3231.ino" once, and using it then with different boards and different apps (which do not include the time setting functionality).Sure, I talk here "the development and experiments", not "a final product" where the ability for setting the initial time is required and obvious, of course, and its necessity has not to be discussed, imhoPS: the above "now()" returns the unix time, it is a 32bit uint.The sync provider works such when you call now() in order to get current system Time, it first checks whether the sync interval is over.If yes, now() reads the external RTC, synces the internal system Time, and returns the system Time.When the sync period is not over, now() only returns the system Time.

author: Telek
author_rank: Contributor
timestamp: August 03, 2020, 06:38:38 pm
content: Necropost, but interesting - I have a collection of these modules (cheap from eBay). Most seem to work perfectly, but I just tried one and it was behaving odd. It seemed to be losing about 1 secondper minute. I figured that I'd bust out the oscilloscope so that I could try to tweak the aging... and I can't get a 32kHz outputat allfrom it. I even send it the command to ensure that it's enabled. Similarly, the SQW output is always on at 1Hz, even when I tell it not to. Swapped out the battery, no difference. Took the battery out, no difference. Swapped for another identical module, and the other module has no problems and I can see the 32kHz output with the exact same code running. I think, as was pointed out, when you pay $1 per unit and the chip costs $8, there's probably a good reason...

author: Kjelt
author_rank: Super Contributor
timestamp: August 04, 2020, 04:21:13 pm
content: Quote from: Telek on August 03, 2020, 06:38:38 pm

author: schmitt trigger
author_rank: Super Contributor
timestamp: August 04, 2020, 04:48:18 pm
content: Another "Made in USA" myth:https://www.snopes.com/fact-check/made-in-usa/

author: tooki
author_rank: Super Contributor
timestamp: August 04, 2020, 05:47:01 pm
content: Quote from: schmitt trigger on August 04, 2020, 04:48:18 pmWhat does that have to do with anything at all in this discussion?

author: 0-8-15 User
author_rank: Regular Contributor
timestamp: August 05, 2020, 08:41:04 am
content: Quote from: floobydust on April 24, 2019, 07:16:17 pmI bought two of them atamazon.deand they work perfectly fine. I use the 1 Hz output on the SQW pin to increase the time through an interrupt service routine and the reading is 10 seconds off after 8 weeks of operation.

author: tooki
author_rank: Super Contributor
timestamp: August 05, 2020, 09:05:44 am
content: Quote from: Telek on August 03, 2020, 06:38:38 pmIs it a DS3231SN or DS3231M?