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 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.