DS3231 slows down with attached EthernetShield

Hi all,
I have problem with RTC modul DS3231.. It is connected to MEGA (SDA 20 and SCL 21) and rapidly speed up (let say 15 seconds on 10 minutes) when I attach EthernetShield W5100. There is still same simple program to read time from RTC modul. (downloaded)
I´m newbie in that and I have no idea how to solve this mystery.. :-/

// DS3231_Serial_Easy (C)2014 Henning Karlsen
// web: http://electronics.henningkarlsen.com/
//
// A quick demo of how to use my DS3231-library to 
// quickly send time and date information over a serial link
//
// To use the hardware I2C (TWI) interface of the Arduino you must connect
// the pins as follows:
//
// Arduino Uno/2009:
// ----------------------
// DS3231:  SDA pin   -> Arduino Analog 4 or the dedicated SDA pin
//          SCL pin   -> Arduino Analog 5 or the dedicated SCL pin
//
// Arduino Leonardo:
// ----------------------
// DS3231:  SDA pin   -> Arduino Digital 2 or the dedicated SDA pin
//          SCL pin   -> Arduino Digital 3 or the dedicated SCL pin
//
// Arduino Mega:
// ----------------------
// DS3231:  SDA pin   -> Arduino Digital 20 (SDA) or the dedicated SDA pin
//          SCL pin   -> Arduino Digital 21 (SCL) or the dedicated SCL pin
//
// Arduino Due:
// ----------------------
// DS3231:  SDA pin   -> Arduino Digital 20 (SDA) or the dedicated SDA1 (Digital 70) pin
//          SCL pin   -> Arduino Digital 21 (SCL) or the dedicated SCL1 (Digital 71) pin
//
// The internal pull-up resistors will be activated when using the 
// hardware I2C interfaces.
//
// You can connect the DS3231 to any available pin but if you use any
// other than what is described above the library will fall back to
// a software-based, TWI-like protocol which will require exclusive access 
// to the pins used, and you will also have to use appropriate, external
// pull-up resistors on the data and clock signals.
//

#include <DS3231.h>

// Init the DS3231 using the hardware interface
DS3231  rtc(SDA, SCL);

void setup()
{
  // Setup Serial connection
  Serial.begin(9600);
  // Uncomment the next line if you are using an Arduino Leonardo
  //while (!Serial) {}
  
  // Initialize the rtc object
  Serial.println("GO");
  rtc.begin();
  
  // The following lines can be uncommented to set the date and time
  //rtc.setDOW(WEDNESDAY);     // Set Day-of-Week to SUNDAY
  //rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(1, 1, 2014);   // Set the date to January 1st, 2014
}

void loop()
{
  // Send Day-of-Week
  Serial.print(rtc.getDOWStr());
  Serial.print(" ");
  
  // Send date
  Serial.print(rtc.getDateStr());
  Serial.print(" -- ");

  // Send time
  Serial.println(rtc.getTimeStr());
  
  // Wait one second before repeating :)
  delay (1000);
}

The two devices shouldn't affect each other, especially since you have not even initialized the w5100.

Exactly which ethernet shield are you testing? Can you post a link to that hardware?

Have you tried disabling the w5100 SPI just as a test?

void setup()
{
  // disable w5100 SPI
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);

  // Setup Serial connection
  Serial.begin(9600);

Hi,
thanks for your reply.. :slight_smile:

my Ethernet shield is exactly like this

no, i didn´t try that (i will), but as you said - i didn´t even inicialize it..

meanwhile i did some tests..

  • connect DS1307 module instead DS3231 => there is same result - lost few seconds in 10 minutes
  • completly power off and after 12hours checked time => it was ok
  • recheck source power level => there is 4.98V
  • I also recovered, that is difference if I read time (every second) or not.. If not, time is OK.. So it seems for me like DS modul is busy with communication and have no time to increment his time counter or whatever.. but I don´t/can´t believe that :o

The link to the ethernet board implies that it is designed to be connected to the UNO. I don't think the pinout on the Mega is the same, so that is very likely to be the cause of the problem.
[+edit]Oh, it also says that it works with the Mega. Hmmm.

Pete

Try disabling the w5100 SPI as I suggested above. If D10 is allowed to float, it could cause weird oscillations that might affect the RTC. That is the only thing I can think of. I was going to have you check the power, but that is ok if the 5v bus is at 4.98 volts.

did as you wrote - W5100 disabled (also SD reader on W5100), but there is still drift in seconds/hour..

I found thread with similar problem..

Have you tried a small capacitor (like maybe 1uf) from Vcc to GND on the RTC module?

SurferTim:
Have you tried a small capacitor (like maybe 1uf) from Vcc to GND on the RTC module?

done -> no change (there allready is capacitator in wiring to this RTC modul ZS-042)

I´ll try modify my program to use I2C.h library instead of Wire.h ..will see what happen :wink:

report..
after change my code to I2C lib. version, there are no changes.. time in RTC is still ocillating aroun real time from NTP.. yes it is oscillating - sometimes above, sometimes below.. it almost looks like RTC modul is trying to correct time.. but it is only my speculation :wink:
in every way - I decided to check RTC time with NTP time and correct it, if need..

so my conlusion for DS3231 (DS1307) is, I´m totaly confused.. :smiley: