Está en la página 1de 9

Chapter 10: I2C protocol

I2C is an acronym for Inter Integrated Circuit bus. I2C is a 2-wire serial
interface standard defined by Philips Semiconductor in the early 198!s It!s
purpose was to pro"ide an easy way to connect a CP# to peripheral chips in
a $%-set. $he &#S physically consists of 2 acti"e wires and a ground
connection. $he acti"e wires' S() and SC*' are both bidirectional. +here
S() is the Serial (ata line and SC* is the Serial Cloc, line.
$he ,ey ad"antage of this interface is that only two lines -cloc, and data. are
re/uired for full duple0ed communication between multiple de"ices. $he
interface typically runs at a fairly low speed -1,12 to 3,12.. +ith I2C'
each IC on the bus has a uni/ue address. Chips can act as a recei"er and 4or
transmitter depending on it!s functionality.
$he I2C-bus is de"eloped by Philips to ma0imi2e hardware efficiency and
circuit simplicity. $he I2C interface is a simple master4sla"e type interface.
Simplicity of the I2C system is primarily due to the bidirectional 2-wire
design' a serial data line -S(). and serial cloc, line -SC*.' and to the
protocol format. &i-directional communication is facilitated through the use
of wire and connection -the lines are either acti"e-low or passi"e high. $he
I2C &us protocol also allows collision detection' cloc, synchroni2ation and
hand-sha,ing for multi-master systems. $he cloc, is always generated by
the master' but the sla"e may hold it low to generate a wait state. In most
systems the microcontroller is the master and e0ternal peripheral de"ices are
sla"es.
$he ma0imum number of de"ices connected to the I2C bus is dictated by the
ma0imum allowable capacitance on the lines' 3 p5' and the protocol!s
addressing limit of 16,7 typical de"ice capacitance is 1 p5. $he I2C
protocol has 128 addresses a"ailable. $he original "ision was to assign
addresses by de"ice function' but when Philips began to sell
microcontrollers for I2C' the address could be programmed' eliminating the
need for a Philips-assigned address.
) de"ice that controls signal transfers on the line in addition to controlling
the cloc, fre/uency is the master and a de"ice that is controlled by the
master is the sla"e. $he master can transmit or recei"e signals to or from a
sla"e' respecti"ely' or control signal transfers between two sla"es' where one
is the transmitter and the other is the recei"er. I2C bus support more than
one master connected to one bus.
$he I2C bus is an inno"ati"e hardware interface which pro"ides the software
designer the fle0ibility to create a truly multi 9mater en"ironment. It
possible to combine se"eral masters' in addition to se"eral sla"es' onto an
arbitration procedure decides master gets priority.
$o begin communication' the bus master -typically a microcontroller.places
the address of the de"ice with which it intends to communicate -the sla"e.
on the bus. )ll ICs monitor the bus to determine if the master de"ice is
sending their address. :nly the de"ice with the correct address
communicates with the master.
Philips! has o"er 1; C<:S and bipolair chips who are I2C-bus compatible'
and also some other companies ma,e ICs with I2C control interface.
$he I2C master is generally implemented with special I2C controller
-sometimes integrated to microcontroller. or sometimes using a
microcontroller and some software running on it. &oth approaches are
possible in typical one master I2C system. $he multi-master system is not
generally implemented with microcontroller software because it is e0tremely
difficult to meet all the I2C &us timing spec-ifications using software. 5or a
true sla"e or multi-master system' some interface hardware is necessary -li,e
S$)=$ >S$:P bit detection..
?owadays there are many different "ariations of I2C in use. @ach of the
"arious I2C deri"ati"es defines a slightly different direct current -(C.
electrical interface. I2C by definition is %. 1igh and low thresholds' rather
than being of fi0ed "alue' are a function of %CC for some parts. $here hac,s
to ma,e I2C to wor, also on other "oltages than ;%. In different application
de"ice addressing can "ary. ) liberal fi0ed addressing scheme is /uite
common -different type of de"ices get for e0ample four addresses each..
)CC@SS' bus uses dynamic addressing scheme.
*et us discuss the I2C protocol' by considering the chip (S 1623' $his chip
is used to indicate the temperature in centigrade. $he complete detail of chip
can be obtained from the sheet of the (allas Company. $his pin diagram is
shown in the figure'
$he features of this chip are followingA
$emperature measurements re/uire no e0ternal components
<easures temperatures from -;;oC to B12;oC in .;oC increments.
5ahrenheit e/ui"alent is -68o5 to 2;8o5 in .95 increments
$emperature is read as a 9-bit "alue byte transfer.
+ide power supply range -2.8% to ;.; %.
Con"erts temperature to digital word in 1 second
$hermostatic settings are user definable and non"olatile
(ata is read from4written "ia a 2-wire serial interface -:pen drain I4:
lines.
)pplications include thermostatic controls' industrial Systems'
consumer products' thermometers' or any $hermal sensiti"e system.
PI? (@SC=IP$I:?
S() -2- +ire Serial (ata Input4:utput
SC* - 2-+ire Serial Cloc,
C?( - Cround
$ou$ - $hermostat :utput Signal
) - Chip )ddress Input
)1 - Chip )ddress Input
)2 - Chip )ddress Input
%(( - Power supply %oltage
$his chip contain )(C' Sensor and decoder. $he (S1621 digital
thermometer thermostat pro"ides 9-bit temperature readings which indicate
the temperature of de"ice. $he thermal alarm output' $:#$' is acti"e when
the temperature of the de"ice e0ceeds a user 9defined temperature $1. $he
output remains acti"e until the temperature drops below user defined
temperature $*' allowing for any hysteresis necessary. #ser defined
temperature settings are stored in non-"olatile memory' so parts may be
programmed prior to insertion in a system. $emperature settings' and
temperature readings are all communicated to4from the (S1621 o"er a
simple 2-wire serial interface.
$he thermal alarm output -$out. of IC ds1621 acti"ates when the temperature
e0ceeds user defined high temperature $1. $he output remains acti"e until
the temperature drops below user defined low temperature $I. #ser definds
temperature setting is stored in the non-"olatile memory. $emperature
setting and temperature reading are all communicated to4from IC (S1621
o"er 2-wire serial cable. $he most significant bit -*S&. is transmitted last.
$he data sheet of the chip is also gi"en in the C(.
)ddressing
$he chip address of (S1621 comprises internal preset code nibble
D11!-binary. followed by e0ternally configurable address pin 4bit )2' )1
and ). $he eight bit of the address byte is determined by the type of
operation -either read or write. that is to be performed. 5or writing to the
de"ice the eight bit is D! and for reading from the de"ice the eight bit is!1!.
In our case' )2' )E )nd ) pins are grounded and hence the de"ice address
for writing is 11b or 9-he0. and for reading the de"ice address is
D111b! or 91 -he0..
Configuration4status register
$his register can be accessed for reading or writing by issuing command
byte )C -he0. from the master -82C;2.. $his register particularly re/uired
(s1621 is used for thermostat control' since it contains flag bits $15 -high
temperature flag. and $*5 -low temperature flag. which are set to D1! when
temperature crosses the respecti"e limits earlier written into $1 and $*
registers. It also contains the flag bit -(one.' which is set to' 1' when results
of con"ersion are a"ailable after issuing of start con"ersion command @@
-he0.. $he other bits of configuration register are defined belowF
(:?@ $15 $*5 ?%+ 1 P:* 1S1:$
<S& *S& D?%&! is the
?on "olatile memory busy flag D1!is write to an @ memory cell in progress'
D! indicate that non "olatile memory is not busy' @2 may ta,e up 1 ms. If
1S1:$ is D! acti"e-low. and DIS1:$! is one 9shot mode. ) copy @2 may
ta,e up to 1 ms. If 1S1:$ is D! (S1621 will continuously perform
temperature con"ersions. $his bit is non "olatile.
Command Set
Complete command instruction set for accessing "arious internal registers as
well as for starting and stopping of con"ersion process are gi"en in $able 1.
5or understanding the e0act
Instruction (escription Protocol
=ead $emperature =ead last con"erted temperature "alue form temperature
register. )sh
=ead counter =eads "alue of count remaining from counter )8h
Start Slope =eads "alue of the slope accumulator )9h
Start Con"ert $ Initiates temperature con"ersion @@h
Stop Con"ert $ 1alts temperature con"ersion 22h
)ccess $1 =ead or write high temperature limit "alue into $* register. )1h
)ccess $* =ead or write low temperature limit "alue into $* register )2h
)ccess Configuration =eads or write configuration data to configuration
register )ch
Se/uence in which Start bit' address byte' ac,nowledgement bit' command
byte -s. and data byte-s. are to be sent along the I2C bus refer to the
datasheet to (S1621 wherein these aspects ha"e been e0plained in proper
detail. $his will help understanding the contents of the main program.
Port and are 8-bit bidirectional input4output -I4:. ports. $hese ports
ha"en!t been used in this temperature reader. Port 1 is an 8-bit bidirectional
I4: port with internal pull 9ups. Ports 1. through 1.8 are connected to pins
8 through 13 of the *C(. Port -1 output buffers can sin,4source four $$I
inputs.
Port G is an 8-bit bidirectional I4: port with internal pull-ups. Ports G. and
G.1 of IC2 are connected to serial cloc, line -SC*. and serial data line
-S(). of ICG' respecti"ely. Ports G.2 through G.3 are connected to pins 3
through 6 of the *C(' respecti"ely. Port G output buffers can sin,4source
four $$* inputs.
) 12<12 crystal oscillator is connected to H$)*1 and H $)*2 Pins for
operation of the microcontroller. ) high pulse on =S$ pin -pin9. while the
oscillator is running resets the microcontroller. I? this circuit' this pin is
connected to B%cc through capacitor C; -1 micro 5 16%.. $he e0ternal
access enable pin -@). is connected to B %cc for internal
Program e0ecution. $his pin also recei"es the 12% programming 9enable
"oltage -%pp. during flash programming when 12% programming is
selected.
1ere is the circuit diagram to interface the )SCI chip with the
microcontroller'
5igF Circuit diagram for interfacing of the (S1621
$o communicate with I2C chip' following protocol is used'
Start data transferF ) change in the state of the data line' from 1IC1 to
*:+' while the cloc, is 1IC1 to *:+' while the cloc, is 1IC1' defines a
S$)=$ condition. So coding will be following
I2CS$)=$F
S@$& S()
)C)** (@*)I:?@
S@$& SC*
)C)** (@*)I:?@
C*= S()
C*= SC*
Stop data transferF ) change in the state of the data line' from *:+ to
1IC1' while the cloc, line is 1IC1' defines the S$:P condition. So coding
will be following
C*= S()
C*= SC*
S@$& SC*
)C)** (@*)I:?@
S@$& S()
<:% C'S()
=@$
$he concept can be understand by following timing diagram
5igF $iming (iagram for the data transfer
(ata "alidF $he state of the data line represents "alid data when' after a
S$)=$ condition' the data line is stable for the duration of cloc, signal. $he
data on the line must be changed during the *:+ period of cloc, signal.
$here is one cloc, pulse per bit of data.
$here is following coding for data transfer and recei"ing.
I2C+=I$@F
<:% =' J81
I2C+=I$@K*::PF
=*C )
<:% S()' C
S@$& SC*
)CC)** (@*)I:?@
C*= SC*
(L?M =' I2C+)=@$@K*::P
C*= SC*
=@$
I2C=@)(F
<:% ='J8
I2C=@)(K*::PF
S@$& SC*
<:% C' S()
=*C )
)C)** (@*)I:?@
C*= SC*
(L?M =' I2C=@)(K*::P
=@$
)ppendi0 )
=eference +ebsiteF
www.proframmershea"en.com
www.8;2.com.
www.embedded.com
www.microcontroller.com
)ppendi0 &
(ata Sheet of )$<@* 89C;1 C1IP
)ppendi0 C
Instructions of 8;1

También podría gustarte