Working with I2C protocol

The I2C protocol provides a lightweight and convenient interface for sensors and controllers connected to microcontroller systems. Five Wire provides a number of tools that support hardware and firmware development using I2C. The Live Logic and Logic Analyzer tools can capture and decode I2C traffic providing a human friendly description of each I2C transaction. The I2C protocol tool can emulate an I2C master or slave device allowing you to take control of the I2C bus to better understand a peripheral devices behavior or provide direct control over the system.

Live Logic provides 2 channels of digital capture using scope probes. This makes it easy to probe SCK and SDA to capture I2C traffic. For example, here is an I2C read of a real-time clock (RTC) date/time value.

To read the RTC, the master must first write the address to read, 0x00, and then read 7 bytes which encode the date and time using the BCD format. We can zoom in on the waveform and inspect the timing or individual bits. However, for this example we want to know the contents of the transaction. First we must select a decoder for the protocol.

We select the I2C decoder using the default settings. Once selected, marks will be placed over the data describing the transaction.

The decoder shows that the RTC was accessed at I2C address 68 and a zero was written. Then 7 bytes were read. These bytes are BCD encoded so you can read them directly. 26 seconds, 42 minutes, 9 hours, day of the week 4 (Thursday), day 27, month 9, year 18.

Although this is a great improvement you can go further by customizing the decoder. Five Wire provides the ability to write your own decode (dcd) scripts which determine how the data is converted into human readable strings. If you browse the Documents/Anewin/FiveWire/decoders folder you will find the i2c.dcd decoder that was used to decode this transaction. The dcd scripts are simple text files. When you load the I2C decoder you can select your custom decoder. Here is an example of a custom dcd used with the RTC.

Now the read is decoded to show the contents of the transaction so you don’t have to mentally decode the bytes.

The Logic Analyzer provides more capture channels so you can observe other activity while capturing I2C transactions. The Logic Analyzer provides the same decode capability and dcd scripts but also supports loading multiple decoders. For example, you can load an I2C decoder on channels 0 and 1, monitor a digital output on channel 2 and load an RS232 decoder on channel 3 as in this example.

With the Five Wire I2C Protocol tool you can take control of the I2C bus as shown in the example below. By entering a few lines to define the desired I2C transaction, the Five Wire Protocol tool can emulate an I2C master doing reads and writes to retrieve the date/time from the RTC.

On line 1 we wrote a zero to the RTC. On line 2 we read 7 bytes (14:55:10 Thursday 09/27/18). In addition to read and write transactions you can include commands that insert delays between transactions, pause execution and wait for an event from another tool or an external trigger source, and form infinite loops to provide a repeated transactions.

The I2C Protocol tool can also act as a slave device. This allows emulation of a missing device or provide exact control over the I2C responses. In the example below the system makes an access to a emulated RTC at address 2. The slave has been programmed to return the date Monday, Sept 1, 2018, 12:00:00. A microcontroller was programmed to access the I2C address 2 and send the response out on its RS232 output. Here is the captured transaction using the Logic Analyzer tool.

Five Wire provides broad support for the I2C protocol. Because of the wide adoption of I2C as a peripheral interface, the capture/decode and protocol emulation capabilities can simplify debug and evaluation of I2C device operation and firmware development.

What is this Live Logic Tool – what is it good for?

Anyone who uses a logic analyzer knows where to find it – its on a cart in the back of the room. Its there for a reason – no one wants to use it. It takes too long to set up to get the data you are looking for. So you try to solve the problem with a scope until you get to the point where you have no choice. Then you drag out the logic analyzer.

What we realized is that engineers have to invest time in a test tool every time they want to make a measurement. With a scope you can get a little information by just touching the probe to the circuit – the signal is toggling, stuck high, or stuck low. Twisting the trigger level and time per div knobs gets you a stable display so you can see the shape of the waveform. Not much effort gets you a lot of data.

Live logic has the goal of giving you a lot of information with not much effort and to capture your hard to see digital signals. It uses scope probes so you can just touch your circuit. An activity LED on each channel immediately tells you if the signal is toggling. The graphic display is continuously updating and auto-scaling so you immediately see the waveform shape – less setup effort than a scope! In addition, the average voltage of your signal is shown on a DVM for each channel so you can check your logic supplies or PWM levels. You get a lot of information by just touching the probe to your signal.

OK, so why is this any better than my scope? Your scope is a great tool but it is designed to display analog signals. This fundamental requirement means that it must be sampling your signal continuously – a good thing if you are interested in measuring overshoot! But if you are looking at an RS-232 signal or an I2C transaction that happens only occasionally and is different every time, your scope will run out of memory, filling it with the static logic levels that exist between these transactions. Yes you can trigger on the first edge and see the start of the transaction but what about seeing the whole transaction or even better, the one that follows this one as well.

Live Logic was designed to only capture digital signals. It ignores those long periods of static logic levels between your transactions. It focuses on the action – it stores signal changes. The only thing that is stored are the transitions in your I2C signal – the thing you are trying to see. If your processor sleeps most of the time waking up to check the local temperature, its no problem. Live Logic can capture time spans as large as 73 minutes! Of course it does have a memory limit just like your scope but that memory is only used to store useful information.

That’s it. That’s the whole reason for Live Logic. It doesn’t replace your scope but its just as easy to use and it can capture digital signals that are challenging for your scope. Add an MB-500 with Live Logic to your bench and your life as an embedded engineer can become a whole lot easier.




Welcome to the Anewin blog

Welcome to our blog! Our goal is to provide useful and timely information to help our customers get the most out of their Anewin products. The blog will include:

  • Application examples that solve real world problems
  • Tips and tricks
  • Tutorials
  • Just for fun topical discussions
  • News about Anewin

Thanks for your interest in Anewin and our flagship product the MB-500.

Mike Hagen

Principal, Anewin LLC