Skip to main content
2 of 2
edited tags

PCF8583 with Arduino delay of one second?

I'm trying to interface the RTC chip : PCF8583 with Arduino Uno. I'm using exactly the circuit shown below except instead of the variable capacitor near the crystal oscillator, I've used a 22pF ceramic capacitor.

enter image description here

For the programming side, I've used the Arduino PCF8583 library

The code I'm using is the following :

#include <Wire.h> // necessary, or the application won't build properly
#include <stdio.h>
#include <PCF8583.h>

/*
*  read/write serial interface to PCF8583 RTC via I2C interface
*
*  Arduino analog input 5 - I2C SCL (PCF8583 pin 6)
*  Arduino analog input 4 - I2C SDA (PCF8583 pin 5)
*
*  You can set the type by sending it YYMMddhhmmss;
*  the semicolon on the end tells it you're done...
*
*/

int correct_address = 0;
PCF8583 p (0xA0);   
void setup(void){
 Serial.begin(9600);
 Serial.print("booting...");
 Serial.println(" done");
}

void loop(void){
 if(Serial.available() > 0){
   p.year= (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48)) + 2000;
   p.month = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
   p.day = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
   p.hour  = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
   p.minute = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
   p.second = (byte) ((Serial.read() - 48) * 10 + (Serial.read() - 48)); 
   // Use of (byte) type casting and ascii math to achieve result.  

   if(Serial.read() == ';'){
     Serial.println("setting date");
     p.set_time();
   }
 }


 p.get_time();
 char time[50];
 sprintf(time, "%02d/%02d/%02d %02d:%02d:%02d",
  p.year, p.month, p.day, p.hour, p.minute, p.second);
 Serial.println(time);
 delay(3000);
}

When setting the time and date, everything went ok, but when getting date/time the result is always HALF the period of the elapsed time, for example if I set the time 10:30 and I check it after 30 MINUTES, I get 10:45 instead of 11:00.

I really don't know if this is a hardware or software issue. If anybody has any idea about this issue, that would be highly appreciable !

Thanks in advance !