Go Down

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

dizzycoder

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() {
 Serial.begin(9600);
 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(nowTime.day);
 Serial.print("/");
 Serial.print(nowTime.month);
 Serial.print("/");
 Serial.print(nowTime.year);
 Serial.print(" ");
 Serial.print(nowTime.hour);
 Serial.print(":");
 Serial.print(nowTime.minute);
 Serial.print(":");
 Serial.println(nowTime.second);
 delay(1000);
}




groundFungus

#1
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.

groundFungus

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;
 
  Wire.begin();
  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 (")");
      count++;
      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() {}

raschemmel

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

dizzycoder

@groundFungus
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. 




groundFungus

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

dizzycoder

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. 


https://github.com/elpaso/Rtc_Pcf8563


https://github.com/Bill2462/PCF8563-Arduino-Library

dizzycoder

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. 

aarg

Quote
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.

dizzycoder

I know a good way to find out.
Hi, 
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". 

milamber_ls

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

dizzycoder

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:
https://github.com/jvsalo/pcf85063a

Go Up