You are on page 1of 3

I2C Controller for RTC

I2C Controller in VHDL for Real Time Clock (RTC) Applications


Overview The I2C_RTC core serves as a bi-directional on-chip communication interface between parallel bus applications and the I2C-bus. The interface implements the I2C-bus protocol for slave applications. This core has be designed for interfacing with the Real Time Clock(RTC), to access the time/date keeping registers of the RTC for varied applications.

Clk_8MHz Rst_H Init Read Sec_data


8 8

Init_done Read_Done Seconds

I2C Controller for RTC

8 8

year_out SCL SDA

year_data

ni2designs, Pune

www.ni2designs.com

I2C Controller for RTC

Steps for Initialization of RTC: Reset the FPGA Apply BCD values to all data input ports for the RTC registers. Make the Init pin to 1. After some time, the Init_done flag goes high. Make the Init pin to 0. The initialization of the RTC is been done.

Note: If the RTC is NOT connected with battery, then the user has to repeat the initialization process on every power ON; else he can just proceed with read operation. How to initialize RTC registers? As the RTC registers accept 8-bit data in BCD encoded data, so here is the illustration to initialize the RTC with following date and time format. Time: i.e. Date: 13:15:20 Hours = 13 05-02-2007 or 01:15:00 PM Minutes = 15 Monday Seconds = 20

The RTC data lines are 8-bit in BCD format. Every register gets 4-bit BCD value from the data line. So, the data to be fed to the input data lines of RTC is as follows; Input Data line Sec_data min_data hrs_data day_data date_data month_data year_data Higher Nibble (7.4) 2 1 1 0 0 0 0 Lower Nibble (3.0) 0 5 3 1 5 2 7 Remarks 20 secs 15 minutes 13 hours Monday (1st day) 5th February 07 (as 20 is for constant for 99 years, so discarded)

ni2designs, Pune

www.ni2designs.com

I2C Controller for RTC

Steps for Reading data from RTC: Make the Read pin to 1. The controller will read all the registers of the RTC, and put the data on the o/p registers. User can keep the read pin to 1; the controller will keep updating the o/p registers. Users can use the read flag for synchronizing the read operation.

Device Address: D0 for DS1307

Write Word Address: 00 for seconds register

Read seconds register data from RTC

Read minutes register data from RTC

Sequence description of controller during read operation: As read pin is made 1; here are the list of sequences which the controller goes through 1. 2. 3. 4. 5. Generate START condition Write device address of RTC (D0) on the SDA line. Write 1 on SDA pin for READ mode. Check acknowledge from RTC, expected value is 0. On correct acknowledge, write word address or address of register which you want to read, in our case we always write 00, which is the address of the seconds register. 6. Check acknowledge from RTC. 7. On correct acknowledge, read the data from the RTC, the first packet received would be of seconds register. 8. Give acknowledge to RTC, i.e. 0. 9. Hence forth, RTC will keep on auto-incrementing its word address from the value assigned first; so keep on reading the data from the RTC, the packet sequence would be now, minutes, hours, day, date, month and year. 10. After read the last packet, give NOT OF ACKNOWLEDGE to RTC, i.e. 1. 11. Generate STOP condition. For further information on this I2C controller core and source codes contact: Vinay Sharma vinay@ni2designs.com ni logic Pvt. Ltd.

ni2designs, Pune

www.ni2designs.com

You might also like