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:
#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);
}
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
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.
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.
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".
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)
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: