Skip to main content

Subsection 10.1.4 Part 3b: One Transaction, Captured on the Scope

Here is what those two wires carried, field by field (Figureย 10.1.10).
Figure 10.1.10. One I2C message, field by field. It opens with a START condition and closes with a STOP, and between them the controller sends an address frame (seven address bits and the read/write bit) followed by as many data frames of eight bits as it needs. Every frame is followed by a single ACK/NACK bit from whichever device is receiving.
SCL and SDA idle high, because of the pull-ups. The controller asserts control by pulling SDA low while SCL is high (the START) and SCL starts running. It then transmits the device address, seven bits, followed by a 0 to command a write or a 1 to command a read. It lets go of the data line, and the peripheral that recognizes its address acknowledges by sending a 0 back: the ACK. Other devices on the bus do not respond, and if nobody responds at all the data line simply stays high, which is called a NACK. Then data bytes, each one acknowledged the same way, and finally the STOP: the controller returns SDA to high while SCL is high, and both lines go back to idle.
One question is left: if SDA is the line carrying the bits, how does a device tell a START from an ordinary 0 going by?
There is one rule: With the exception of START and STOP conditions, SDA is allowed to change only while SCL is LOW. So while SCL is HIGH, SDA holds still and is read by devices sampling the line. The protocol then takes the one thing that rule forbids and uses it to mark the edges of a transaction. A START condition is SDA going from HIGH to LOW while SCL is HIGH; a STOP condition is SDA going from LOW to HIGH while SCL is HIGH. Neither can occur during normal data transfer, so neither can be mistaken for a bit, and every device on the bus recognizes them immediately.
One more piece. After the seven address bits and the R/W bit the controller lets go of SDA and keeps clocking, and the device whose address matched pulls SDA LOW for that ninth pulse. That one-bit reply is the ACK. SDA staying HIGH is a NACK (nobody claimed that address), and every data byte after the address is acknowledged the same way, by whichever side is receiving.
Figure 10.1.11. The two exceptions, on the wire. SCL is above and SDA below, and the shaded bands mark the SCL LOW phases, the only times SDA is allowed to move. At the left SDA falls while SCL is still HIGH, which is the START condition; at the right it rises while SCL is HIGH, which is the STOP. Neither can happen during an ordinary data bit, which is what makes them unmistakable.
Figureย 10.1.12 is the whole of it in one picture: START, seven address bits, the R/W bit, ACK, a data byte, ACK, STOP.
Figure 10.1.12. One I2C write transaction. SCL (top) begins clocking once the START condition has occurred. SDA (bottom) shows the START (SDA falling while SCL is HIGH), then seven address bits and the R/W bit, which for address 0x70 and a write are 1 1 1 0 0 0 0 followed by 0; then the ACK, with the addressed device pulling SDA LOW; then eight data bits, 0xAA = 10101010, most significant bit first; then a second ACK; and finally the STOP, SDA rising while SCL is HIGH. Receivers sample SDA during the SCL HIGH phase, and SDA may change only while SCL is LOW, the START and STOP conditions being the two deliberate exceptions.
The loop in helloDisplay.c is putting one of those on the wire four times a second, so all six parts of that diagram are visible when using an oscilloscope, which is what weโ€™ll do now.
Figure 10.1.13. The AD2 in oscilloscope mode, set up for this capture. The trigger is the part that matters: source Channel 2, the one on SDA; type Edge; condition Falling; level 1 V. SDA idles HIGH and the first thing that happens in a transaction is SDA falling, so that setting catches the START. The time base is 25 ยตs per division with the position at 100 ยตs, which fits the whole transaction on screen, and the two channels are given different offsets (โˆ’4 V on channel 1, 500 mV on channel 2), so the traces sit one above the other instead of on top of each other.

Activity 10.1.2. Capture a Transaction and Mark It Up.

Weโ€™ll now use the AD2 to look at the oscilloscope trace of the I2C transaction that is happening on SDA and SCL.

(a)

Put your AD2 in oscilloscope mode and tap the two bus wires: channel 1 (orange) on SCL (PB8, D15), channel 2 (blue) on SDA (PB9, D14), and both minus leads, the ones with the white stripe, to ground.

(b)

With your helloDisplay.c running, take a single sweep. Because of the 250 ms delay in the loop you are catching one transaction out of four per second, so the trigger is what matters: source Channel 2 (SDA), type Edge, condition Falling, level 1 V. SDA idles HIGH and falls at the START, so that setting catches it.

(c)

Take a screenshot of your capture and, with any markup tool, mark all six on it: the START, the seven address bits, the R/W bit, the ACK, the data byte, and the STOP. Read off the eight bit values of that first byte, the seven address bits and the R/W bit after them, in the order they go out.

(d)

How many clock pulses are in your capture, and why that many? Count them on the screen and verify with the protocol.

(e)

Two bytes went out in that transaction: the address byte and the data byte, which for this loop is 0x00. Which eight clock pulses would change if you altered the data, and which if you altered the address?
Both channels sitting HIGH and nothing ever happening? The bus is idle and correctly pulled up; the scope has not triggered. In Waveformsโ€™ trigger panel, set the source to the channel on SDA and the condition to a falling edge, then arm a single sweep again. Nothing there is a wiring problem, and the display staying lit is the proof.