Class 9 - I2C Concept & RTC using DS1307

June 06, 2025

Hi Buddies!

Today on our BuddyKit, let’s explore one of the essential communication protocols – the I2C Protocol.

Microcontrollers support many protocols like I2C, SPI, and Serial. Among these, I2C (Inter-Integrated Circuit) is widely used for communication between devices on the same board or across boards.

I2C works with one master and multiple slave devices. Each slave device has a unique address, and communication starts when the master sends a data packet with the slave address.

Basics of I2C

I2C has two main lines:

  • SDA – Serial Data Line
  • SCL – Serial Clock Line

The master controls communication, initiates data transfer, and makes decisions. We’ll be writing the code from the master side.

I2C has 3 Main Stages:

  • Start Condition
  • Data Transfer (Write/Read)
  • Stop Condition

Start Condition:

Start condition occurs when SDA goes from HIGH to LOW while SCL is HIGH.

Stop Condition:

Stop condition occurs when SDA goes from LOW to HIGH while SCL is HIGH.

Data Transfer:

During a write, master sets SDA as output, sends each bit with clock pulses. After 8 bits, 9th bit is ACK (acknowledge).

During a read, master sets SDA as input and reads data on each clock pulse.

I2C Write Operation

I2C Read Operation

Interfacing DS1307 RTC with I2C

Now let’s apply the I2C concept with DS1307 – a Real Time Clock (RTC) module.

This is an I2C slave device with these addresses:

  • 0xD0 – for Write
  • 0xD1 – for Read

RTC stores data in specific memory locations:

  • 0x00 – Seconds
  • 0x01 – Minutes
  • 0x02 – Hours
  • 0x03 – Day of Week
  • 0x04 – Date
  • 0x05 – Month
  • 0x06 – Year

Note: The RTC uses 1970 as the base year. So, if you see 55 in RTC memory, it means 2025 (1970 + 55).

All values are stored in BCD format.

RTC Write Code:

RTC Read Code:

Circuit Diagram

RTC Clock Display Demo

Using the above code and our BuddyKit RTC & LCD libraries, we can display a real-time clock on LCD.

Final Note

We hope this I2C protocol explanation and RTC example helped you understand how real-world sensors and timekeeping modules communicate with microcontrollers.

There are many more I2C-based devices like gyroscopes, ADCs, temperature & humidity sensors, accelerometers, and more. In our upcoming videos, we’ll cover many of them using BuddyKit.

Stay tuned for our next topic. See you soon!

Leave a reply
Class 8 – Servo MotorClass 10 – Digital Clock Project using 7 Segment

Leave Your Reply