rawspi

There’s two new binary I/O libraries in the v2.3 Bus Pirate firmware. Raw bitbang mode provides direct control over the Bus Pirate pins and hardware using a simple single-byte protocol. We discussed the new raw SPI mode yesterday.

Hopefully the raw access modes inspire some interesting new Bus Pirate tools using PC software. There’s already a patch for AVRDude AVR programmer in the works.

Full documentation of the raw bitbang binary I/O mode after the break.

Commands

  • 00000000 – Reset, responds “BBIO1”
  • 00000001  – Enter binary SPI mode, responds “SPI1”
  • 00000010 – Enter binary I2C mode, responds “I2C1”
  • 00000011 – Enter binary UART mode, responds “ART1”
  • 00000100 – Enter binary 1-Wire mode, responds “1W01”
  • 00000101 – Enter binary raw-wire mode, responds “RAW1”
  • 0000xxxx – Reserved for future raw protocol modes
  • 00001111 – Reset Bus Pirate (returns to user terminal)
  • 00010000 – Short binary mode self-test
  • 00010001 – Long test (requires jumpers between +5 and Vpu, +3.3 and ADC)
  • 00010010 – Setup pulse-width modulation (requires 5 byte setup)
  • 00010011 – Clear/disable PWM
  • 00010100 – Take voltage probe measurement (returns 2 bytes)
  • 010xxxxx  – Set pins as input(1) or output(0), responds with read
  • 1xxxxxxx  – Set pins high (1) or low (0), responds with read

The bitbang protocol uses a single byte for all commands. The default start-up state is pin input (HiZ).

00000000 – Reset, responds “BBIO1”

This command resets the Bus Pirate into raw bitbang mode from the user terminal. It also resets to raw bitbang mode from raw SPI mode, or any other protocol mode. This command always returns a five byte bitbang version string “BBIOx”, where x is the current protocol version (currently 1).

Some terminals send a NULL character (0x00) on start-up, causing the Bus Pirate to enter binary mode when it wasn’t wanted. To get around this, you must now enter 0x00 at least 20 times to enter raw bitbang mode.

Note: The Bus Pirate user terminal could be stuck in a configuration menu when your program attempts to enter binary mode. One way to ensure that you’re at the command line is to send <enter> at least 10 times, and then send ‘#’ to reset. Next, send 0x00 to the command line 20+ times until you get the BBIOx version string.

00000001  – Enter binary SPI mode, responds “SPI1”

After entering bitbang mode, you can enter other binary protocol modes. Binary SPI mode is documented here.

00000010 – Enter binary I2C mode, responds “I2C1”

Binary I2C mode is documented here.

00000011 – Enter binary UART mode, responds “ART1”

Binary UART mode is documented here.

00000100 – Enter binary 1-Wire mode, responds “1W01”

Binary 1-Wire mode is documented here.

00000101 – Enter binary raw-wire mode, responds “RAW1”

Binary raw-wire mode is documented here.

00001111 – Reset Bus Pirate

The Bus Pirate responds 0x01 and then performs a complete hardware reset. The hardware and firmware version is printed (same as the ‘i’ command in the terminal), and the Bus Pirate returns to the user terminal interface. Send 0x00 20 times to enter binary mode again.

Note: there may be garbage data between the 0x01 reply and the version information as the PIC UART initializes.

0001000x – Bus Pirate self-tests

Binary self tests are documented here. Available only in v2go and v3 hardware.

00010010 – Setup pulse-width modulation (requires 5 byte setup)

Configure and enable pulse-width modulation output in the AUX pin. Requires a 5 byte configuration sequence. Responds 0x01 after a complete sequence is received. The PWM remains active after leaving binary bitbang mode!

Equations to calculate the PWM frequency and period are in the PIC24F output compare manual. Bit 0 and 1 of the first configuration byte set the prescaler value. The Next two bytes set the duty cycle register, high 8bits first. The final two bytes set the period register, high 8bits first.

00010011 – Clear/disable PWM

Clears the PWM, disables PWM output. Responds 0x01.

00010100 – Take voltage probe measurement (returns 2 bytes)

Take a measurement from the Bus Pirate voltage probe. Returns a 2 byte ADC reading, high 8bits come first. To determine the actual voltage measurement: (ADC/1024)*3.3volts*2; or simply (ADC/1024)*6.6.

010xxxxx  – Configure pins as input(1) or output(0): AUX|MOSI|CLK|MISO|CS

Configure pins as an input (1) or output(0). The pins are mapped to the lower five bits in this order:

AUX|MOSI|CLK|MISO|CS.

The Bus pirate responds to each direction update with a byte showing the current state of the pins, regardless of direction. This is useful for open collector I/O modes.

Note: updated to correct order on 16/JAN/10

1xxxxxxx   – Set on (1) or off (0): POWER|PULLUP|AUX|MOSI|CLK|MISO|CS

The lower 7bits of the command byte control the Bus Pirate pins and peripherals. Bitbang works like a player piano or bitmap. The Bus Pirate pins map to the bits in the command byte as follows:

1|POWER|PULLUP|AUX|MOSI|CLK|MISO|CS

The Bus pirate responds to each update with a byte in the same format that shows the current state of the pins.

Note: updated to correct order on 16/JAN/10

Key Points

  • Send 0x00 to the user terminal 20 times to enter the raw binary bitbang mode.
  • Send 0x0F to exit raw bitbang mode and reset the Bus Pirate.
  • Other raw protocol modes are accessible from within bitbang mode, 0x00 always returns to raw bitbang mode and prints the version string.
  • There is a slight settling delay between pin updates, currently about 5us.

Updates

Advertisements