DS3231 intermittent start-up issues when coin-cell battery connected - Page 1
Forum section: electronics / general

author: newtekuser
author_rank: Frequent Contributor
timestamp: June 16, 2024, 07:29:34 am
content: I have a DS3231MZ connected to a PIC as per the attached diagram. If the coin cell battery is present it frequently causes the IC to misbehave on power-on where it just hangs (when debugging I see it hangs during i2c start)This does not happen on power-on if the battery is not present. How does the presence of the battery affect it and what can I do to solve this?

author: iMo
author_rank: Super Contributor
timestamp: June 16, 2024, 07:46:06 am
content: There is an internal comparator which compares Vpf (power fail) voltage of aprox 2.6V (internal reference) and asserts reset (see the DS).It could happen this somehow triggers. For example your battery is low, your Vcc is low, add decoupling capacitors (your 10nF is too low, go with 10u for example), etc..

author: selcuk
author_rank: Frequent Contributor
timestamp: June 16, 2024, 01:12:52 pm
content: I used DS3231SN with two 100nF capacitors, one at Vbat and the other on at Vcc. I haven't noticed this issue. Vcc is 3.3V. They are similar chips. I can recommend using at least the minimum capacitances written on the datasheet.

author: hugo
author_rank: Regular Contributor
timestamp: June 16, 2024, 04:53:21 pm
content: To improve things you could try using stronger pull-up resistors (3k3, 4k7) and a decoupling capacitor of 1uF.

author: newtekuser
author_rank: Frequent Contributor
timestamp: June 16, 2024, 04:58:11 pm
content: Quote from: hugo on June 16, 2024, 04:53:21 pmI am using 10K resistors on SDA and SCL lines and also swapped the cap for 100nF on Vcc but it didn't make a difference.

author: newtekuser
author_rank: Frequent Contributor
timestamp: June 16, 2024, 04:58:59 pm
content: Quote from: selcuk on June 16, 2024, 01:12:52 pmI'll have to try with decoupling Vbat as well because increasing the cap size on Vcc to 100nF didn't make a difference.

author: newtekuser
author_rank: Frequent Contributor
timestamp: June 16, 2024, 05:22:09 pm
content: Also bypassed Vbat with a 100nF cap and issue is still there. I checked the voltage on the battery and it's 3V which is higher than the threshold for Vpf.I should mention this happens when the circuit is powered on from Vcc (5v) and there's other load coming up like powering a 5V 16x2 LCD. The Input Vcc for the entire circuit is decoupled with a 100uF electrolytic cap.

author: jaka
author_rank: Contributor
timestamp: June 17, 2024, 06:33:54 am
content: Could it be that there was I2C communication with DS3231 going on when power was switched off? This could have left DS3231 in a state where it excepts more I2C clock cycles to complete the I2C transaction.You could try to cycle the SCL pin e.g. some tens of times when your PIC boots up, before trying to communicate with DS3231.

author: Psi
author_rank: Super Contributor
timestamp: June 17, 2024, 07:16:23 am
content: Coin cells are terrible at high currents. I can totally see your battery voltage momentarily dropping to 2.6V and triggering the internal comparator even with a new coin cell if the current burst is high enough.eg. 20mA LED flashes, RF transmits some data, MCU's built in dcdc switches on etc..Try 100uF of ceramic across the cell. (electrolytic is fine for testing but they leak like crazy and will flatten your coin cell over a few weeks.)And check the 10k is actually 10k and not 10R

author: newtekuser
author_rank: Frequent Contributor
timestamp: June 17, 2024, 08:53:22 pm
content: Tried with the 100uF cap on Vbat, also toggling the pin that goes to SCL before going through i2c init and no differenceCode:for(uint8_t i=0; i<50; i++){RC3 = 0;__delay_ms(1);RC3 = 1;__delay_ms(1);}I also double-checked the pull-ups are 10K and not lower.

author: selcuk
author_rank: Frequent Contributor
timestamp: June 17, 2024, 09:57:42 pm
content: A short voltage drop on the 5V rail seems to cause the issue. I'm not sure about the exact mechanism.There are single supply input RTCs. You usually connect both battery and the DC supply to the same pin via diodes. You may try that as a work around. If it is possible to alter your circuit, you may check Fig 12 of the below document and try it either on Vcc or Vbat. Recommended low leakage diodes are on Table 9.https://www.nxp.com/docs/en/user-guide/UM10301.pdf

author: Peabody
author_rank: Super Contributor
timestamp: June 17, 2024, 10:05:58 pm
content: So the problem doesn't occur unless you intialize I2C?You know there have to be hundreds of thousands of embedded systems using this RTC, including a dozen or so of mine, where this problem never happens. I really just can't imagine what would cause it unless it's a power issue of some kind. But I've never tried it with a PIC, only AVR.

author: newtekuser
author_rank: Frequent Contributor
timestamp: June 17, 2024, 10:12:55 pm
content: Quote from: Peabody on June 17, 2024, 10:05:58 pmCorrect and this only happens with the coin cell battery connected to the RTC, never without the battery. I can't fault the RTC module either as I'm seeing this with replacements too, all have been purchased from reputable source, either Digikey or Mouser.

author: newtekuser
author_rank: Frequent Contributor
timestamp: June 17, 2024, 10:17:37 pm
content: Quote from: selcuk on June 17, 2024, 09:57:42 pmI tried adding long delays before initializing i2c for power to stabilize to no avail.

author: Peabody
author_rank: Super Contributor
timestamp: June 17, 2024, 10:21:15 pm
content: So it's either some weird power problem, or there's something wrong with the PIC software. Or, I guess, possibly the PIC.

author: newtekuser
author_rank: Frequent Contributor
timestamp: June 19, 2024, 02:02:46 am
content: Quote from: Psi on June 17, 2024, 07:16:23 amOk, so with just a 100uF cap across the cell didn't fix it, but once I also replaced the 100nF with a 100uF on the Vcc pin of the DS3231, it worked flawlessly.

author: ArdWar
author_rank: Frequent Contributor
timestamp: June 19, 2024, 02:38:08 am
content: From the description it's probably problem with I2C instead of device itself. Either stuck bus confusing everyone and/or PIC peripheral went into some unexpected state, usually ended up stuck waiting interrupt or something. Try some other I2C implementation and see if problem persist.

author: newtekuser
author_rank: Frequent Contributor
timestamp: June 19, 2024, 03:53:40 am
content: Quote from: ArdWar on June 19, 2024, 02:38:08 amConsidering that this issue doesn't happen without the battery connected and that the issue is gone after increasing the cap size I think this should rule out a problem with i2c. What makes you think it's still an i2c issue?

author: ArdWar
author_rank: Frequent Contributor
timestamp: June 19, 2024, 04:35:07 am
content: Can you probe SCL and see if there are stray falling edge during VCC ramp up?Another thing to try is to delay I2C peripheral initialization until supply settles. Or to put the SCK pin as GPIO DOUT during startup and toggle it at least 9 times to force bus reset into known state.Quote from: newtekuser on June 19, 2024, 03:53:40 amBecause it isn't this problematic (yet?) with my designs. Well, not this exact P/N but similar.

author: newtekuser
author_rank: Frequent Contributor
timestamp: June 19, 2024, 04:40:44 am
content: Quote from: ArdWar on June 19, 2024, 04:35:07 amI've tried the two as stated earlier and they didn't fix the issue (toggling the SCL line and adding a delay until starting i2c init).

author: Peabody
author_rank: Super Contributor
timestamp: June 19, 2024, 01:59:04 pm
content: Do you have a way to measure the current in the DS3231's Vcc line? Nominally, it's about 100uA for the processor itself, and then if you're using a module of some kind, whatever the pullups might draw and the power indicator LED if present. It's just hard to see why such a large cap would be needed to make it work right. The traditional ZS-042 module has two caps on that line - 0.1uF and 1uF, but it also has an EEPROM chip.Could you try powering the RTC's Vcc and pullups from a GPIO pin? Then you could intialize I2C before bringing up Vcc. I have an AVR project that only brings up Vcc when communicating with the RTC, which otherwise runs on Vbat. Seems to work fine. And The GPIO is active low when not high, so the pullups are actually pulldowns, and it still works when everything goes back high.It just seems like there must be large currents flowing somewhere that shouldn't be.

author: Psi
author_rank: Super Contributor
timestamp: June 20, 2024, 06:10:39 am
content: Have you double and triple checked your PCB/circuit matches the diagram postedAnd checked you don't have any pins bridged or shorted to anything.Maybe something with the INT pin. Where if an int happens it draws large current through somewhere, and maybe when you dont init the chip over i2c the int is not enabled, so the issue doesn't occur.

author: ArdWar
author_rank: Frequent Contributor
timestamp: June 20, 2024, 06:21:53 am
content: Things can be much clearer if you can record what happened with SDA/SCL during VCC ramp up, maybe record Vcc and Vbat while at it.Otherwise it'll continue to be wild guesses.

author: newtekuser
author_rank: Frequent Contributor
timestamp: June 20, 2024, 04:41:13 pm
content: Quote from: Psi on June 20, 2024, 06:10:39 amNo pins bridged/shorted and nothing connected to the INT pin either. PCB and breadboard wiring are identical and observing the same behavior.Attached the PCB layout and schematic for reference.

author: mikerj
author_rank: Super Contributor
timestamp: June 20, 2024, 07:33:34 pm
content: Do you have more details on the nature of the I2C hang at start-up? e.g. is the I2C bus functioning (activity on SCL and SDA) but the DS3231 doesn't ACK, or is the SDA pin being pulled low by the DS3231 so the PIC cannot perform the start sequence?

author: newtekuser
author_rank: Frequent Contributor
timestamp: August 07, 2024, 04:41:36 pm
content: Quote from: Peabody on June 19, 2024, 01:59:04 pmI think this may be the case as I'm seeing this behavior, though less prevalent even without the coin-cell battery present. If I measure the current on start-up I see a spike of 100mA after which it settles to around 24mA and if I remove the cap the spike drops to around 70mA, likely from the other caps I have on the PCB that charge during power on.I believe I need to implement a soft-start circuit to limit this spike, correct? Any recommendations on the soft-start circuit design/components? (my circuit is 5V powered and will draw 1.4 Amp max when under load)

author: Peabody
author_rank: Super Contributor
timestamp: August 07, 2024, 10:07:14 pm
content: Sorry, but I don't know what's going on. Don't know what to suggest.