Bus Pirate: Binary I2C mode
See the latest version in the documentation wiki.
The Bus Pirate’s new binary modes provide a consistent, logical way to script actions from Python, Perl, etc. We already introduced the new binary bitbang and SPI modes, today we’ll document the binary I2C mode. Binary I2C will be in the v2.6 firmware release, for now you can grab the v2.6 nightly compile.
We want your scripts! If you script something for any of the new modes, in any language, we’d like to host it in the example scripts folder. We’ll send Bus Pirate probe cable kits to two authors of Bus Pirate binary mode scripts posted by the end of next week (October 24th, 2009).
Binary I2C mode specification follows after the break.
Binary I2C mode command table
- 00000000 – Exit to bitbang mode, responds “BBIOx”
- 00000001 – Mode version string (I2C1)
- 00000010 – Send I2C start bit
- 00000011 – Send I2C stop bit
- 00000100 – I2C read byte
- 00000110 – Send I2C ACK bit
- 00000111 – Send I2C NACK bit
- 00001111 – Start bus sniffer
- 0001xxxx – Bulk transfer, send 1-16 bytes (0=1byte!)
- 0100wxyz – Configure peripherals w=power, x=pullups, y=AUX, z=CS
- 011000xx – Set I2C speed, 3=~400kHz, 2=~100kHz, 1=~50kHz, 0=~5kHz
Enter binary I2C mode by first entering bitbang mode, then send 0x02 to enter I2C mode.
Most I2C mode commands are a single byte. Commands generally return 1 for success, 0 for failure.
00000000 – Exit to bitbang mode, responds “BBIOx”
This command resets the Bus Pirate into raw bitbang mode from the user terminal. It also resets to raw bitbang mode from raw I2C mode, or any other protocol mode. This command always returns a five byte bitbang version string “BBIOx”, where x is the current bitbang protocol version (currently 1).
00000001 – Display mode version string, responds “I2Cx”
Once in binary I2C mode, send 0×01 to get the current mode version string. The Bus Pirate responds ‘I2Cx’, where x is the raw I2C protocol version (currently 1). Get the version string at any time by sending 0×01 again. This command is the same in all binary modes, the current mode can always be determined by sending 0x01.
00000010 – I2C start bit
Send an I2C start bit. Responds 0x01.
00000011 – I2C stop bit
Send an I2C stop bit. Responds 0x01.
00000100 – I2C read byte
Reads a byte from the I2C bus, returns the byte. You must ACK or NACK each byte manually!
00000110 – ACK bit
Send an I2C ACK bit after reading a byte. Tells a slave device that you will read another byte. Responds 0x01.
00000111 – NACK bit
Send an I2C NACK bit after reading a byte. Tells a slave device that you will stop reading, next bit should be an I2C stop bit. Responds oxo1.
00001111 – Start bus sniffer
Sniff traffic on an I2C bus.
- [/] – Start/stop bit
- \ – escape character precedes a data byte value
- +/- – ACK/NACK
Sniffed traffic is encoded according to the table above. Data bytes are escaped with the ‘\’ character. Send a single byte to exit, Bus Pirate responds 0x01 on exit.
0001xxxx – Bulk I2C write, send 1-16 bytes (0=1byte!)
Bulk I2C allows multi-byte writes. The Bus Pirate expects xxxx+1 data bytes. Up to 16 data bytes can be sent at once. Note that 0000 indicates 1 byte because there’s no reason to send 0.
BP replies 0×01 to the bulk I2C command. After each data byte the Bus Pirate returns the ACK (0x00) or NACK (0x01) bit from the slave device.
0100wxyz – Configure peripherals w=power, x=pullups, y=AUX, z=CS
Enable (1) and disable (0) Bus Pirate peripherals and pins. Bit w enables the power supplies, bit x toggles the on-board pull-up resistors, y sets the state of the auxiliary pin, and z sets the chip select pin. Features not present in a specific hardware version are ignored. Bus Pirate responds 0×01 on success.
Note: CS pin always follows the current HiZ pin configuration. AUX is always a normal pin output (0=GND, 1=3.3volts).
NOTE: due to a typo this was previously command 0110.
0110000x – Set I2C speed, 1=high (50kHz) 0=low (5kHz)
011000xx – Set I2C speed, 3=~400kHz, 2=~100kHz, 1=~50kHz, 0=~5kHz (updated in v4.2 firmware)
The last bit of the speed command determines the I2C bus speed. Binary mode currently uses the software I2C library, though it may be configurable in a future update. Startup default is high-speed. Bus Pirate responds 0×01 on success.
NOTE: due to a typo this was previously command 0100.This entry was posted in binmode, Bus Pirate and tagged bitbang, I2C, raw io.