Skip to main content

I2C Protocol Commands

Overview

  • Bus: I2C (eye-squared-see or eye-two-see)
  • Connections: two pins (SDA/SCL) and ground
  • Output type: open drain/open collector
  • Pull-up resistors: always required (2K - 10K ohms)
  • Maximum voltage: 5volts

I2C is a common 2-wire bus for low speed interfaces, generally 100KHz, 400KHz and sometimes 1MHz.

Configuration options

Bus Pirate [/dev/ttyS0]
I2C speed
1KHz to 1000KHz
x. Exit
KHz (400KHz*) >
Data bits
1. 8*
2. 10
x. Exit
Bits (1) >
Mode: I2C
I2C>

Pull-up resistors

I2C is an open-collector bus, it requires pull-up resistors to hold the clock and data lines high and create the data '1'. I2C parts don't output high, they only pull low, without pull-up resistors there can never be a '1'. This will cause common errors such as the I2C address scanner reporting a response at every address.

Enable the Bus Pirate onboard pull-up resistors with the P command.

tip
  • I2C requires pull-up resistors to hold the clock and data lines high.
  • I2C parts don't output high, they only pull low.
  • Without pull-up resistors there can never be a '1'.
  • Enable the Bus Pirate onboard pull-up resistors with the P command.

Connections

Bus PirateDirectionCircuitDescription
SDASDASerial Data
SCLSCLSerial Clock
GNDGNDSignal Ground

Syntax

CommandDescription
{ or [Issue I2C start condition.
] or }Issue I2C stop condition.
rRead one byte, send ACK. (r:1…255 for bulk reads)
0bWrite this binary value, check ACK. Format is 0b00000000 for a byte, but partial bytes are also fine: 0b1001.
0xWrite this HEX value, check ACK. Format is 0x01. Partial bytes are fine: 0xA. A-F can be lower-case or capital letters.
0-255Write this decimal value, check ACK. Any number not preceded by 0x or 0b is interpreted as a decimal value.
spaceValue delimiter. Use a space to separate numbers. No delimiter is required between non-number values: {0xa6 0 0 16 5 0b111 0xaF rrrr}.
(#)Run macro, (0) for macro list.

Commands

Bus Pirate 5 has global commands available everywhere, and mode commands specific to the currently selected mode. Type help to see all commands in every mode, or help mode for the currently available mode commands.

I2C address search scan

The scan command in the Bus Pirate I2C mode scans the for device addresses.

Help

Bus Pirate [/dev/ttyS0]
I2C> scan -h
usage:
scan [-v(erbose)] [-h(elp)]
Scan I2C address space: scan
Scan, list possible part numbers: scan -v

scan I2C addresses, with optional part number
-v Verbose mode, print potential part numbers
-h Get additional help

tip

Use scan -h to see the latest options and features.

Options and Flags

FlagDescription
-vVerbose mode, print potential part numbers.
-hGet additional help.

Scans for I2C Devices

Bus Pirate [/dev/ttyS0]
I2C> scan
I2C address search:
0x50 (0xA0 W) (0xA1 R)
0x51 (0xA2 W) (0xA3 R)
0x52 (0xA4 W) (0xA5 R)
0x53 (0xA6 W) (0xA7 R)
0x54 (0xA8 W) (0xA9 R)
0x55 (0xAA W) (0xAB R)
0x56 (0xAC W) (0xAD R)
0x57 (0xAE W) (0xAF R)

Found 16 addresses, 8 W/R pairs.

I2C>

You can find the I2C address for most I2C-compatible chips in the datasheet. But what if you're working with an unknown chip, a dated chip with no datasheet or you're just too lazy to look it up?

The Bus Pirate has a built-in address scanner that checks every possible I2C address for a response. This brute force method is a fast and easy way to see if any chips are responding, and to uncover undocumented access addresses.

I2C chips respond to a 7bit address, so up to 128 devices can share the same two communication wires. An additional bit of the address determines if the operation is a write to the chip (0), or a read from the chip (1).

Scanner details

The scan command in I2C mode runs the address scanner.

  • For I2C write addresses: the BP sends a start, the write address, looks for an ACK, then sends a stop.
  • For I2C read addresses: the BP sends a start, the read address, looks for an ACK. If there is an ACK, it reads a byte and NACKs it. Finally it sends a stop.

When the I2C chip responds to the read address, it outputs data and will miss a stop condition sent immediately after the read address (bus contention). If the I2C chip misses the stop condition, the address scanner will see ghost addresses until the read ends randomly. By reading a byte after any read address that ACKs, we have a chance to NACK the read and properly end the I2C transaction.