Starting Electronics Needs Your Help!
It is that time of the year when we need to pay for web hosting and buy new components and equipment for new tutorials. You can help by making a donation. Contribute to this website by clicking the Donate button. The total will be updated once daily. (You may need to clear your browser cache to see the updates.)

Target Amount: $2000
Amount Raised: $495

Donations Received

Top Donor: D.C. $30

X

Testing the PCF8563 Real Time Clock IC using Arduino

Created on: 3 February 2013

Some tests that can be done to check if the PCF8563 real time clock (RTC) IC is working. The tests are done using an Arduino Uno board.

Testing will also check the Arduino to PCF8563 interface and communications over the I2C bus.

Test 1: Testing the Oscillator

In this test the Arduino is used only to supply 5V to the PCF8563. You will need a multimeter that can measure frequency and/or an oscilloscope.

The circuit is built as shown below and then the frequency on pin 7 (CLKO or CLKOUT) of the PCF8563 is measured to see if it is 32.768kHz (the multimeter may round this value up).

Testing the PC8563 oscillator

Testing that the Oscillator is Working on the PCF8563

This video shows the test being performed.

Can't see the video? View on YouTube →

Test 2: Writing to the PCF8563

In this test, the frequency on pin 7 (CLKO or CLKOUT) of the PCF8563 is changed from the default 32.768kHz to 1Hz. This is done by writing to one of the PCF8563 registers (the CLKOUT_CONTROL register at address 0x0D).

An LED is interfaced to the CLKOUT pin so that it can be seen switching on and off at the 1Hz rate.

The circuit diagram for this test is shown below. The SCL and SDA lines of the I2C bus are now connected between the Arduino and the PCF8563.

Hardware for Testing a Write to the CLKOUT_CONTROL Register of the PCF8563

Hardware for Testing a Write to the CLKOUT_CONTROL Register





This test shows whether the PCF8563 can be written to by the Arduino. Load the sketch below to the Arduino to perform the test.

/*--------------------------------------------------------------
  Program:      PCF8563_clkout_wrt

  Description:  Writes to the CLKOUT_CONTROL register of the
                PCF8563 RTC IC to set the frequency on the
                CLKOUT pin to 1Hz. For testing writing to the
                PCF8563.
                
  Date:         3 February 2013
 
  Author:       W.A. Smith, http://startingelectronics.org
--------------------------------------------------------------*/
#include <Wire.h>

#define RTC_ADDR  (0xA2 >> 1)

void setup()
{
    Wire.begin();        // initialize the I2C/TWI interface
    delay(1000);         // delay as a precaution
    
    // write to the PCF8563
    Wire.beginTransmission(RTC_ADDR);
    Wire.write(0x0D);                  // point to the CLKOUT_CONTROL register
    Wire.write(0x83);                  // set the CLKOUT frequency to 1HZ
    Wire.endTransmission();
}

void loop()
{
    // do nothing here, could also put the write code here
}

This video shows the above test being done. Notice that the frequency on the multimeter changes from the default value to 1Hz and the blinking LED becomes visible after loading the sketch.

Can't see the video? View on YouTube →

Amazon.com

Amazon.co.uk

Test 3: Reading from the PCF8563

The final test reads the seconds from the PCF8563. The value of the seconds is sent out of the serial port as a string for display in the Arduino serial monitor window. This tests both reading and writing as the PCF8563 must first be written to before it can be read from (to address the RTC time registers).

Build the second circuit above, but leave off the LED and its series resistor. Load the following sketch to the Arduino to perform the test.

/*--------------------------------------------------------------
  Program:      PCF8563_read

  Description:  Reads the seconds from the PCF8563 and sends
                them out the serial port for viewing in the
                serial monitor window.
                Tests that the PCF8563 can be written to and
                read from.
                
  Date:         3 February 2013
 
  Author:       W.A. Smith, http://startingelectronics.org
--------------------------------------------------------------*/
#include <Wire.h>

#define RTC_ADDR  (0xA2 >> 1)

unsigned char time_date_raw[7]; // stores time/date read from RTC
int index = 0;                  // index into above array
char seconds[] = "00";          // stores seconds string

void setup()
{
    Wire.begin();        // initialize the I2C/TWI interface
    delay(1000);         // delay as a precaution
    Serial.begin(9600);  // initialize the serial port
}

void loop()
{
    // point to the time registers in the RTC
    Wire.beginTransmission(RTC_ADDR);
    Wire.write(0x02);
    Wire.endTransmission();
    
    // read all the time/date registers
    //Wire.beginTransmission(RTC_ADDR);
    Wire.requestFrom(RTC_ADDR, 7);
    while (Wire.available()) {
        time_date_raw[index] = Wire.read();
        index++;
        if (index >= 7) {
            index = 0;
            break;
        }
    }
    Wire.endTransmission();
    
    delay(80);               // delay as a precaution
    // convert seconds to string
    seconds[0] = ((time_date_raw[0] >> 4) & 0x07) + '0';
    seconds[1] = (time_date_raw[0] & 0x0F) + '0';
    Serial.println(seconds);
}

This video shows the test being performed.

Can't see the video? View on YouTube →