[solved]setting date on mega and wiznet

Hi,

I tried to set time and date on mega and wiznet with the below code, but no message on serial monitor...
what is wrong??

#include <Wire.h>
#include <Rtc_Pcf8563.h>

//init the real time clock
Rtc_Pcf8563 rtc;

void setup()
{
//clear out the registers
rtc.initClock();
//set a time to start with.
//day, weekday, month, century(1=1900, 0=2000), year(0-99)
rtc.setDate(14, 6, 3, 1, 10);
//hr, min, sec
rtc.setTime(1, 15, 0);
}

void loop()
{
//both format functions call the internal getTime() so that the
//formatted strings are at the current time/date.
Serial.print(rtc.formatTime());
Serial.print("\r\n");
Serial.print(rtc.formatDate());
Serial.print("\r\n");
delay(1000);
}

Hello, you forgot to initialize a serial instance :slight_smile:

Add in setup():

Serial.begin( 9600 ); // 9600 or whatever is the baud speed that you have set in the serial monitor window

still no answer:( nothing happens on serial...this code was working fine on atmega328...but mega2560 now... :~
I have read on playground I should define I2C addresses...like
#define RTCC_R 0xa3
#define RTCC_W 0xa2

my addresses are 0x51 and 0x02

but I gues this format is not ok..or whatever...

ok, now it is answering after this:
include <Wire.h>
#include <Rtc_Pcf8563.h>
#define I2C_RTC 0x51

//init the real time clock
Rtc_Pcf8563 rtc;

void setup()
{
Serial.begin( 9600 );
//clear out the registers
rtc.initClock();
//set a time to start with.
//day, weekday, month, century(1=1900, 0=2000), year(0-99)
rtc.setDate(15, 4, 11, 0, 12);
//hr, min, sec
rtc.setTime(21, 52, 0);
}

void loop()
{
//both format functions call the internal getTime() so that the
//formatted strings are at the current time/date.
Serial.print(rtc.formatTime());
Serial.print("\r\n");
Serial.print(rtc.formatDate());
Serial.print("\r\n");
delay(1000);
}

but still have wrong values back:

45:85:85
25/45/19@5

Take care about the pins!! for I2C

mega:
20 (SDA)
21 (SCL)

duemila:
A4 (SDA)
A5 (SCL)

Do I have to take care about it in the sketch after wiring out??

Problem is solved:

Have to wire out from wiznet to mega:

mega:
20 (SDA)
21 (SCL)

wiznet:
A4 (SDA)
A5 (SCL)