Oscilloscopes offer a variety of
tools to help diagnose troublesome circuits. In this tutorial, we will
use the oscilloscope to read an I²C serial bus.
Getting a Scope
For more information on how to obtain an oscilloscope, please refer to Part 1.Project Overview
I will use the Tektronix Multi-Domain Oscilloscope 3104 to decode I²C data and determine the I²C address for a device by sequentially polling all addresses and looking for an acknowledge (ACK) signal. Any I²C device will do. I received an evaluation kit for the Infineon 3D Hall-Effect Sensor, and I will use this as my I²C device.Product | Cost (and Product Link) | Other Information |
---|---|---|
Infineon 3D Magnetic Sensor 2 Go Kit | $28 | Kit Manual | Sensor Manual | Sensor Product Brief |
4 Position Header (0.100") | $1 | Datasheet |
Arduino Uno R3 | $15 | Product Information |
Bi-Directional Logic Level Converter | $3 | Datasheet |
Jumper Wires | $3 |
Setting Up the Circuit
The Arduino board that I used operates with 5V logic. The 3D2GO evaluation kit is supplied by 3.3 V. That means a Bi-Directional Logic Level Converter (BD-LLC) must be inserted between the data lines of the Arduino and the evaluation kit.To insert your BD-LLC between the Arduino and your I²C device, make the following connections:
- GND from the Arduino to GND on the BD-LLC
- GND from the BD-LLC to GND on the 3D2GO
- 3.3V from the Arduino to Low Voltage (LV) on the BD-LLC
- LV on the BD-LLC to 3.3V on the 3D2GO
- Arduino 5V to High Voltage (HV) on the BD-LLC
- Arduino SDA to HV1
- Arduino SCL to HV2
- BD-LLC LV1 to 3D2GO SDA
- BD-LLC LV2 to 3D2GO SCL
Setting up the Oscilloscope
Next, you'll need to set up your oscilloscope. To do that, follow these steps:- Turn on the oscilloscope and wait until it completes its self-tests.
- Plug probes into Channel 1 and Channel 2.
- Connect the probe's ground clip to a ground point in the circuit (use a jumper wire if necessary).
- Connect Probe 1 to SDA and Probe 2 to SCL (use a jumper wire if necessary).
// I2C Scanner from Arduino.cc
// Attribution to Krodal, Nick Gammon, Anonymous
#include
void setup()
{
Wire.begin();
Serial.begin(9600);
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address <= 127; address++)
{
// The i2c_scanner uses the return value of
// Wire.endTransmission to see if
// a device acknowledged the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // wait 5 seconds for next scan
}
Now, every 5 seconds, the Arduino will poll I²C addresses 1-127. If a device exists at the address polled, it will send an acknowledge signal to the Arduino by pulling the SDA line low after the address byte has been transmitted.
We can now move on to using the oscilloscope to decode the I²C bus.
Use the following steps for a Tektronix MDO3000 or MDO4000 series oscilloscope, with generic instructions for any oscilloscope in parentheses.
- Press the Channel 1 button (turn on oscilloscope channel 1)
- Press "Label" (label your inputs if you are able to)
- Use Multipurpose b to scroll down to "DATA" (label channel 1 "Data")
- Select "Insert Preset Label"
- Use the Vertical Scale Knob below the Channel 1 button to set 2 volts per division (decrease the height of the signal so it fills less than half of your screen)
- Use the knob above the Channel 1 button to move the signal to the upper-middle part of the screen
- Press the "Down" arrow to move to "channel 2" (turn on oscilloscope channel 2)
- Use Multipurpose b to scroll down to "CLK" (label channel 2 "Clock")
- Select "Insert Preset Label"
- Push the Menu Off button
- Press the Channel 2 button
- Use the knob below the Channel 2 button to set 2 volts per division (decrease the height of the signal so it fills less than half your screen)
- Use the knob above the Channel 2 button to move the signal into the lower middle part of the screen (this separates the trace for the clock signal from the trace for the data signal)
- Press the B1 button (the scope's bus functionality
allows you to interpret and display serial or parallel data; in this
case, we are dealing with I²C data)
- Press "Bus B1" and use Multipurpose a to select "I2C" (tell the oscilloscope which type of data to expect)
- Select "Define Inputs"
- Use Multipurpose a to select "SCL" on Channel 2 (assign CLK channel to be SCL)
- Use Multipurpose b to select "SDA" on Channel 1 (assign DATA channel to be SDA)
- Set "Thresholds" to "1 V" on both SDA and SCL using Multipurpose a and Multipurpose b
- Set "Include R/W In Address" to "yes"
- Set "B1 Label" to "I2C" (just to keep track of things)
- Set "Bus Display" to "Bus and Waveform"
- Set "Hex"
- Press the Trigger Menu button
- Select "Bus"
- Select "Source B1-I2C"
- Select "Trigger on Start"
- Press Menu Off
- Use the Scale rotary knob to change the time-scale to 1.00 ms
- Press Single to capture a single waveform
- Use the Wave Inspector rotary knobs to Zoom into any portion of the I²C transaction that you want to inspect more carefully. In my case, an ACK was received after address 0x5E, because that is the address of the magnetic sensor chip.
The following video walks you through the steps required to decode an I²C bus.
How to Save Data from the Oscilloscope to Your Computer
Decoded data is stored in an event table. You can save it to a USB drive or to your computer.Since plugging in a USB drive is a trivial example, we'll do it the hard way by remotely controlling the scope. The steps below are specific to Microsoft Windows and the Tektronix MDO3000 and MDO4000 series of scopes.
On a side note, what we are about to do is a potential data security risk. Talk to your IT department before doing this at work.
My computer is at 192.168.0.18, and the oscilloscope is at 192.168.0.40. Make appropriate adjustments to your commands.
- Run CMD.EXE as an administrator and type the following to create a share:
- mkdir C:\Oscilloscope
- NET SHARE Scope=C:\Oscilloscope /remark:"TEK3104 Data" /grant:domain\user,FULL // This creates a share named "Scope" on your main hard drive. You can change it to any location you like. Be certain to change domain\user to the name of the domain the computer is connected to, or the name of the PC followed by the username that you used to log on to Windows.
- ipconfig // Note the Local Area Connection IPv4 Address. In my example, it is 192.168.0.18.
- Next, while still in CMD.EXE, use PuTTY or telnet to connect to the scope:
- TELNET -O 192.168.0.40 4000 // Change 192.168.0.40 to the IP of your scope, displayed on the main screen at startup.
- You are now connected to the oscilloscope at its IP address on the default port 4000. Type the following:
- !d // This clears the device.
- files:mount:list? // This will show all mounted drives.
- files:mount:drive "H:;192.168.0.18;Scope;user;pass;" // This creates a persistent drive on the machine at 192.168.0.18.
- files:mount:list? // This should cause a new drive to appear.
- files:mkdir "H:/NewArticles" // This makes a directory called "New Articles" on the computer.
- files:cwd "H:/NewArticles" // This changes focus to that directory.
- save:eventtable:B1 "eventtable.csv" // This (finally) saves the data to the computer.
Conclusion
In under 15 minutes, we decoded an I²C bus and, from across the room, saved the data to a computer for analysis.And now that the shared folder is established, future work can be accomplished in just a few minutes. This automatic decoding process is much more effective than simply probing the signals and trying to manually interpret logic levels.
I used the scope and the procedures shown in this article to decode I²C bus data for several different modes of the 3D Magnetic Sensor 2 Go and determine which commands correspond to which power modes.
No comments:
Post a Comment