8051 – I2C Tutorial

Now we will see 8051 I2C Interfacing Tutorial. so we will Interface EEPROM to check I2C.

8051 I2C Interfacing Tutorial

Suggest to Read

Before getting into I2C interfacing with 8051, Please read below topics…



I²C is a serial computer bus, which is invented by NXP semiconductors previously it is named as Philips semiconductors. The I²C bus is used to attach low speed peripheral integrated circuits to microcontrollers and processors. I²C bus uses two bidirectional open-drain lines such as SDA (serial data line) and SCl (serial clock line) and these are pulled up with resistors. I²C bus permits a master device to start communication with a slave device. Data is interchanged between these two devices. Typical voltages used are +3.3V or +5V although systems with extra voltages are allowed. Nowadays new microcontrollers have inbuilt I²C Registers. But in 8051 there is no such registers. So we have to achieve I²C in 8051. So in this tutorial, we will see how to achieve that.

Many devices support I²C. For example, EEPROM, ADC, LCD, etc. For the sake of implementing I²C, we are going to interface EEPROM.


Electrically Erasable Programmable ROM (EEPROM) is a user-modifiable ROM which can be removed and reprogrammed frequently through the application of higher than the normal electrical voltage. An EEPROM is a kind of non-volatile memory used in electronic devices like computers to store small quantities of data that should be saved when power is detached.

Connection Diagram

SCK – P3.6

SDA – P3.7

8051 I2C Tutorial

I²C Implementation

Write Mode

  1. Send the START command from the Master.
  2. Send Device (EEPROM) Address with write mode.
  3. Send Register address in Device (EEPROM), Where we have to access.
  4. Send the Data to the Device (EEPROM).
  5. If you want to send more than one byte, keep sending that byte.
  6. Finally, Send the STOP command.

Read Mode

  • Send the START command from the Master.
  • Send Device (EEPROM) Address with write mode.
  • Send Register address in Device (EEPROM), Where we have to access.
  • Send again START command or Repeated START command.
  • Send Device address with Read mode.
  • Read the data from Device (EEPROM).
  • Finally, Send STOP command.


In our code, First, we will Write the Data into EEPROM. Then we will read that data from EEPROM and send it to Serial Communication (UART). So it will print in the serial console.

START Command

Just go through the above diagram. In this

  1. Initially, SDA and SCL are High.
  2. SDA first goes to Zero.
  3. Then SCL goes to Zero.

This is the START condition. Look at the below code. 

STOP Command

When SCL is High, We have to toggle the SDA Low to High.

Send Data

Sending Data and Address are the same procedure. Here we have to send bit by bit to the SDA based on the SCL.

Read Data

Reading also the same as write data. We have to read bit by bit from the SDA line based on SCL. Go through the Full code and try it.

Full Code

If you have any doubt please comment below.

0 0 vote
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Newest Most Voted
Inline Feedbacks
View all comments
August 26, 2017 2:03 PM

its not working

Reply to  owl
August 29, 2017 4:51 AM


chandu malipatil
chandu malipatil
December 19, 2018 11:57 AM

im not getting why (EP_DATA==13)…???

September 20, 2020 2:52 PM

what crystal frequency you have used for this code?

Would love your thoughts, please comment.x
%d bloggers like this: