Lab # 03 I2C Write
Lab # 03 I2C Write
I2C Communication
Objective:
Configure the I2C registers and interface with EEPROM 24C01 with PIC 16F877A.
Components:
Microcontroller PIC16F877A
Pull Up Resistor (10 Kilohms)
EEPROM 24C01C
I2C Debugger
Theory:
I2C Communication:
I²C (Inter-Integrated Circuit), pronounced I-squared-C, is multi-master, multi-slave, packet
switched, single-ended, serial computer bus invented in 1982 by Philips.
The I2C (Inter-IC) bus is a bi-directional two-wire serial bus that provides a communication link
between integrated circuits (ICs).
I2C is a synchronous protocol that allows a master device to initiate communication with a slave
device. Data is exchanged one bit at a time. Most of the sensor are related to I2C.
The two wires, or lines are called Serial Clock (or SCL) and Serial Data (or SDA). The SCL line is
the clock signal which synchronize the data transfer between the devices on the I2C bus and it’s
generated by the master device. The other line is the SDA line which carries the data.
The two lines are “open-drain” which means that pull up resistors needs to be attached to them so
that the lines are high because the devices on the I2C bus are active low. Commonly used values for
the resistors are from 2K for higher speeds at about 400 kbps, to 10K for lower speed at about 100
kbps.
The I2C mode fully implements all master and slave functions (including general call support) and
provides interrupts on Start and Stop bits in hardware to determine a free bus (multi-master function).
It supports 7-bit and 10-bit addressing. 127 devices connected on two wires.
Two pins are used for data transfer:
• Serial clock (SCL) – RC3/SCK/SCL
• Serial data (SDA) – RC4/SDI/SDA
The user must configure these pins as inputs or outputs
through the TRISC<4:3> bits.
Master:
A device on the I2C bus which starts the communication.
Slave:
A device which is being addressed by MASTER.
Protocol:
The data signal is transferred in sequences of 8 bits. So, after a special start condition occurs comes
the first 8 bits sequence which indicates the address of the slave to which the data is being sent. The
device addressing sequence starts with the most significant bit (MSB) first and ends with the least
significant bit (LSB) and it’s actually composed of 7 bits because the 8th bit is used for indicating
whether the master will write to the slave (logic low) or read from it (logic high). After each 8 bits
sequence follows a bit called Acknowledge. After the first Acknowledge bit in most cases comes
another addressing sequence but this time for the internal registers of the slave device. After the
addressing sequences follows the data sequences as many until the data is completely sent and it
ends with a special stop condition.
Code:
Output:
I2C Debug:
Variables Status:
Conclusion:
In this lab, we studied about the I2C communication and interface with EEPROM 24C01C by using
PIC 16F877A. Configured the required registers and write code by understand the timing diagram
of I2C protocol. Also write data in EEPROM 24C01.