Go Down

Topic: RTC circuit not working (Read 261 times) previous topic - next topic


Jan 14, 2021, 06:05 pm Last Edit: Jan 14, 2021, 08:19 pm by dizzycoder
Hi guys,

I'm not sure if my question belongs to this category or not. But here it is:
I have hooked up the RTC circuit as shown in the screen shot. I have an ATMEGA32U4 and an RTC chip "PCF85063AT". I tried a few libraries to make it work but the numbers are frozen on the initial values without changing. I checked the crystal and it looks fine, because if I take it off, the COM port will show weird results. Also, the SCL and SDA are reversed in my schematic. But it's been fixed in my actual board.
I think there's still something wrong with the hardware, because as I said, I used 2 different libraries and they both have their initial values frozen, I noticed the "seconds" and "Year" are always zero as you can see in figure!
I'd be grateful if you could help me out.

Here's the code:
Code: [Select]
#include <Keyboard.h>

#include "PCF8563.h"

PCF8563 pcf;

void setup() {
 pcf.init();//initialize the clock

 pcf.stopClock();//stop the clock

 //set time to to 31/3/2018 17:33:0

 pcf.setYear(18);//set year
 pcf.setMonth(3);//set month
 pcf.setDay(31);//set dat
 pcf.setHour(17);//set hour
 pcf.setMinut(33);//set minut
 pcf.setSecond(0);//set second

 pcf.startClock();//start the clock

void loop() {
 Time nowTime = pcf.getTime();//get current time

 //print current time
 Serial.print(" ");


Jan 14, 2021, 06:39 pm Last Edit: Jan 14, 2021, 10:37 pm by groundFungus
Where are the required pullup resistors (4.7K) on the SDA and SCL lines?

20 posts and no code tags.  Why?  Read the how get the most out of this forum sticky to see how to properly post code.  Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code in code tags.  You can go back and edit your original post to include code tags.


What results do you get with the I2C scanner?
Code: [Select]
// I2C scanner by Nick Gammon.  Thanks Nick.

#include <Wire.h>

void setup() {
  Serial.begin (115200); //*****  make sure serial monitor baud matches *****

  // Leonardo: wait for serial port to connect
  while (!Serial)

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  for (byte i = 1; i < 120; i++)
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}


Where are the require pullup resistors (4.7K) on the SDA and SCL lines?
Did you check the RTC board for pullup resistors using a meter with no power connected to the RTC board ?


Thanks for your reply, Sorry, only this post didn't have code tags and it's now fixed. 
When I uploaded your code, I received the following result from COM port. 


There are several  PCF8563 libraries.  Post a link to the one that you are using.  Is the default address in the library 0x51?


There are several  PCF8563 libraries.  Post a link to the one that you are using.  Is the default address in the library 0x51?
Thanks for the reply. Here are the libraries I used. 




I have to admit that I haven't used any pull_up resistors on the SCL and SDA lines. Do you think his would be the reason for frozen timer? 
Because I just found another library and this is also printing the same result as others, date and time are frozen on a number. 


I have to admit that I haven't used any pull_up resistors on the SCL and SDA lines. Do you think his would be the reason for frozen timer?
I know a good way to find out.
  ... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.


I know a good way to find out.
could you help me out please? 
I added the pull_up resistors but still the same problem! Timer is frozen on initial values and prints zeros for "Year" and "Second". 


add pull up resistors (4k7) on your SDA and SCL lines. Also does your crystal need load capacitors? its datasheet should state that  (one cap one each pin , connected to ground with value specified in its datasheet)
RapidStencil.com, a unique solder paste stencil printer for prototyping and small production batches. Fast, easy and most cost-effective


Thanks for all the help guys, using pull-up resistors did the work, also some libraries are not optimized well so use this library if you want this specific chip to work well:

Go Up