The R4571 is a Real Time Clock (RTC) with internal oscillator and alarm/interrupt functions. This chip can be found in some Epson printers with clock features.
(photo by Blunoise, Public Domain)
The R4571 is connected to the Arduino using pins (CE, DIO, CLK) and Vdd can be connect to +5V (or +3.3V). FOUT chip pin can be used as a source clock (see notes) IRQ pin can be used as counter time interrupt.
The Vdd range is 1.6V - 5.5V and the battery it could be a lithium battery (see datasheet). Be careful to connect value minor than 3V because the DIO Pin High and Low voltage levels are based on Vdd (comunication problems)
The R4571 use a 3-wire serial interface (Most Significant Bit First). How described in code section, to realize the protocol the arduino shiftIn and shiftOut functions have been used. To perform a write register operation call writeReg(register,value). To perform a read register operation call readReg(register).
How it's described at CLK pin description in datasheet the read mode clockis on fall edge and the write mode clock is on raise edge. So, based on the shiftOut documentation (http://arduino.cc/en/Reference/ShiftOut) the clock pin must be setted LOW at beginning of any transmission because the comunication always start with a byte sended by arduino that contain operation mode and address.(see nexts points)
The first byte must contain read/write mode on first part and the register address on rest part. For a read operation byte first part must be 1001 (09h). For a write operation byte first part must be 0001 (01h). Example:to make a read operation on register 0x03 the first byte to transmit is 1001 0011 (0x93)
To read or set time and date just call the appropriate function:
The week days starts from Sunday (value 0x01) to Saturday (value 0x07).
this function return date in form “Fri 2013-07-12”
e.g.: get minutes value
This chips has an out clock specific pin (FOUT) and the frequency can be set by FOE pin and FSEL0 FSEL1 bits in extension register. Another interesting function of the device is the fixed-cycle counter: When a "1" is written to the TE bit, the fixed-cycle timer countdown starts from the preset value. A fixed-cycle timer interrupt event starts a countdown based on the countdown period (source clock). When the count value changes from 001h to 000h, an interrupt event occurs( transition of IRQ Pin from HIGH to LOW).
Data can be cathed in continuous operation and objected address is auto incremented. Auto incrementing of the address is cyclic, so address "F" is followed by address "0". This method was not implemented in code at this time.