SlideShare una empresa de Scribd logo
1 de 30
I2C Protocol
Lecture Notes: 17th April 2018
Sudhanshu Janwadkar, SVNIT Surat
Introduction
I²C (Inter-Integrated Circuit) is a
• Synchronous
• multi-master
• multi-slave
• packet switched
• single-ended
serial computer bus invented in 1982 by Philips Semiconductor
It is widely used for attaching lower-speed peripheral ICs to
processors and microcontrollers in short-distance, intra-board
communication.
A particular strength of I²C is the capability of a
microcontroller to control a network of device chips with just
two general-purpose I/O pins and software.
Many other bus technologies used in similar applications, such
as Serial Peripheral Interface Bus, require more pins and
signals to connect multiple devices.
Introduction
Design (H/W)
I²C uses only two bidirectional open-drain lines, Serial Data
Line (SDA) and Serial Clock Line (SCL), pulled up with
resistors.
Typical voltages used are +5 V or +3.3 V, although systems
with other voltages are permitted.
Design (H/W)
The I2C bus drivers are “open drain”, meaning that they can
pull the corresponding signal line low, but cannot drive it high.
Thus, there can be no bus contention where one device is
trying to drive the line high while another tries to pull it low,
eliminating the potential for damage to the drivers or excessive
power dissipation in the system.
Each signal line has a pull-up resistor on it, to restore the
signal to high when no device is asserting it low.
Design (H/W)
The I²C reference design has a 7-bit address space.
Common I²C bus speeds are the 100 kbit/s standard mode and
the 400 kbit/s Fast mode.
The maximal number of nodes is limited by the address space
and also by the total bus capacitance of 400 pF, which restricts
practical communication distances to a few meters.
The relatively high impedance and low noise immunity
requires a common ground potential, which again restricts
practical use to communication within the same PC board or
small system of boards.
Design (H/W)
Design (Architecture)
The bus has two roles for nodes: master and slave:
• Master node – node that generates the clock and initiates
communication with slaves.
• Slave node – node that receives the clock and responds
when addressed by the master.
The bus is a multi-master bus, which means that any number
of master nodes can be present.
Additionally, master and slave roles may be changed between
messages (after a STOP is sent).
There may be four potential modes of operation for a given
bus device, although most devices only use a single role and
its two modes:
• master transmit – master node is sending data to a slave,
• master receive – master node is receiving data from a slave
• slave transmit – slave node is sending data to the master
• slave receive – slave node is receiving data from the
master.
Design (Architecture)
I2C Protocol (Basics)
Frame Format
I2C Protocol (Basics)
Messages are broken up into two types of frame:
• Address frame: The master indicates the slave to which the
message is being sent
• Data frame: These are 8-bit data messages passed from
master to slave or vice versa.
Data is placed on the SDA line after SCL goes low, and is
sampled after the SCL line goes high.
I2C Protocol (Basics)
Start Condition
• To initiate the address frame, the master device leaves SCL
high and pulls SDA low.
• This puts all slave devices on notice that a transmission is
about to start.
• If two master devices wish to take ownership of the bus at one
time, whichever device pulls SDA low first wins the race and
gains control of the bus.
• It is possible to issue repeated starts, initiating a new
communication sequence without relinquishing control of the
bus to other masters
I2C Protocol (Basics)
Address Frame
• The address frame is always first in any new communication
sequence.
• For a 7-bit address, the address is clocked out most significant
bit (MSB) first, followed by a R/W bit indicating whether this
is a read (1) or write (0) operation.
I2C Protocol (Basics)
NACK/ACK bit
• It is the 9th bit of the frame
• This is the case for all frames (data or address).
• Once the first 8 bits of the frame are sent, the receiving device
is given control over SDA.
• If the receiving device does not pull the SDA line low before
the 9th clock pulse, it can be inferred that the receiving device
either did not receive the data or did not know how to parse the
message.
• In that case, the exchange halts, and it’s up to the master of the
system to decide how to proceed.
I2C Protocol (Basics)
Data Frames
• After the address frame has been sent, data can begin being
transmitted.
• The master will simply continue generating clock pulses at a
regular interval, and the data will be placed on SDA by either
the master or the slave, depending on whether the R/W bit
indicated a read or write operation.
I2C Protocol (Basics)
Stop condition
• Once all the data frames have been sent, the master will
generate a stop condition.
• Stop conditions are defined by a 0->1 (low to high) transition
on SDA after a 0->1 transition on SCL, with SCL remaining
high.
• During normal data writing operation, the value on SDA
should not change when SCL is high, to avoid false stop
conditions.
I2C Protocol
1. The master is initially in master transmit mode by sending a
START followed by the 7-bit address of the slave it wishes to
communicate with
2. This is finally followed by a single bit representing whether it
wishes to write (0) to or read (1) from the slave.
3. If the slave exists on the bus then it will respond with an ACK
bit (active low for acknowledged) for that address.
4. The master then continues in either transmit or receive mode
(according to the read/write bit it sent), and the slave
continues in the complementary mode (receive or transmit,
respectively).
I2C Protocol
5. The address and the data bytes are sent most significant bit
first.
6. The master terminates a message with a STOP condition if
this is the end of the transaction or it may send another
START condition to retain control of the bus for another
message (a "combined format" transaction).
I2C Protocol
If the master wishes to write to the slave, then it repeatedly
sends a byte with the slave sending an ACK bit. (In this
situation, the master is in master transmit mode, and the slave
is in slave receive mode.)
If the master wishes to read from the slave, then it repeatedly
receives a byte from the slave, the master sending an ACK bit
after every byte except the last one. (In this situation, the
master is in master receive mode, and the slave is in slave
transmit mode.)
An I²C transaction may consist of multiple messages.
Types of Transactions in I2C
• I²C defines basic three types of transactions, each of which
begins with a START and ends with a STOP:
• Single message where a master writes data to a slave.
• Single message where a master reads data from a slave.
• Combined format, where a master issues at least two
reads or writes to one or more slaves.
• In a combined transaction, each read or write begins with a
START and the slave address. The START conditions after the
first are also called repeated START bits. Repeated STARTs
are not preceded by STOP conditions, which is how slaves
know that the next message is part of the same transaction.
Timing Diagram
1. Data transfer is initiated with a start bit (S) signaled by SDA being pulled
low while SCL stays high.
2. SCL is pulled low, and SDA sets the first data bit level while keeping SCL
low
3. The data are sampled (received) when SCL rises for the first bit (B1). For a
bit to be valid, SDA must not change between a rising edge of SCL and the
subsequent falling edge
4. This process repeats, SDA transitioning while SCL is low, and the data
being read while SCL is high (B2, ...Bn).
5. The final bit is followed by a clock pulse, during which SDA is pulled low
in preparation for the stop bit.
6. A stop bit (P) is signaled when SCL rises, followed by SDA rising.
Interfacing of 8051 with EEPROM
(I2C Protocol)
#include<reg51.h>
#define ACK 1
#define NO_ACK 0
unsigned char i;
unsigned char EData[5];
unsigned char Data;
void DelayMs(unsigned int);
void WriteI2C(unsigned char);
void Start(void);
void Stop(void);
void ReadBYTE(unsigned int);
void WriteBYTE(unsigned int);
unsigned char ReadI2C(bit);
sbit SCL = P2^0; // connect to SCL pin (Clock)
sbit SDA = P2^1; // connect to SDA pin (Data)
void main(void) //Main Program
{
WriteBYTE(0x0000);
WriteI2C(‘A’); //Write Data’s Here
WriteI2C(‘B’);
WriteI2C(‘C’);
Stop();
DelayMs(10);
ReadBYTE(0x0000);
EData[0] = ReadI2C(NO_ACK);
EData[1] = ReadI2C(NO_ACK);
EData[2] = ReadI2C(NO_ACK);
while(1);
}
void Start(void) ///;Start I2C Protocol
{
SDA = 1;
SCL = 1;
_nop_();_nop_();
SDA = 0;
_nop_();_nop_();
SCL = 0;
_nop_();_nop_();
}
void Stop(void) // Stop I2C protocol
{
SDA = 0;
_nop_();_nop_();
SCL = 1;
_nop_();_nop_();
SDA = 1;
}
void WriteI2C(unsigned char Data) //;WriteI2C
{
for (i=0;i<8;i++)
{
SDA = (Data & 0x80) ? 1:0;
SCL=1;SCL=0;
Data<<=1;
}
SCL = 1;
_nop_();_nop_();
SCL = 0;
}
unsigned char ReadI2C(bit ACK_Bit)
{
Start();
WriteI2C(0xA1);
SDA = 1;
for (i=0;i<8;i++)
{
SCL = 1;
Data<<= 1;
Data = (Data | SDA);
SCL = 0;
_nop_();
}
if (ACK_Bit == 1)
SDA = 0; // Send ACK
else
SDA = 1; // Send NO ACK
_nop_(); _nop_();
SCL = 1;
_nop_();_nop_();
SCL = 0;
Stop();
return Data;
void ReadBYTE(unsigned int Addr) // Read 1 byte from I2C
{
Start();
WriteI2C(0xA0);
WriteI2C((unsigned char)(Addr>>8)&0xFF);
WriteI2C((unsigned char)Addr&0xFF);
}
void WriteBYTE(unsigned int Addr) //Write 1 byte to I2C
{
Start();
WriteI2C(0xA0);
WriteI2C((unsigned char)(Addr>>8)&0xFF); // send address high
WriteI2C((unsigned char)Addr&0xFF); // send address low
}
void DelayMs(unsigned int count)
{
unsigned int i;
while(count)
{
i = 115;
while(i>0) i- -;
Count- -;
}
}
Common applications of the I²C bus are:
• Describing connectable devices via small ROM configuration
tables to enable "plug and play" operation, such as
• Accessing real-time clocks and NVRAM chips that keep user
settings.
• Accessing low-speed DACs and ADCs.
• Controlling LCD displays.
Applications of I2C

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral Interface
 
APB protocol v1.0
APB protocol v1.0APB protocol v1.0
APB protocol v1.0
 
I2C
I2CI2C
I2C
 
SPI Protocol
SPI ProtocolSPI Protocol
SPI Protocol
 
I2C Protocol
I2C ProtocolI2C Protocol
I2C Protocol
 
SPI introduction(Serial Peripheral Interface)
SPI introduction(Serial Peripheral Interface)SPI introduction(Serial Peripheral Interface)
SPI introduction(Serial Peripheral Interface)
 
UART
UARTUART
UART
 
I2 c
I2 cI2 c
I2 c
 
Communication Protocols (UART, SPI,I2C)
Communication Protocols (UART, SPI,I2C)Communication Protocols (UART, SPI,I2C)
Communication Protocols (UART, SPI,I2C)
 
UART(universal asynchronous receiver transmitter ) PPT
UART(universal asynchronous receiver transmitter ) PPTUART(universal asynchronous receiver transmitter ) PPT
UART(universal asynchronous receiver transmitter ) PPT
 
ARM Processors
ARM ProcessorsARM Processors
ARM Processors
 
AMBA 3 APB Protocol
AMBA 3 APB ProtocolAMBA 3 APB Protocol
AMBA 3 APB Protocol
 
UART
UARTUART
UART
 
Serial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System ProtocolSerial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System Protocol
 
AMBA Ahb 2.0
AMBA Ahb 2.0AMBA Ahb 2.0
AMBA Ahb 2.0
 
ARM CORTEX M3 PPT
ARM CORTEX M3 PPTARM CORTEX M3 PPT
ARM CORTEX M3 PPT
 
Pcie basic
Pcie basicPcie basic
Pcie basic
 
VHDL-PRESENTATION.ppt
VHDL-PRESENTATION.pptVHDL-PRESENTATION.ppt
VHDL-PRESENTATION.ppt
 
RS 232
RS 232RS 232
RS 232
 
Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral Interface
 

Similar a I2C Protocol

communication interfaces-Embedded real time systems
communication interfaces-Embedded real time systemscommunication interfaces-Embedded real time systems
communication interfaces-Embedded real time systemsRaghunath reddy
 
Raspberry Pi - Lecture 3 Embedded Communication Protocols
Raspberry Pi - Lecture 3 Embedded Communication ProtocolsRaspberry Pi - Lecture 3 Embedded Communication Protocols
Raspberry Pi - Lecture 3 Embedded Communication ProtocolsMohamed Abdallah
 
An Implementation of I2C Slave Interface using Verilog HDL
An Implementation of I2C Slave Interface using Verilog HDLAn Implementation of I2C Slave Interface using Verilog HDL
An Implementation of I2C Slave Interface using Verilog HDLIJMER
 
UNI T 6- SPI_I2C_Lecture8.pptx
UNI                    T 6- SPI_I2C_Lecture8.pptxUNI                    T 6- SPI_I2C_Lecture8.pptx
UNI T 6- SPI_I2C_Lecture8.pptxnaveen088888
 
Implementation of I2C Master Bus Protocol on FPGA
Implementation of I2C Master Bus Protocol on FPGAImplementation of I2C Master Bus Protocol on FPGA
Implementation of I2C Master Bus Protocol on FPGAIJERA Editor
 
I2C protocol and DS1307 RTC interfacing
I2C protocol and DS1307 RTC interfacingI2C protocol and DS1307 RTC interfacing
I2C protocol and DS1307 RTC interfacingBhargav Kakadiya
 
Part-2: Mastering microcontroller with embedded driver development
Part-2: Mastering microcontroller with embedded driver developmentPart-2: Mastering microcontroller with embedded driver development
Part-2: Mastering microcontroller with embedded driver developmentFastBit Embedded Brain Academy
 
Inter intergrated circuits-communication protocol
Inter intergrated circuits-communication protocolInter intergrated circuits-communication protocol
Inter intergrated circuits-communication protocolRevathi Subramaniam
 
I2C And SPI Part-23
I2C And  SPI Part-23I2C And  SPI Part-23
I2C And SPI Part-23Techvilla
 
Peripherals and interfacing
Peripherals  and interfacingPeripherals  and interfacing
Peripherals and interfacingRAMPRAKASHT1
 
I2C-Bus Design and Verification Specs
I2C-Bus Design and Verification SpecsI2C-Bus Design and Verification Specs
I2C-Bus Design and Verification SpecsMostafa Khamis
 
ARDUINO AND ITS PIN CONFIGURATION
 ARDUINO AND ITS PIN  CONFIGURATION ARDUINO AND ITS PIN  CONFIGURATION
ARDUINO AND ITS PIN CONFIGURATIONsoma saikiran
 

Similar a I2C Protocol (20)

communication interfaces-Embedded real time systems
communication interfaces-Embedded real time systemscommunication interfaces-Embedded real time systems
communication interfaces-Embedded real time systems
 
Raspberry Pi - Lecture 3 Embedded Communication Protocols
Raspberry Pi - Lecture 3 Embedded Communication ProtocolsRaspberry Pi - Lecture 3 Embedded Communication Protocols
Raspberry Pi - Lecture 3 Embedded Communication Protocols
 
I2C PRESENTATION.PPT
I2C PRESENTATION.PPTI2C PRESENTATION.PPT
I2C PRESENTATION.PPT
 
An Implementation of I2C Slave Interface using Verilog HDL
An Implementation of I2C Slave Interface using Verilog HDLAn Implementation of I2C Slave Interface using Verilog HDL
An Implementation of I2C Slave Interface using Verilog HDL
 
COM_BASIC.pptx
COM_BASIC.pptxCOM_BASIC.pptx
COM_BASIC.pptx
 
UNI T 6- SPI_I2C_Lecture8.pptx
UNI                    T 6- SPI_I2C_Lecture8.pptxUNI                    T 6- SPI_I2C_Lecture8.pptx
UNI T 6- SPI_I2C_Lecture8.pptx
 
Implementation of I2C Master Bus Protocol on FPGA
Implementation of I2C Master Bus Protocol on FPGAImplementation of I2C Master Bus Protocol on FPGA
Implementation of I2C Master Bus Protocol on FPGA
 
The I2C Interface
The I2C InterfaceThe I2C Interface
The I2C Interface
 
I2C protocol and DS1307 RTC interfacing
I2C protocol and DS1307 RTC interfacingI2C protocol and DS1307 RTC interfacing
I2C protocol and DS1307 RTC interfacing
 
Part-2: Mastering microcontroller with embedded driver development
Part-2: Mastering microcontroller with embedded driver developmentPart-2: Mastering microcontroller with embedded driver development
Part-2: Mastering microcontroller with embedded driver development
 
Introduction to embedded systems
Introduction to embedded systemsIntroduction to embedded systems
Introduction to embedded systems
 
Lpc2148 i2c
Lpc2148 i2cLpc2148 i2c
Lpc2148 i2c
 
Assembler4
Assembler4Assembler4
Assembler4
 
I2C
I2CI2C
I2C
 
Inter intergrated circuits-communication protocol
Inter intergrated circuits-communication protocolInter intergrated circuits-communication protocol
Inter intergrated circuits-communication protocol
 
I2C And SPI Part-23
I2C And  SPI Part-23I2C And  SPI Part-23
I2C And SPI Part-23
 
Peripherals and interfacing
Peripherals  and interfacingPeripherals  and interfacing
Peripherals and interfacing
 
I2C-Bus Design and Verification Specs
I2C-Bus Design and Verification SpecsI2C-Bus Design and Verification Specs
I2C-Bus Design and Verification Specs
 
ARDUINO AND ITS PIN CONFIGURATION
 ARDUINO AND ITS PIN  CONFIGURATION ARDUINO AND ITS PIN  CONFIGURATION
ARDUINO AND ITS PIN CONFIGURATION
 
I2c buses
I2c busesI2c buses
I2c buses
 

Más de Sudhanshu Janwadkar

Keypad Interfacing with 8051 Microcontroller
Keypad Interfacing with 8051 MicrocontrollerKeypad Interfacing with 8051 Microcontroller
Keypad Interfacing with 8051 MicrocontrollerSudhanshu Janwadkar
 
ASIC design Flow (Digital Design)
ASIC design Flow (Digital Design)ASIC design Flow (Digital Design)
ASIC design Flow (Digital Design)Sudhanshu Janwadkar
 
Fpga architectures and applications
Fpga architectures and applicationsFpga architectures and applications
Fpga architectures and applicationsSudhanshu Janwadkar
 
Introduction to 8051 Timer/Counter
Introduction to 8051 Timer/CounterIntroduction to 8051 Timer/Counter
Introduction to 8051 Timer/CounterSudhanshu Janwadkar
 
Architecture of the Intel 8051 Microcontroller
Architecture of the Intel 8051 MicrocontrollerArchitecture of the Intel 8051 Microcontroller
Architecture of the Intel 8051 MicrocontrollerSudhanshu Janwadkar
 
Introduction to Embedded Systems
Introduction to Embedded SystemsIntroduction to Embedded Systems
Introduction to Embedded SystemsSudhanshu Janwadkar
 
Interconnects in Reconfigurable Architectures
Interconnects in Reconfigurable ArchitecturesInterconnects in Reconfigurable Architectures
Interconnects in Reconfigurable ArchitecturesSudhanshu Janwadkar
 
Design and Implementation of a GPS based Personal Tracking System
Design and Implementation of a GPS based Personal Tracking SystemDesign and Implementation of a GPS based Personal Tracking System
Design and Implementation of a GPS based Personal Tracking SystemSudhanshu Janwadkar
 
Embedded Logic Flip-Flops: A Conceptual Review
Embedded Logic Flip-Flops: A Conceptual ReviewEmbedded Logic Flip-Flops: A Conceptual Review
Embedded Logic Flip-Flops: A Conceptual ReviewSudhanshu Janwadkar
 

Más de Sudhanshu Janwadkar (20)

DSP Processors versus ASICs
DSP Processors versus ASICsDSP Processors versus ASICs
DSP Processors versus ASICs
 
Keypad Interfacing with 8051 Microcontroller
Keypad Interfacing with 8051 MicrocontrollerKeypad Interfacing with 8051 Microcontroller
Keypad Interfacing with 8051 Microcontroller
 
ASIC design Flow (Digital Design)
ASIC design Flow (Digital Design)ASIC design Flow (Digital Design)
ASIC design Flow (Digital Design)
 
Fpga architectures and applications
Fpga architectures and applicationsFpga architectures and applications
Fpga architectures and applications
 
LCD Interacing with 8051
LCD Interacing with 8051LCD Interacing with 8051
LCD Interacing with 8051
 
Interrupts in 8051
Interrupts in 8051Interrupts in 8051
Interrupts in 8051
 
Serial Communication in 8051
Serial Communication in 8051Serial Communication in 8051
Serial Communication in 8051
 
Introduction to 8051 Timer/Counter
Introduction to 8051 Timer/CounterIntroduction to 8051 Timer/Counter
Introduction to 8051 Timer/Counter
 
Intel 8051 Programming in C
Intel 8051 Programming in CIntel 8051 Programming in C
Intel 8051 Programming in C
 
Hardware View of Intel 8051
Hardware View of Intel 8051Hardware View of Intel 8051
Hardware View of Intel 8051
 
Architecture of the Intel 8051 Microcontroller
Architecture of the Intel 8051 MicrocontrollerArchitecture of the Intel 8051 Microcontroller
Architecture of the Intel 8051 Microcontroller
 
Introduction to Embedded Systems
Introduction to Embedded SystemsIntroduction to Embedded Systems
Introduction to Embedded Systems
 
CMOS Logic
CMOS LogicCMOS Logic
CMOS Logic
 
Interconnects in Reconfigurable Architectures
Interconnects in Reconfigurable ArchitecturesInterconnects in Reconfigurable Architectures
Interconnects in Reconfigurable Architectures
 
Introduction to FPGAs
Introduction to FPGAsIntroduction to FPGAs
Introduction to FPGAs
 
Design and Implementation of a GPS based Personal Tracking System
Design and Implementation of a GPS based Personal Tracking SystemDesign and Implementation of a GPS based Personal Tracking System
Design and Implementation of a GPS based Personal Tracking System
 
Embedded Logic Flip-Flops: A Conceptual Review
Embedded Logic Flip-Flops: A Conceptual ReviewEmbedded Logic Flip-Flops: A Conceptual Review
Embedded Logic Flip-Flops: A Conceptual Review
 
Pass Transistor Logic
Pass Transistor LogicPass Transistor Logic
Pass Transistor Logic
 
Memory and Processor Testing
Memory and Processor TestingMemory and Processor Testing
Memory and Processor Testing
 
Pass Transistor Logic
Pass Transistor LogicPass Transistor Logic
Pass Transistor Logic
 

Último

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 

Último (20)

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 

I2C Protocol

  • 1. I2C Protocol Lecture Notes: 17th April 2018 Sudhanshu Janwadkar, SVNIT Surat
  • 2. Introduction I²C (Inter-Integrated Circuit) is a • Synchronous • multi-master • multi-slave • packet switched • single-ended serial computer bus invented in 1982 by Philips Semiconductor It is widely used for attaching lower-speed peripheral ICs to processors and microcontrollers in short-distance, intra-board communication.
  • 3. A particular strength of I²C is the capability of a microcontroller to control a network of device chips with just two general-purpose I/O pins and software. Many other bus technologies used in similar applications, such as Serial Peripheral Interface Bus, require more pins and signals to connect multiple devices. Introduction
  • 4. Design (H/W) I²C uses only two bidirectional open-drain lines, Serial Data Line (SDA) and Serial Clock Line (SCL), pulled up with resistors. Typical voltages used are +5 V or +3.3 V, although systems with other voltages are permitted.
  • 6. The I2C bus drivers are “open drain”, meaning that they can pull the corresponding signal line low, but cannot drive it high. Thus, there can be no bus contention where one device is trying to drive the line high while another tries to pull it low, eliminating the potential for damage to the drivers or excessive power dissipation in the system. Each signal line has a pull-up resistor on it, to restore the signal to high when no device is asserting it low. Design (H/W)
  • 7. The I²C reference design has a 7-bit address space. Common I²C bus speeds are the 100 kbit/s standard mode and the 400 kbit/s Fast mode. The maximal number of nodes is limited by the address space and also by the total bus capacitance of 400 pF, which restricts practical communication distances to a few meters. The relatively high impedance and low noise immunity requires a common ground potential, which again restricts practical use to communication within the same PC board or small system of boards. Design (H/W)
  • 8. Design (Architecture) The bus has two roles for nodes: master and slave: • Master node – node that generates the clock and initiates communication with slaves. • Slave node – node that receives the clock and responds when addressed by the master. The bus is a multi-master bus, which means that any number of master nodes can be present. Additionally, master and slave roles may be changed between messages (after a STOP is sent).
  • 9. There may be four potential modes of operation for a given bus device, although most devices only use a single role and its two modes: • master transmit – master node is sending data to a slave, • master receive – master node is receiving data from a slave • slave transmit – slave node is sending data to the master • slave receive – slave node is receiving data from the master. Design (Architecture)
  • 11. I2C Protocol (Basics) Messages are broken up into two types of frame: • Address frame: The master indicates the slave to which the message is being sent • Data frame: These are 8-bit data messages passed from master to slave or vice versa. Data is placed on the SDA line after SCL goes low, and is sampled after the SCL line goes high.
  • 12. I2C Protocol (Basics) Start Condition • To initiate the address frame, the master device leaves SCL high and pulls SDA low. • This puts all slave devices on notice that a transmission is about to start. • If two master devices wish to take ownership of the bus at one time, whichever device pulls SDA low first wins the race and gains control of the bus. • It is possible to issue repeated starts, initiating a new communication sequence without relinquishing control of the bus to other masters
  • 13. I2C Protocol (Basics) Address Frame • The address frame is always first in any new communication sequence. • For a 7-bit address, the address is clocked out most significant bit (MSB) first, followed by a R/W bit indicating whether this is a read (1) or write (0) operation.
  • 14. I2C Protocol (Basics) NACK/ACK bit • It is the 9th bit of the frame • This is the case for all frames (data or address). • Once the first 8 bits of the frame are sent, the receiving device is given control over SDA. • If the receiving device does not pull the SDA line low before the 9th clock pulse, it can be inferred that the receiving device either did not receive the data or did not know how to parse the message. • In that case, the exchange halts, and it’s up to the master of the system to decide how to proceed.
  • 15. I2C Protocol (Basics) Data Frames • After the address frame has been sent, data can begin being transmitted. • The master will simply continue generating clock pulses at a regular interval, and the data will be placed on SDA by either the master or the slave, depending on whether the R/W bit indicated a read or write operation.
  • 16. I2C Protocol (Basics) Stop condition • Once all the data frames have been sent, the master will generate a stop condition. • Stop conditions are defined by a 0->1 (low to high) transition on SDA after a 0->1 transition on SCL, with SCL remaining high. • During normal data writing operation, the value on SDA should not change when SCL is high, to avoid false stop conditions.
  • 17. I2C Protocol 1. The master is initially in master transmit mode by sending a START followed by the 7-bit address of the slave it wishes to communicate with 2. This is finally followed by a single bit representing whether it wishes to write (0) to or read (1) from the slave. 3. If the slave exists on the bus then it will respond with an ACK bit (active low for acknowledged) for that address. 4. The master then continues in either transmit or receive mode (according to the read/write bit it sent), and the slave continues in the complementary mode (receive or transmit, respectively).
  • 18. I2C Protocol 5. The address and the data bytes are sent most significant bit first. 6. The master terminates a message with a STOP condition if this is the end of the transaction or it may send another START condition to retain control of the bus for another message (a "combined format" transaction).
  • 19. I2C Protocol If the master wishes to write to the slave, then it repeatedly sends a byte with the slave sending an ACK bit. (In this situation, the master is in master transmit mode, and the slave is in slave receive mode.) If the master wishes to read from the slave, then it repeatedly receives a byte from the slave, the master sending an ACK bit after every byte except the last one. (In this situation, the master is in master receive mode, and the slave is in slave transmit mode.) An I²C transaction may consist of multiple messages.
  • 20. Types of Transactions in I2C • I²C defines basic three types of transactions, each of which begins with a START and ends with a STOP: • Single message where a master writes data to a slave. • Single message where a master reads data from a slave. • Combined format, where a master issues at least two reads or writes to one or more slaves. • In a combined transaction, each read or write begins with a START and the slave address. The START conditions after the first are also called repeated START bits. Repeated STARTs are not preceded by STOP conditions, which is how slaves know that the next message is part of the same transaction.
  • 21. Timing Diagram 1. Data transfer is initiated with a start bit (S) signaled by SDA being pulled low while SCL stays high. 2. SCL is pulled low, and SDA sets the first data bit level while keeping SCL low 3. The data are sampled (received) when SCL rises for the first bit (B1). For a bit to be valid, SDA must not change between a rising edge of SCL and the subsequent falling edge 4. This process repeats, SDA transitioning while SCL is low, and the data being read while SCL is high (B2, ...Bn). 5. The final bit is followed by a clock pulse, during which SDA is pulled low in preparation for the stop bit. 6. A stop bit (P) is signaled when SCL rises, followed by SDA rising.
  • 22. Interfacing of 8051 with EEPROM (I2C Protocol)
  • 23. #include<reg51.h> #define ACK 1 #define NO_ACK 0 unsigned char i; unsigned char EData[5]; unsigned char Data; void DelayMs(unsigned int); void WriteI2C(unsigned char); void Start(void); void Stop(void); void ReadBYTE(unsigned int); void WriteBYTE(unsigned int); unsigned char ReadI2C(bit); sbit SCL = P2^0; // connect to SCL pin (Clock) sbit SDA = P2^1; // connect to SDA pin (Data)
  • 24. void main(void) //Main Program { WriteBYTE(0x0000); WriteI2C(‘A’); //Write Data’s Here WriteI2C(‘B’); WriteI2C(‘C’); Stop(); DelayMs(10); ReadBYTE(0x0000); EData[0] = ReadI2C(NO_ACK); EData[1] = ReadI2C(NO_ACK); EData[2] = ReadI2C(NO_ACK); while(1); }
  • 25. void Start(void) ///;Start I2C Protocol { SDA = 1; SCL = 1; _nop_();_nop_(); SDA = 0; _nop_();_nop_(); SCL = 0; _nop_();_nop_(); } void Stop(void) // Stop I2C protocol { SDA = 0; _nop_();_nop_(); SCL = 1; _nop_();_nop_(); SDA = 1; }
  • 26. void WriteI2C(unsigned char Data) //;WriteI2C { for (i=0;i<8;i++) { SDA = (Data & 0x80) ? 1:0; SCL=1;SCL=0; Data<<=1; } SCL = 1; _nop_();_nop_(); SCL = 0; }
  • 27. unsigned char ReadI2C(bit ACK_Bit) { Start(); WriteI2C(0xA1); SDA = 1; for (i=0;i<8;i++) { SCL = 1; Data<<= 1; Data = (Data | SDA); SCL = 0; _nop_(); } if (ACK_Bit == 1) SDA = 0; // Send ACK else SDA = 1; // Send NO ACK _nop_(); _nop_(); SCL = 1; _nop_();_nop_(); SCL = 0; Stop(); return Data;
  • 28. void ReadBYTE(unsigned int Addr) // Read 1 byte from I2C { Start(); WriteI2C(0xA0); WriteI2C((unsigned char)(Addr>>8)&0xFF); WriteI2C((unsigned char)Addr&0xFF); } void WriteBYTE(unsigned int Addr) //Write 1 byte to I2C { Start(); WriteI2C(0xA0); WriteI2C((unsigned char)(Addr>>8)&0xFF); // send address high WriteI2C((unsigned char)Addr&0xFF); // send address low }
  • 29. void DelayMs(unsigned int count) { unsigned int i; while(count) { i = 115; while(i>0) i- -; Count- -; } }
  • 30. Common applications of the I²C bus are: • Describing connectable devices via small ROM configuration tables to enable "plug and play" operation, such as • Accessing real-time clocks and NVRAM chips that keep user settings. • Accessing low-speed DACs and ADCs. • Controlling LCD displays. Applications of I2C