Bus Pirate v3.6a Hookup Guide

Introduction

The Bus Pirate is an electronics prototyping dream. It’s packed with many of the tools needed when getting a project up and running. The Bus Pirate can perform a variety of test equipment functions such as measuring voltage and frequency as well as generating PWM signals.

Most of the functionality of the Bus Pirate revolves around serial protocols. The Bus Pirate can communicate on 1-wire, 2-wire, 3-wire, UART, I2C, SPI, and HD44780 LCD protocols. It also has a bitbang mode for other or custom options.

This guide is intended to be a quick overview and cover a few things not explicitly covered in the Bus Pirate documentation provided by Dangerous Prototypes.

Suggested Reading

The following concepts will be mentioned in this guide. If you are unfamiliar with any of them, check out the corresponding tutorial.

Board Overview

Bus Pirate Ports

The Bus Pirate has 3 ports. This first is the ICSP port for directly programming the PIC microcontroller at the heart of this product. Since there is a bootloader and a reflashing utility, you shouldn’t ever have to use this port.

The second port is a mini-B USB jack. Connect this to a computer with a standard A to mini-B cable. This provides the power to the board and allows you to communicate with Bus Pirate.

The third port is the most interesting. It’s a shrouded 0.1" pitch 2x5 pin header. We sell a handy cable to connect the Bus Pirate to the system you are developing, debugging, or reverse engineering. Here is a graphic that shows maps the IO functions to the colors of the cable.

The following table describes in a little more detail the purpose of each pin. It’s sorted in the same order as the conductors on the cable. The power supplies can be switched on or off in software, and each can supply up to 150mA to power your project.

Binary Scripting Mode

Binary scripting mode allows applications and/or scripts to control the Bus Pirate. This interface could be used to write a GUI, automated testing, etc. It’s more work to get up and running, but it is more powerful. The following code block is a minimal Python script that can serve as a starting place to use the binary access mode on most platforms. It puts the Bus Pirate into binary mode, sends a command, and then prints out a response. It doesn’t actually ‘do anything’ beyond that though; it’s only a framework.

On my Mac I run a command like: ./binaryModeDemo.py -p /dev/tty.usbserial-AL00ESEJ. The default baud rate for the Bus Pirate is 115200. For help, run python binaryModeDemo.py --help. It should run on any platform running a Python interpreter. Some tweaks might be necessary if running a non-2.7 version of Python.

User Terminal Mode

Terminal mode is likely the interface of choice for most users, at least to start. It provides an interactive menu system for configuring the Bus Pirate. All one needs to use it is a terminal emulator.

The first thing to note is how to get help or list all of the commands. At the prompt enter ?.

Example

Here is a quick example of reading a register from a device on the I2C bus. I had an LSM303C Breakout laying on my desk, so I’ll use it. Any I2C device will work a similar way. Here is a picture of all of the connections required to get the breakout board powered an communicating. This board runs on 3.3V, so we will power it with the red wire.

Note: By default VDD & VDD_IO on the LSM303C breakout are connected and either could have been used to power the board.

Fritzing diagram of Bus Pirate connected to LSM303C

Bus Pirate cable attached to the LSM303C Breakout

On Mac or Linux, I typically run picocom. You can use about any terminal emulator you like. I connect with a command such as picocom -b115200 /dev/tty.usbserial-AL00ESEO. The default baudrate of the Bus Pirate is 115200 baud, and the hardware I have in hand shows up at /dev/tty.usbserial-AL00ESEO. The first step is to select the correct mode. We say above from the help that m is the ‘Change mode’ command. This will show the 9 mode options.

To power the board we need to enable the power regulators with ‘W’ (‘w’ will disable):

I2C>W
Power supplies ON

At this point you might also want to enable pull-up resistors. To do so you need to connect the VPU pin to the correct voltage supply. Then ‘P’ will connect the resistors. The LSM303C Breakout already has pull-up resistors, so we can skip this step. We are ready to start communicating with the IC.

Let’s take a look at the LSM303C datasheet to see what it expects to see on the I2C bus:

It looks like as the master we need to send a start condition then a slave address with the read/write bit clear for a write. The LSM303C should then acknowledge receipt (ACK). Next we need to send the address of the register or interest. The slave/LSM303C should ACK. Next we need to send a repeated start condition (same thing as a normal start condition), followed by the slave address with the r/w bit set to do a read. The LSM303C should respond, and we as the master don’t acknowledge. The sequence ends with a stop condition.

Looks like we need more details such as the addresses. The LSM303C datasheet gives the 7-bit slave address to be 0011101b (0x1D) for the accelerometer and 0011110b (0x1E) for the magnetometer.

I2C Slave Addresses

To use these addresses we need to append the read/write bit to the end. In our case if we want to read from the accelerometer we need to shift 0b0011101 left once and or that with 0x01 to indicate a read. The shift yields 0b0111010 and OR-ing that result with 1 results in 0b0111011 (0x3B). If we had OR-ed with 0x00 for a write we would have got 0b0111010 (0x3A) for the write address. Let’s use a Bus Pirate macro to see if those addresses exist on the bus:

Sure enough, we can see a write address at 0x3A, and a read address at 0x3B! Now we need to know the address of a register to read from. The WHO_AM_I_A (0x0F) register always contains 0x41, so that makes an easy read to verify.

Who Am I Register Details

Let’s put all of those addresses into Bus Pirate syntax and in the format that the LSM303C will respond to. Start condition [, write address 0x3A, register address 0x0F, repeated start condition [, read address with read command 0x3B r, and end it all with a stop condition ]. Here is how the Bus Pirate responds to that input:

In 2003, CU student Nate Seidle fried a power supply in his dorm room and, in lieu of a way to order easy replacements, decided to start his own company. Since then, SparkFun has been committed to sustainably helping our world achieve electronics literacy from our headquarters in Boulder, Colorado.

No matter your vision, SparkFun's products and resources are designed to make the world of electronics more accessible. In addition to over 2,000 open source components and widgets, SparkFun offers curriculum, training and online tutorials designed to help demystify the wonderful world of embedded electronics. We're here to help you start something.