Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
2
An I2C bus analyser to let
you satisfy your curiosity
Etienne Boyer
In this article, we propose a microcomputing instrument that’s valuable – not to say indispensable
– when it comes to analysing what’s happening on the I2C bus. It lets you examine the most
interesting signals carried by this very common, easy-to-implement interconnection
bus.
The heart of the circuit takes the form Now that START detection has taken C2
of a microcontroller from Microchip. place, all we have to do is detect each
The PIC18F4520 [2] is an improved SCL clock pulse and sample the data 2
1n
1
version of the 18F452, but is still pin- SDA at this moment. Once the signals RCX CX
4 6 START
compatible, not only with the latter, have been analysed, the microcon-
but also with the famous 16F877. Its troller will store each event in memo- ≥1
5 IC2.A 7
function is to analyse, by scanning, in- ry in the same way as a data logger.
put lines RC3 and RC4 of the PIC, di- The four events are START, BYTE, AC- R
rectly driven by the SCL (Serial CLock) KNOWLEDGE, and STOP. The memory 3
and SDA (Serial DAta) signals. Push- gets filled up at the rate of the traffic on SDA SCL
button S3 (SCAN) starts the analysis. the bus, and once full is transferred by
Closer examination of the circuit leads a serial link to the PC ( USB is by defini-
us to ask the inevitable question: tion a serial link, not a parallel one ). Figure 2. A monostable triggered by a falling edge.
ciated with the events STOP (D1) and
START (D2) respectively.
Two 27 Ω resistors protect the Data+
and Data– lines. The FT232BM IC
switches +5 V to resistor R16, indicat -
ing two things to the host USB (PC):
first of all, presence of the peripheral,
and secondly recognition of the Full
Speed mode, since R16 is connected
to Data+.
One interesting component is induc-
tor L1, a ferrite bead intended to sup-
press high-frequency interference. Its
impedance goes from 0.15 Ω at dc to
70 Ω at 100 MHz, thereby dissipat-
ing any electromagnetic interference
(EMI) as heat. In addition, it acts as a
fuse if you have the misguided idea of
short-circuiting our circuit’s +5 V sup-
Figure 3. Creation of the Start and Stop.
JP1
8k2
START R13
R6
C2 C4
470 Ω
330 Ω
TP7 L1
1n 100n
2 1 START 14 15 T2
RCX CX RCX CX
4 6 12 10
VCC VCC VCC
≥1 ≥1
5 IC2.A 7 11 IC2.B 9 2N7000
C10 TP3 C9
R R C12
VCC 100n 10n
3 13
SDA SCL 33n K1 3 26
R8 1
K2
4k7
2 13 30
11 32 VCCIO AVCC R14 1
3 4 8 +5V
VCC RESET USBDM 27 Ω 2
1 40 4 2 D–
MCLR/VPP RB7/PGD EEDATA R15 3
R7 39 5 1 7 D+
RB6/PGC EESK USBDP 27 Ω 4
TP6 IC3 IC4
470 Ω
2 38 6 11 GND
RA0/AN0 RB5 RXLED R16
SCOPE- 3 37 12 5
RA1/AN1 RB4 ISP ICD TSLED RSTOUT 1k5
TRIGGER 4 36 15 19 USB
S1 RA2/AN2/VREF- RB3/PGM TP5 PWREN DCD
5 Tx 20
RESET RA3/AN3/VREF+ DSR
VCC 6 25 24 23
RA4/T0CKI RC6/TX/CK RXD RTS
K3 7 26 25 22
1 RA5/AN4/SS RC7/RX/DT TXD CTS
START 8 21
2 RE0/RD/AN5 DTR VCC
9 19 Rx 32 FT232BM 18
3 VCC RE1/WR/AN6 RD0/PSP0 TP4 EECS RI
10 20 16 10
4 RE2/CS/AN7 RD1/PSP1 TXDEN SLEEP
21 6 29
5 RD2/PSP2 3V3OUT AGND
22 VCC 14 31
6 RD3/PSP3 PWRCTL TEST 16 16
R9 R10 15 27
RC0/T1OSO/T1CKI RD4/PSP4 XIN XOUT
I 2C TP2 16 28 IC1 IC2
10k
10k
RC1/T1OSI/CCP2 RD5/PSP5 9 27 28 17
K4 SDA 17 29 R11 R12 X2
1 RC2/CCP1 RD6/PSP6 8 8
18 30
1k
1k
2 RC3/SCK/SCL RD7/PSP7
3 PIC18F4520 C11 C7 C8
23 35
4 RC4/SDI/SDA RB2
24 34 33n 22p 22p
5 RC5/SDO RB1 6MHz IC1, IC2 = 4538
SCL 33
6 RB0/INT
TP1 STOP
OSC1 OSC2 S2 S3 VCC
I 2C 12 13 14 31
K5 X1 R1 R3 D1
1 rouge
DISPLAY SCAN
1M5
8k2
2 STOP
3 C5 C6 R5
C1 C3
330 Ω
4
5 22p 20MHz 22p TP8
1n STOP 100n
6 2 1 14 15 T1
RCX CX RCX CX
2 SDA 4 6 12 10
I C
≥1 ≥1
5 IC1.A 7 11 IC1.B 9 2N7000
R R
3 13
SCL
070600 - 11
VCC
Figure 4. The circuit electronics don’t amount to very much: a PIC/USB chip double-act surrounded by a handful of connectors of all types…
ply, thereby protecting the power sup-
ply from the PC. In connection with
this, note the presence of a header +
jumper JP1, which makes it possible
to disconnect the PC supply.
PCB
It goes without saying that such a cir-
cuit merits a PCB. The screen-print-
ed component overlay is shown in
Figure 5.
T h e m a n / m a c h i n e i n t e r f a c e :
Figure 6. Screen dump of Monitor I2C program.
installation
This application, written in C++
Builder V5.0, runs under Windows
existing I²C bus, the four monostables help of cross-compiler PCH compiler and is easy to install by copying the
ought to react to the arrival of a Start V4.010 from CCS (Custom Computer executable monitor_I2C.exe. This
and a Stop by lighting the green and Services). This compiler tolerates a application requires prior installation
red LEDs respectively. certain flexibility in the academic C of drivers on the PC. To do this, it’s
Then the PIC can be programmed. language, and so is very well suit- worth consulting the FTDI [3] web-
ed to programming by electronics site and the previous Elektor articles
technicians. on this subject.
Software Development is carried out under
The microcontroller source program MPLAB V.7.62. The program, which RS-232 configuration
is written in C and compiled with the runs under Windows, is written in At start-up, an initial dialogue box lets
you select the Virtual Com Port via
which the USB link is going to receive
the data sent by the PIC in the form
of a standard asynchronous serial link
(transfer speed 128,000 baud).
Then the status bar indicates that the
serial port has been opened properly.
Displaying the results
Scanning is started by operating push-
button S3 (SCAN). The I²C events are
then recorded by the circuit and ap-
pear according to a colour code cor-
responding to the I²C event. Screen
dump Figure 6 shows the main screen
when acquisition is finished; in it you
will be able to recognize the STARTs
in green, the STOPs in red, the ad-
dresses in ultramarine blue, and the
data in royal blue. However, this dis-
play will be modified by the value of
the acknowledge bit: if it is present,
we see these two in blue, but if it is
absent, they will be greyed out.
The status bar also shows the format
of the codes transmitted on the serial
link between the circuit and the PC
(ASCII coding).
Figure 7. Scope_trigger screen dump Example:
The secrets of I2C and its bus
SDA
SDA SDA
SCL
SCL SCL
S P
data line change STOP condition
START condition
stable; of data
data valid allowed
A B
The I2C (Inter Integrated Circuit) bus was dreamt up by Philips, at the the SDA line has gone back to ‘1’ and the SCL line is also at ‘1’, we
time when they were one of the leading manufacturers of audio equip- have the StopBit.
ment. Its major fields of application were home automation and home
electronics in the early 80s. Microprocessors were putting in an ap- 3) Transfer of data onto the I2C bus (Figure C).
pearance in TVs, and they needed to find a cheap, easy technique for
interconnecting the various electronic sub-assemblies in such devices. This condition having been defined, the master places the MSB on the
SDA line. It validates the data by briefly forcing the SCL line ‘high’. It
The I2C bus is a synchronous serial bus with just 3 lines: Data, (SDA), continues in the same way for the various bits right down to the LSB.
Clock (SCL), and ground (used as a reference). The transmission over, the slave forces the SDA line low, this is the…
Operation of the bus is based on the concept of master (the peripheral 4) Acknowledge signal on the I2C bus (Figure D).
that manages the communication, generates the clock, and transmits
the data) and slave (the peripheral that receives the data and confirms The slave component issues this signal to indicate reception of all the
reception by an ‘acknowledge’ signal). But don’t let’s be deceived: data. If everything is OK, it forces the line to ‘0’.
despite its rustic simplicity, this bus can handle several microcontrollers
Despite its simplicity, the I2C bus allows handling of relatively complex
without conflicts, as long as certain rules are properly obeyed.
operations. The various scope traces given in the article illustrate this
The four most important situations in this protocol are illustrated below. operation very well.
1) Transfer of a bit onto the I2C bus (Figure A). It’s worth noting that a master-component can also receive data from
a slave (master-receiver).
The clock doesn’t really have the ‘form’ of a real clock, since it can
have variable mark/space ratios (within constraints). If you want to find out more, all is explained in the I2C bus specifica-
tions from January 2000:
2) START and STOP conditions (Figure B).
http://www.nxp.com/acrobat_download/literature/9398/39340011.
At the start of communication, the SDA line goes to ‘0’ while the SCL pdf
lines is at ‘1’. This is the StartBit. At the end of communication, when
(Illustrations: Philips Semiconductors)
P
DATA OUTPUT
SDA BY TRANSMITTER
MSB acknowledgement acknowledgement Sr
signal from slave signal from receiver not acknowledge
byte complete,
interrupt within slave DATA OUTPUT
BY RECEIVER
clock line held low while
interrupts are serviced
acknowledge
SCL S Sr
or 1 2 7 8 9 1 2 3-8 9 or SCL FROM
Sr P 1 2 8 9
ACK ACK MASTER
START or STOP or S
repeated START repeated START
condition condition clock pulse for
START
C D condition
acknowledgement
->S00 for the START SCOPE_TRIGGER pin to synchro- reveals the transition of the SCOPE_
->V20 for an acknowledged byte with nize a scope in external trigger mode. TRIGGER signal at the moment of the
a value of 20 (HEX) This makes it possible to display the ninth SCL clock pulse. This instant,
->v20 for an unacknowledged byte shapes of the SDA and SCL signals which normally corresponds to the
with a value of 20 (HEX) just at that instant. For example, the reply from the receiver, enables us
->P00 for the STOP. screen dump in Figure 7 represents to read a ‘1’ on SDA, indicating that
the SCOPE_TRIGGER signal for the there has been no acknowledgment:
O s c i l l o s c o p e s y n c h r o n i z a t i o n sync byte 21 (HEX). The top part of from that moment on, the I²C circuit
function the trace clearly shows how each time with the address 10 (HEX) for which
This utility lets us configure the set- this byte occurs, the signal toggles data bytes 21 22 23 were intended
up with a synchronization byte, which for the duration of the next byte. The is considered as absent from the bus
when it is present in the frame trig- central section shows the magnified or defective.
gers a synchronization pulse on the portion with a zoom factor of 10 and
Delay function analyser, connect the latter to a PC,
Another utility function makes it pos- start the monitor_I2C.exe program,
sible to delay the start of recording press the SCAN button, followed a
of a certain number of events; in this few moments later by a press on S2,
case they are replaced on the display DISPLAY, and wait for the first data to
by a dot. appear on the screen.
I²C summary
A built-in help page includes a brief
Conclusion
summary of a few definitions of events This simple-to-use circuit using stand-
present on an I 2C bus. In addition, it ard components (CMOS logic ICs, PIC
shows the recording of real signals. microcontroller, USB interface) makes
To transmit data over the I²C bus, it is it possible to analyse the signals
necessary to monitor two specific con- present on an I²C bus. One further de-
ditions: Start and Stop. The Start con- velopment of the circuit might be to fit
Photo of the prototype. Note that component designations have been changed in the final version.