How-to: The Bus Pirate V2 With USB

buspiratev2goii450

Update, Saturday July 4th, 2009: All preorders are closed.

The Bus Pirate is a universal serial interface tool, we use it to test new chips without writing any code. It currently supports most serial protocols, including 1-Wire, I2C, SPI, JTAG, asynchronous serial, MIDI, and more. We added some other features we frequently need, like pulse-width modulation, frequency measurement, voltage measurement, bus sniffers, pull-up resistors, and switchable 3.3volt and 5volt power supplies.

The new v2 family adds USB power and connectivity to the best Bus Pirate design yet. We also reduced the part count and cost wherever possible. If you want to get your hands on some Bus Pirate USB goodness, Seeed Studio has assembled hardware for $30 (including worldwide shipping).

Read about the new design after the break.

Concept overview

overview450

The Bus Pirate connects to a PC USB port. The user send commands to the Bus Pirate from a serial terminal on the PC. Commands are translated to the bus protocols that control microchips. See our Bus Pirate page for full documentation.

The latest firmware supports 1-Wire, I2C, SPI, JTAG, asynchronous serial, MIDI, and PC keyboards. Bit-wise 2- and 3-wire libraries can interface most proprietary serial protocols.  More protocols are being added all the time, check out the source code on our Google Code SVN page.

Hardware

cct25450

Click for a large image of the schematic (PNG). The schematic and board layout were made with the freeware version of Cadsoft Eagle. Download the latest files from our Google Code page.

PIC24F

pic24f-highlight

A Microchip PIC24F series microcontroller generates the user interface and translates input into bus communications. V2 uses the same 24FJ64GA002 as the previous Bus Pirate versions. It’s cheap, has a ton of memory, a couple 5volt tolerant input pins, and the peripheral pin select feature lets us assign hardware modules anywhere we want.

The PIC (IC1) is powered by a 3.3volt regulator (VR2, C23). Each PIC power pin gets a 0.1uF bypass capacitor (C1,2). The internal 2.5volt regulator requires a 10uF tantalum capacitor (C20). The programming pins are brought to a five pin header (ICSP) on the edge of the PCB.

USB interface

ftdi-450ii1

The Bus Pirate is powered from the USB 5volt supply, which is first filtered with a ferrite bead (L1) and 10uF tantalum capacitor (C21). We used the small, still-not-quite-common, USB mini-b connector (J2).

Choosing a ferrite bead is a common hangup. Its purpose is to filter small power fluctuations, all the current for the circuit will go through it. We can guestimate that the Bus Pirate’s worst case current consumption is 525ma (3 power supplies @ 150ma, the FTDI chip @ 25ma, 2 LEDs @ 50ma max). Use a ferrite bead rated for at least 1000ma to be safe. We used this one, which is rated for 1500ma and costs 10 cents.

An FTDI FT232BL USB->serial chip (IC2) handles the USB connection. You might be familiar with this chip from various Arduino boards. FTDI has extensive driver support for most platforms, we used the virtual com port drivers.  This is the latest generation chip, and it’s only available in small SSOP and QFN packages. We had no problem hand-soldering it to a professional PCB, but it’s not for everyone.

The FT232BL is powered directly from the filtered, unregulated USB supply. C4 is a  decoupling capacitor for the FTDI232BL supply pin. A single LED (LED4/USB) indicates USB status and activity. The FT232BL RXLED pin sinks current, so we powered the LED from the 5volt USB supply through a 1.1K resistor (R3).

While the FT232BL runs at 5volts from the USB supply, its serial IO pins have an independent supply input – they can operate at another voltage. Since the microcontroller is 3.3volts, we just feed the FT232BL IO pins a 3.3volt supply and eliminate any funky translation circuitry. We used the chip’s internal 3.3volt regulator to supply the IO pins because it was the easiest trace to route. The IO pins get their own 0.1uF bypass capacitor (C5).

Switchable power supplies

vreg-450ii

The Bus Pirate has on-board 3.3volt and 5volt supplies (VR3, VR4) that can power a test circuit. The supplies are switchable, so we can reset the circuit from software when something goes wrong. To be extra safe, the supplies are held off until activated in the terminal.

[Nathan Seidle] at SparkFun recommended that we replace the  TPS796xx ($2.50) we used in The Bus Pirate v1a with a MIC5205-xxYM5 ($0.90). They supply just 150ma maximum current, compared to 800ma from the TPS796xx, but the cost savings and reduced part-count are worth it.

The regulators are fed from the 5volt USB supply. The 5volt regulator drops a few millivolts below optimal because there’s no headroom, but it’s within the minimum level specified by most 5volt parts.

The MIC5205 requires a large output filter capacitor (C22-24, 10uF), but no input capacitor. An optional small-value capacitor on the BP pin can decrease power supply noise, but we left this off because it didn’t make much difference in practice.

A small voltage on the EN pin enables the supply, we used a 10K pull-down resistor (R18, not shown) to ensure that the supplies stay off while the PIC initializes. LED3/VREG, with current limiting resistor R32, lights when the power supplies are active.

On-board pull-up resistors

resis

Bus Pirate V2 has multi-voltage, software controlled pull-up resistors via the 4066 (PDF) quad bilateral switch (IC3). When enabled, the 4066 connects the four on-board bus pull-up resistors (R20-23, 10K) to any external signal on the Vpullup pin (0 to 5volts). When disabled, the outputs are high-impedance and have no effect on the bus lines.

The 4066 can’t switch an input voltage greater than the supply voltage. To give it the widest possible range, we powered it from the USB supply (5volts).

When operated at 5volts, it takes 4volts+ to enable the 4066. The PIC pins have a maximum output of 3.3volts, so we have a problem. We solve it with a 5volt tolerant PIC pin and a pull-up resistor.  We turn on the 4066 with a pull-up resistor to 5volts (R19, 10K), and then disable it by switching the connected PIC pin to ground.

For a brief instant at power-on, the PIC pin is high-impedance and the 4066 outputs are active because the pull-up resistor holds the control pins at 5volts. This is a concern if the Vpullup input is connected to an external 5volt supply while the bus is connected to a 3.3volt device – the brief exposure to 5volts might harm the device. If you’re worried about this, make sure there’s no active power supply connected to the Vpullup input before powering the Bus Pirate. This isn’t a concern if you use one of the on-board power supplies for the pull-up voltage because they’re disabled at startup.

Voltage monitoring

cct-adcin

Four voltage dividers (R10-17, 10K), attached to analog to digital converters, allow the 3.3volt PIC to safely measure up to 6volts DC.

Two voltage monitors measure the switchable power supply output. One measures the Vpullup input voltage, and another connects to the external voltage measurement probe.

Indicator LEDs

front-back2450

Three LEDs indicate power, mode, and voltage regulator status (LED1-3). LED4/USB displays USB activity.

There are pads for resistors R30-32 and LEDs 1-3 on the front and back of the PCB. Only one set should be populated. We put pads on both sides so the board could be mounted with the indicator LEDs abutting the top of an enclosure.

V2a vs V2go

bpv2450

Click for large schematic (PNG) and layout (PNG) images of the version 2a hardware. The Eagle layout files are available in our Google Code SVN.

Bus Pirate V2a is a developer’s board. In addition to all the features of V2go, it includes a jack (J1) for an external power supply and an additional 5volt regulator (VR1).  A switch (S1) selects between USB power and the external supply.

The FT232BL chip on V2a is powered directly from the USB supply, and is not connected to the external supply. This is useful if you want to disable USB and use the Bus Pirate with a serial port on a PC or PDA.

The V2a 4066 enable pull-up resistor is powered by the switchable 5volt regulator. The 5volt regulator must be enabled for the 4066 to be active. Don’t forget to install the 4066 pull-up resistor (R19), located on the back of the v2a PCB.

PCB

brd25450

The PCB is a compact, 2-layer design. We prepared gerbers and had PCBs made by our usual service, BatchPCB ($21, shipped to EU), and tried a new service offered by Seeed Studio ($32, shipped worldwide).

Seeed has a PCB service specifically for open source hardware projects. For $32 (including worldwide shipping) we got 5 small PCBs, and Seeed made a few extra to sell in their shop. We liked the idea that there would be extra PCBs available.

You might know Seeed Studio from their cheap, improved Seeeduino Arduino clone. They’re located in Shenzhen, a Chinese electronics manufacturing hot-spot. A bunch of notable bloggers recently visited the region and wrote about the huge electronic component markets.

seeed-batchpcb4501

The Seed order arrived in 14 days (left), the BatchPCB order arrived in 30 days (right).  Seeed and BatchPCB both make beautiful PCBs. Seeed has a much faster turn-around, and has better minimum trace widths and separation (8mil vs 6mil). BatchPCB has standard green PCBs, Seeed gives you the choice of green, black, or white; red, blue and yellow are $7.50 extra.

We really like the Seeed PCB service, extra Bus Pirate v2go and v2a PCBs from our order are available in the Seeed shop. BatchPCB remains the cheapest prototyping option if you want a single board, closed source work, or don’t mind the extra wait.

Parts list

Part Value (package)
IC1 PIC24J64GA002 (SOIC)
IC2 FT232RL (SSOP)
IC3 CD4066D (SOIC-N)
VR2,3 MIC5205-3.3YM5 3.3volt regulator (SOT23-5)
VR4 MIC5205-5.0YM5 5volt regulator (SOT23-5)
C1-5 0.1uF capacitor (0805)
C20-24 10uF tantalum capacitor (SMC-A)
L1 1000ma+ Ferrite bead (0805)
R1 2000 ohm resistor (0805)
R3,30 1100 ohm resistor (0805)
R10-23 10,000 ohm resistor (0805)
R31,32 390 ohm resistor (0805)
LED1-4 LED (0805)
J2 USB MINI-B (SMD)
I/O 0.1″ pin header (2×05)
ICSP 0.1″ pin header (1×05)
ST 0.1″ pin header (1×03) *unpopulated, optional*

Optional Parts for V2a
C6-10 0.1uF capacitor (0805)
J1 2.1mm power jack (SMD)
LED5,6 LED (0805)
R33,34,40 1100 ohm resistor (0805)
S1 Slide switch, SPDT, rt angle
VR1 LD1117s50 5volt regulator (SOT223)

Firmware

The latest Bus Pirate firmware for all hardware version is always available on our Google Code page. The code is written in C, and is compiled with the Microchip C30 demonstration compiler.

Bootloader

The biggest change in the latest firmware is the addition of a bootloader. Now the firmware can be updated through the USB or serial connection.

A bootloader is small program that sits at the beginning of the PIC program memory. It accepts updated firmware through the USB or serial port and saves it to the chip.

bootload-jumper4501

The bootloader comes from Microchip application note AN1157. We modified the bootloader to check for a jumper between the programming clock (PGC) and data (PGD) pins at power-up (update, above left). If there’s a connection, the bootloader takes over and waits for new code. Without a connection, the bootloader exits and runs the main program.

There’s a very minor chance of accidentally entering the bootloader with no jumper installed. This won’t damage the Bus Pirate, but you will need to connect it again.  You can prevent it by moving the jumper over one position,  between the ground pin and the inner programming pin (normal, above right).

Upgrading the firmware with the bootloader

pic24fqp

If you’re using a fresh chip, first program it with the bootloader firmware (vxx-PIC Bootloader.hex) through the ICSP header using a ‘real’ programmer like an ICD2 or PicKit.

If you’re upgrading, follow this procedure or refer to the instructions in the firmware download.

  • Disconnect the Bus Pirate from any power supply such as the USB cable.
  • Place a jumper between the programming data and clock pins of the ICSP header. This will trigger the bootloader mode.
  • Connect the Bus Pirate to a USB port (or, if applicable, power and serial cable).
  • Start the MS Windows P24QP.exe programmer utility. You may need to modify the COM port (portindex=) in P24qp.ini to match your system.  Programmer source is available, and the simple bootloader protocol is documented in AN1157 if you want to write an app for a non-Windows system.
  • Click the connect to device icon (#1). The program will connect to the PIC.
  • Click the folder icon (#2) and open the firmware update file (vxx-Firmware for BL.hex).
  • Click the erase device icon (#3) to erase the chip. DO NOT SKIP THIS STEP. Programming may not be successful if you forget to erase the chip.
  • Click the write device icon (#4) to program the new firmware. Ignore any verify errors between 0x400 and 0xBFF, the bootloader lives in this region and doesn’t get updated.
  • Click the green arrow icon (#5) to exit the bootloader and start the program. Click OK at the warning, we use the jumper to re-enter the bootloader.
  • Remove the jumper from the programming pins, or move it over one position to connect the inner PGx pin to ground (GND).
  • ***IMPORTANT*** Now restart the Bus Pirate by disconnecting and reconnecting the USB cable (or power cable). Some features won’t work until after a complete hardware reset.

Using it

USB device driver

You may need to install an FTDI virtual serial port driver for your platform.

On Windows, go to the Device Manager to configure the FTDI driver or check the COM port number.

Menus and Syntax

term450

Use a serial terminal to communicate with the Bus Pirate. We like Tera Term.

The Bus Pirate works best with the terminal set to 115200bps, 8 databits, no parity, 1stopbit. Disable local echo in the terminal, and use CR for line breaks. Some modes also require Xon/Xoff software flow control.

In the serial terminal, press ? for the help menu. Read more about the Bus Pirate’s menu and syntax on the Bus Pirate page. There’s lots of demonstrations in our recent parts posts.

LED indicators

leds-450

  • PWR indicates power to the Bus Pirate.
  • MODE is off when the I/O pins are in a safe, high-impedance state. MODE is lit when a bus mode is engaged, the pins may be active.
  • VREG indicates that the on-board switchable power supplies are active.
  • UR is a single USB activity indicator LED. It displays data coming from the PC to the Bus Pirate. You can probably change what this LED displays with the FTDI configuration utility.

Connections

Pin location diagrams: v2a, v2g0.

Pin name |
Description (Bus Pirate is the master)
MOSI Master data out, slave in (SPI, JTAG), Serial data (1-Wire, I2C, KB), TX* (UART)
CLK Clock signal (I2C, SPI, JTAG, KB)
MISO Master data in, slave out (SPI, JTAG) RX (UART)
CS* Chip select (SPI), TMS (JTAG)
AUX Auxiliary IO, frequency probe
ADC Voltage measurement probe (max 6volts)
Vpu Voltage input for on-board pull-up resistors (0-5volts).
+3.3v +3.3volt switchable power supply, max 150ma
+5.0v +5volt switchable power supply, max 150ma
GND Ground, connect to ground of test circuit

Notes: * TX moved from CS to MOSI in firmware v0g.

The 10 pin I/O block contains the data signals and power supplies that connect to a test circuit. Each pin is labeled on the back of the PCB, refer to the table above for a detailed description.

The pinout on V2 is similar to V1, but we moved the power supply output and Vpullup input to the cable bundle. We also eliminated the second, unused auxiliary pin.

Conclusion

If you want a complete Bus Pirate or a kit, here’s a couple options:

  • Seeed Studio is accepting pre-orders for assembled Bus Pirate v2go hardware until the end of Friday, July 3.  An assembled Bus Pirate v2go is $30, including worldwide shipping.
  • Seeed Studio also has the extra v2g0 ($5.90) and v2a ($6.50) PCBs from our order.
  • Fundamental Logic sells a through-hole kit version of the Bus Pirate V1a ($29.50). ***v1a is serial port only***

Thanks to everyone who contributed to this project. The Bus Pirate wouldn’t be possible without a ton of great feedback from the comments. If you’d like to get involved, join the Bus Pirate project at Google Code.

Hack a Day review disclosure: We asked Seeed Studio to make our first order of PCBs for free. Since then, we’ve made several paid orders.

bpv2goiii

32 thoughts on “How-to: The Bus Pirate V2 With USB

  1. So, does that mean that, even though it’s USB, it’s limited to 115200bps?

    I mean, I know Logic Analyzer 2.0 (the other ad) costs five times more, but being limited to UART speeds is too serious an impairment (for an otherwise great device).

  2. So, what exactly could I do with this thing? I read the stuff on here all the time, and whenever they post stuff like this, I know it can be used for something that has to do with the DIY projects, but I don’t know how. Someone please explain.

  3. That cable almost looks custom made as it has a mix of two different probe types.

    The 10-pin IDC connector, and multicolor ribbon cable can be had for 75c at futurlec.

    As for the grabbers, the thin flat style with two hooks are by far the best for SMD and most through hole. You can usually buy gray ones for ~$1.50 each, or NKC electronics has a multicolored set for $22.

  4. @alexwhittemore, Nick, jproach

    We’ll have a cable How-to next week.

    @busp
    The 232BL and PIC UARTs can go up to 3MBPS, but we used 115200. Only the the bus sniffer functions would benefit from more speed, but they’d benefit most from proper FIFO buffering.

  5. Awesome product, but one quick note…

    Going from ~5V USB to a 5 V “regulated” supply with the MIC5205 is a little misleading. It’s very likely that this LDO has a P-type pass element, meaning, that when operating in dropout, the transconductance is very small, greatly reducing the PSRR from the 75 dB mentioned in the datasheet (with 1 V differential).

    In short: noise on the USB line will be largely coupled through to the 5 V “regulated” supply from the MIC5205’s output, when the USB line is nominal (or lower). This can be diminished by greatly increasing the output capacitance of the MIC5205.

  6. @carltonstedman

    Thanks for your notes. We considered a few other ways to switch the 5volt supply, like the P-FET switch recommended in the FTDI 232BL datasheet. We ultimately felt like short circuit protection and voltage & current regulation probably justified the use of a regulator, instead of a relay or FET. This part of the design could definitely be improved further.

  7. @ian lesnet

    Actually, I was suggesting using some other regulation scheme; I definitely agree, that current limiting / short circuit protection are a *must*.

    For this design, I’d think of using a charge pump + regulator, to get a clean 5 V, no matter the voltage on the USB line. A voltage-doubler charge pump running off, for example, the regulated 3.3 V line, with a 5 V ldo on it’s output (stepping from 6.6 V down to 5 v) would be one thing to consider, requiring a charge pump IC and a couple of caps and potentially a more current-capable 3.3 V regulator.

    At these current levels, going with a switcher is probably not economical, but a charge pump + regulator combo probably is.

    Certainly, if any analog circuitry / references (which seems to be the case) runs off the 5 v line, than the improved psrr with the above outlined method could be justified.

  8. On the ICSP header PGC(clock) and PGD(data)have changed their places in reference to microchip’s pickit programmer header. Anyway since the addition of a bootloader it’s not a big deal. Just have to remember not plugging my pickit directly to Bus Pirate.
    Btw, great job.

  9. for the seeed studio link, I can find no reference to V2 or V2go or Bus Pirate materials. How do we go about ordering a board (and prefereably an assembled system)? I am very interested in using the sniffer for I2C. Much thanks for your good work.
    Ted

  10. Good job – at first look!

    What about considering to use PIC24FJ64GB002 ?!
    It has USB capability so you/we can save the FT232RL …

    Almost forget… it is a future product of Microchip.

Leave a Reply to FoxyCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.