Sniffer Device With Custom I2C Implementation

This document describes the project of a software I2C implementation and will link you to the materials needed to reproduce the device.

Preface - Why Software I2C

I2C Bus is a two-wire master/slave oriented bus intended for simple and inexpensive (in means of PCB design) interconnection of individual integrated circuits (see specification).

Each I2C device is assigned a 7-bit or 10-bit address (which must be unique within the given circuit), part of which is predefined by the manufacturer and part may be programmable.

There are two types of I2C devices:

  • master - can query other devices, controls the bus clock wire; the specification enables multi-master environments with arbitration (lower address has higher priority), and
  • slave - can only respond on a master’s request using the data wire.

It is important to realize that every device (even the master ones) only respond to a request identified by its unique address. If we want to detect and control all the I2C traffic, the I2C protocol has to be implemented in software. We created a device with these 3 modes:

  • master and slave compatible with the I2C specification, and
  • sniffer mode allowing to observe all the bus traffic.

The device is controlled from a PC using the RS232 serial line. We provide a Windows driver defining an abstraction of the device’s functionality.

The Device

The device itself is a very simple I2C-to-UART interconnection using a tiny PIC microcontroller. The major functionality is in the PIC’s software.

The schematics and PCB layout are designed in Formica. You can download a free evaluation version if you want to play with it.

The device is designed for 5V power supply (the ‘power’ connector and the +/- pins of the ‘i2c’ connector are interconnected). The ‘serial’ part of the device supports both 12V logic (such as desktop RS232 ports) and 5V logic (used in notebooks).

Note that the circuit already contains a low-voltage ICSP programmer (LVP). The PIC may be easily re-programmed using the same serial cable which is used for communication. The only problem is that you must already have your PIC set-up for LVP (which is not factory default) to be able to program it on this device. The reason is that this device was optimised for use with notebooks, which do not have high-voltage (12V) serial ports anyway, so the LVP was an obvious choice.

If you already have another PIC programmer, you may omit some parts, otherwise you will need to modify the device for high-voltage programming.


Board Schematics PCB Bottom PCB Top Assembled Device
Schematics (PS, Formica) PCB - mirrored (PS, Formica) Parts layout Finished device

Part list

  • PIC16F628
    the main microcontroller; capable of up to 20MHz, flash-programmable,
  • XTAL20M
    20.000 MHz crystal to get full processor speed (internal oscillator reaches 4MHz max),
  • 7404
    (actually SN74HC04N on my device) inverter for connecting the PIC to a notebook; note: if you are connecting the device to a 12V serial port (such as on a desktop), you may want to use a level invertor (ex. MAX232), but I find it unnecessary,
  • LED (5x, all optional)
    power indicator (red), rx/tx (yellow/green), debugging LEDs (yellow/red),
  • 330 ohm resistors (5x)
    for regulating the current through the 5 LEDs,
  • 1k6 resistors (2x, optional)
    pull-up resistors for the I2C bus; if you already have these pullups elsewhere on your bus (which is most likely), you may omit them,
  • BAT42 (7x)
    schottky diodes used to clamp the programming voltages in case of a 12V serial port connection,
  • 2k2 resistor
    to reduce possible 12V TXD voltage from PC,
  • 22K resistor (2x)
  • 15pF capacitor (2x)
  • 1uF capacitor
  • 5.1V Zener diode


Once the device is assembled, it has to be programmed with the PIC firmware. Then it can be used in the following levels of abstraction:

  • Using a simple Windows console application that allows you to observe and control the I2C bus using several textual commands,
  • creating your own I2C control application using the services provided by an encapsulating Windows driver, and finally
  • creating your own application controlling the device over the serial line, using the device’s native Communication protocol

Setting up the Device

First of all you need a proper serial cable. Note that the device uses a generic 7-pin connector (with 2.54mm span) thus omiting the first and last wire of the 9-wire serial cable. Pin 2 of RS232 is connected to the topmost pin, pin 8 of RS232 to the opposite (see Finished device).

Uploading the firmware
  • install and run the WinPIC programmer,
  • switch to the Interface panel and select Custom, on COM port, defined by FILE in Interface Type,
  • select the COM port your cable is attached to,
  • select the COM84_LVP_B3.INI in the Custom interface definition file field,
  • choose File | Load & Program Device (all) and select the i2c_sniffer.hex file.

If you want to have a look into the PIC source files (while the documentation is being written :-) ), you may download the PIC source files archive. It is written in CCS PIC-C, which unfortunately is not freely available.

Windows console application

Download the source file here.

Yet to be documented. If you’re interested, contact me and I will publish this information.

Windows driver

You may download the whole solution (including Visual Studio 2003 project files). See the pages of Tomas Matousek for documentation.

Communication protocol

Yet to be documented. If you’re interested, contact me and I will publish this information.


The device may be simply modified (preserving the PCB) to better suit your needs. The two following modifications address the programmer part.

High-voltage programming

You may omit all the D_PGD_LO, D_PGC_LO, 22k_LVP, ZD_LVP, and 1uF_LVP from the schematics. Replace the 200R with a 2k2 resistor and wire it with pin 4 of the PIC (the MCLR pin). Cut the path connecting the +5V with the pin 4 (either from the ‘i2c’ the the ‘power’ connector, whichever you’re using) and replace it with a diode (to prevent high programming voltage from penetrating into the 5V VCC). And that’s it!

Omitting the programmer

You may simply omit all the D_PGD_LO, D_PGC_LO, 22k_LVP, ZD_LVP, 1uF_LVP, and 200R from the schematics.

  i2c/start.txt · Last modified: 2005/12/02 23:50
Recent changes RSS feed Driven by DokuWiki