Pages: [1]   Go Down
Author Topic: [solved]setting date on mega and wiznet  (Read 443 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 1
Posts: 171
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
}

« Last Edit: November 17, 2012, 04:39:44 am by vespapierre » Logged

France
Offline Offline
Edison Member
*
Karma: 37
Posts: 1008
Scientia potentia est.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, you forgot to initialize a serial instance smiley

Add in setup():
Code:
Serial.begin( 9600 ); // 9600 or whatever is the baud speed that you have set in the serial monitor window
« Last Edit: November 15, 2012, 03:18:43 pm by guix » Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 171
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

still no answer:( nothing happens on serial...this code was working fine on atmega328...but mega2560 now... smiley-confuse
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...
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 171
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 171
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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??

Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 171
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Problem is solved:

Have to wire out from wiznet to mega:

mega:
20 (SDA)
21 (SCL)

wiznet:
A4 (SDA)
A5 (SCL)
Logged

Pages: [1]   Go Up
Jump to: