Hello, I'm trying to use the PCF8563 RTC/Calendar/Alarm IC. It uses the I2C bus, an Interrupt for alarms and has a clock output. I know I2C works as I have other I2C devices plugged in (PCF8574 Bidi shift registers). I have hooked up the clock out to the external interrupt of the arduino and wanted to be able to read a steady 1Hz. I have a pull up resistor (1.5K) on the line as clock out is an open drain output. sadly that's a no joy.
Here is my code:
/* PCF8563 (I2C) Real Time Clock / Calendar / Alarm
* ---------------
*
* (cleft) 2005 by Matthieu Lalonde
* <http://smurfturf.net>
* <mailto:mlalonde(at)smurfturf(dot)net>
*
*/
#include <Wire.h>
#define BAUD_RATE 19200
#define statusLED 12
// Addr. |Mode (162 + Read)
#define RTCAddressW B10100010
#define RTCAddressR B10100011
int blinkStatus = LOW;
void setup(void) {
// initialize inputs/outputs
// start serial
Serial.begin(BAUD_RATE);
Wire.begin();
Wire.beginTransmission(RTCAddressW);
//Wire.send(0);
// Registers
Wire.send(B00000000); // 00H Test mode
Wire.send(B00000000); // 01H Alarm mode
Wire.send(B00000000); // 02H Seconds
Wire.send(30); // 03H Minutes
Wire.send(19); // 04H Hours
Wire.send(11); // 05H Date
Wire.send(2); // 06H Day of the week
Wire.send(B00000000); // 07H Century bit
Wire.send(7); // 08H year
Wire.send(B10000000); // 09H Minute alarm
Wire.send(B10000000); // 0AH Hour alarm
Wire.send(B10000000); // 0BH Day alarm
Wire.send(B10000000); // 0CH Weekday alarm
Wire.send(B10000011); // 0DH CLKOUT control (1Hz)
Wire.send(B00000000); // 0EH Timer control
Wire.send(B00000000); // 0FH Timer
Wire.endTransmission();
reportAVRState(3,0);
pinMode(statusLED, OUTPUT);
attachInterrupt(1, clockIn, CHANGE);
}
void loop()
{
digitalWrite(statusLED, blinkStatus);
if (blinkStatus) {
Serial.println("Blinked");
}
}
void clockIn( void ) {
blinkStatus != blinkStatus;
}
// Reports the state of the controller via pin 13's led and serial
void reportAVRState(int howManyTimes, int leaveOn) {
int i;
pinMode(statusLED, OUTPUT);
for (i=0; i < howManyTimes; i++) {
digitalWrite(statusLED, HIGH);
delay(200);
digitalWrite(statusLED, LOW);
delay(200);
}
if (leaveOn) {
digitalWrite(statusLED, HIGH);
}
Serial.println();
Serial.println("AVR Initialized");
}
Thanks, I tried it out. It compiles fine, but everything acts the same way. I, sadly, do not have a scope to check the frequency of the crystal or the clock out. But normally it would clock out at 1Hz, and that should be easy enough to see with a multimeter.... but it doesn't seem like anything happens on clock out. I'm starting to think I got something wrong with the way the IC works. Although from what I see in the very well documented datasheet and app notes, it doesn't seem so. The crystal might also be the factor as I salvaged it from an old Nomad Jukebox. But it does say 32(R6E0) and looks like a clock crystal.
No, at the moment I am able to write to the RTC, and read all the registers. The R/(not)W bit doesn't seem to have an effect and the clock never changes when I read back the registers. Clkout still does not work. I'm definitely starting to blame the crystal. I which I knew a company that offers samples of Khz range xtals. I've only found Mhz and I don't want to order one or two of a 1$ part when shipping will cost me like 10$ or more. What's the difference from the 8562 to 8563?
Hi,
did you ever find a solution on this issue?
I tried to use the ds1307, with the same results as you. i can write to the clock registers and read them, but nothing changes, the values wont change. The clock seems not to run.
The Post i've started: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1180908809/5#5
I hope I'm not breaking any rules by dredging up this thread (:X) but I've had the same problems, and I think I've found the solution.
When using the Wire library, you only need to pass Wire.beginTransmission and Wire.requestfrom the 7-bit device address, less the read/write bit. Apparently, Wire takes care of the read/write bit for you, so if you pass it the full 8-bit address, your data is gonna get sent to the wrong place. This isn't mentioned anywhere in the documentation, and I had to find out about it from a blog. : |
Did you get the PCF8563 working? I am thinking of adding a Real time clock to my arduino project and so I was wondering if I should go with PCF8563. My project requires an RTC that gives me the current time... more or less accurately.
I haven't really tried in a while. By now I've worked with a few other I2C devices like maxim's ds1337 RTC. I'm pretty sure the PCF8563 could work too. But for a safe bet use the ds1337 as there's a lib for it. Here's the code, config1 & config2 and usage doc. The only hitch is the 32.768Khz crystal needs to be a 6pF for accurate timing (12pF seems more common). From what I read in the datasheet at 12pF the skew could be ±1min/day. I'm not sure if that's also the case for the PCF8563.
Sorry for bringing this old thread up again but i really wan't to get my pcf8563 up and running...
I made som changes to your code, just to get it up and running but whit out success...:
#include <Wire.h>
void setup(void)
{
Wire.begin();
Serial.begin(9600);
Wire.beginTransmission(0xA2);
//Wire.send(B00000000);
Wire.send(B00000000); // 00H Test mode
Wire.send(B00000000); // 01H Alarm mode
Wire.send(B00000011); // 02H Seconds
Wire.send(B01000101); // 03H Minutes:p
Wire.send(B00010100); // 04H Hours
Wire.send(B00010101); // 05H Date
Wire.send(B00000101); // 06H Day of the week
Wire.send(B10000111); // 07H Century bit 19XX = 1 | 20XX = 0
Wire.send(B10011001); // 08H year
Wire.send(B10000000); // 09H Minute alarm
Wire.send(B10000000); // 0AH Hour alarm
Wire.send(B10000000); // 0BH Day alarm
Wire.send(B10000000); // 0CH Weekday alarm
Wire.send(B10000011); // 0DH CLKOUT control (00: 32.768Khz 11: 1Hz)
Wire.send(B00000000); // 0EH Timer control
Wire.send(B00000000); // 0FH Timer
Wire.endTransmission();
}
void loop()
{
Wire.beginTransmission(0xA2);
Wire.send(0x00);
Wire.endTransmission();
Wire.requestFrom(0xA2, 0x10);
while(Wire.available())
{
Serial.println(Wire.receive() ,BIN);
}
Serial.println("Waiting a little");
delay(2000);
}
And i get an response like this:
0
0
11
1000101
10100
10101
101
10000111
10011001
10000000
10000000
10000000
10000000
10000011
0
0
Waiting a little
Now, the strange thing is that when i RTC from my arduino I get the same response. Well, thats strange, if it's not connected you should not get any response right, but you do, it's the same when I try your code and remove the PCF8563...
Does anyone else experience the same thing or is it only me?
Yes, if the address is invalid you'll read back the buffer. Look on this forum, I have a post describing how to modify the TWI library to enable scanning of addresses. My bet is you need to shift your address by one to the right (>>1).