DS1307 is a low power serial real time clock with full binary coded decimal (BCD) clock/calendar plus 56 bytes of NV SRAMΒ (Non Volatile Static Random Access Memory). Data and Address are transferred serially through aΒ bidirectionalΒ I2C bus. The RTC provides year, month, date, hour, minute and second information. The end date of months is automatically adjusted for months fewer than 31 days including leap year compensation up to year 2100. It can operate either in 24-hour format or 12-hour format with AM/PM indicator. DS1307 comes with built-in power sensing circuit which senses powerΒ failuresΒ and automatically switches to back up supply.Β The DS1307 RTC uses an external 32.768kHz Crystal OscillatorΒ and itΒ does not requires any external resistors or capacitors to operate.
What is I2C (IΒ²C) ?
IΒ²CΒ (Read as βi-squared ceeβ;Β Inter-Integrated Circuit) is aΒ multi-masterΒ serialΒ single-endedΒ computer busΒ invented byΒ Philips,Β used to attach low-speed peripherals to aΒ embedded system,cellphone, motherboard, or other electronic device and is generally referred to asΒ βtwo-wire interfaceβ. It consists of two wires called SCL and SDA. SCL is the clock line which is used to synchronise all the data transfers through I2C bus and SDA is the data line. It also need a third line as reference line (ground or 0 volt). A 5v power should be also be given to the device for its working. The main thing to be noted is that both SCL and SDA are Open Drain drives. Which means that the chip can drive its low output but canβt drive high output. Thus we must provide two pull up resistors to 5v for SCL and SDA, to make it to drive high output as shown in the fig.
Selection of Pull Up Resistors
1. The rise time of SCL and SDA voltages will depend up on the value of pull up resistor and I2C bus capacitance. Thus pull up resistor should be selected according to the I2C bus frequency being used.
2. The higher value of pull up resistor is limited by the rise time and the lower vale of pull up resistor is limited by theΒ drive strength (IOL max) of the SDA and SCL drivers. If the pull up resistor is very low , the SCL and SDA outputs might not be establish enough low voltage.
I recommend you to use 1.8K pull up resistors.
MikroC PRO for PIC Microcontroller provide built-in libraries for I2C devices. DS1307 works as a slave device on I2C bus. Register access can be obtained byΒ implementingΒ a START and followed by device identification address. Then each registers can be accessed sequentially by using its address until a STOP condition is executed.
Device Address : 0X68 = 1101000
For more detail: Interfacing Real Time Clock (RTC) DS1307 with PIC Microcontroller