SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral InterfaceAnurag Tomar
 
SPI introduction(Serial Peripheral Interface)
SPI introduction(Serial Peripheral Interface)SPI introduction(Serial Peripheral Interface)
SPI introduction(Serial Peripheral Interface)SUNODH GARLAPATI
 
Serial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System ProtocolSerial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System ProtocolAditya Porwal
 
Embedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerEmbedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerGaurav Verma
 
8051 Microcontroller I/O ports
8051 Microcontroller I/O ports8051 Microcontroller I/O ports
8051 Microcontroller I/O portsanishgoel
 
AMBA 3 APB Protocol
AMBA 3 APB ProtocolAMBA 3 APB Protocol
AMBA 3 APB ProtocolSwetha GSM
 
I2C And SPI Part-23
I2C And  SPI Part-23I2C And  SPI Part-23
I2C And SPI Part-23Techvilla
 
PPT on 8085 Microprocessor
PPT on 8085 Microprocessor  PPT on 8085 Microprocessor
PPT on 8085 Microprocessor DebrajJana4
 
Programmable Peripheral Interface 8255
 Programmable Peripheral Interface   8255 Programmable Peripheral Interface   8255
Programmable Peripheral Interface 8255Dr.P.Parandaman
 

Tendances (20)

UART
UARTUART
UART
 
I2C Protocol
I2C ProtocolI2C Protocol
I2C Protocol
 
Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral Interface
 
SPI introduction(Serial Peripheral Interface)
SPI introduction(Serial Peripheral Interface)SPI introduction(Serial Peripheral Interface)
SPI introduction(Serial Peripheral Interface)
 
8086
80868086
8086
 
Serial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System ProtocolSerial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System Protocol
 
Embedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerEmbedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontroller
 
I2C BUS PROTOCOL
I2C BUS PROTOCOLI2C BUS PROTOCOL
I2C BUS PROTOCOL
 
Communication protocols - Embedded Systems
Communication protocols - Embedded SystemsCommunication protocols - Embedded Systems
Communication protocols - Embedded Systems
 
Amba bus
Amba busAmba bus
Amba bus
 
RS 232
RS 232RS 232
RS 232
 
8051 Microcontroller I/O ports
8051 Microcontroller I/O ports8051 Microcontroller I/O ports
8051 Microcontroller I/O ports
 
Serial Communication in 8051
Serial Communication in 8051Serial Communication in 8051
Serial Communication in 8051
 
8086 micro processor
8086 micro processor8086 micro processor
8086 micro processor
 
AMBA 3 APB Protocol
AMBA 3 APB ProtocolAMBA 3 APB Protocol
AMBA 3 APB Protocol
 
I2C And SPI Part-23
I2C And  SPI Part-23I2C And  SPI Part-23
I2C And SPI Part-23
 
PCI express
PCI expressPCI express
PCI express
 
Verilog hdl
Verilog hdlVerilog hdl
Verilog hdl
 
PPT on 8085 Microprocessor
PPT on 8085 Microprocessor  PPT on 8085 Microprocessor
PPT on 8085 Microprocessor
 
Programmable Peripheral Interface 8255
 Programmable Peripheral Interface   8255 Programmable Peripheral Interface   8255
Programmable Peripheral Interface 8255
 

Similaire à 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
 
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
 

Similaire à 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
 
I2 c
I2 cI2 c
I2 c
 
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
 
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
 

Plus 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
 
Silicon on Insulator (SOI) Technology
Silicon on Insulator (SOI) TechnologySilicon on Insulator (SOI) Technology
Silicon on Insulator (SOI) TechnologySudhanshu Janwadkar
 

Plus 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
 
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
 
Silicon on Insulator (SOI) Technology
Silicon on Insulator (SOI) TechnologySilicon on Insulator (SOI) Technology
Silicon on Insulator (SOI) Technology
 

Dernier

Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 

Dernier (20)

Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 

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