
See the latest version in the documentation wiki.
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 (0×00) on start-up, causing the Bus Pirate to enter binary mode when it wasn’t wanted. To get around this, you must now enter 0×00 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 0×00 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 0×01 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 0×00 20 times to enter binary mode again.
Note: there may be garbage data between the 0×01 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 0×01 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 0×01.
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 0×00 to the user terminal 20 times to enter the raw binary bitbang mode.
- Send 0×0F to exit raw bitbang mode and reset the Bus Pirate.
- Other raw protocol modes are accessible from within bitbang mode, 0×00 always returns to raw bitbang mode and prints the version string.
- There is a slight settling delay between pin updates, currently about 5us.
Updates
-
When I get mine the first thing I’m going to do is implement a simple SWD script for uploading to Arm Cortex-M3’s.
It took me ages to cobble together all the documentation needed to use that protocol ;)
-
Tip to anyone using bin mode, when sending command strings read single replies before sending more commands, sending long commands and attempting to read long replies causes the bus pirate to miss part of the command when performing the first part. This is caused by the bus pirate polling the serial line, since it might be busy when the next byte comes in the pic’s buffer can overflow and the command is lost.
-
…and give your circuit some time to stabilize after switching pull ups or power supplies.
-
My v2go running 3.6 has a different order of the input/direction bits:
1|POWER|PULLUP|AUX|MOSI|CLK|MISO|CS
Is the order in the post wrong?-
@W1N9Zr0 – Thank you, you are absolutely correct. I updated the post. The relevant code is located here:
http://code.google.com/p/the-bus-pirate/source/browse/trunk/source/binIO.c#227
-
-
I would like driving BP3 through a LibertyBasic simple basic program … sending simple characters command to the card (through COMp port) as done with a terminal program like Hyperterminal … How do I do that ?
I can send the commands but no response is readed ? -
Thank you for your response, Ian, …
Very simple in fact … Here is a short program …
I did almost some thing with USB Bit Whalker card … and it works …
>>>‘ Liberty Basic sample application code or any similar programming language …
‘ Written for BP3 … USB Bus Pirate …
‘ RS232 master commands … Through USB …mainwin 40 20
‘ First open the COM port to the BP3 through USB virtual port
OPEN “COM4:300,N,8,1″ FOR random AS #BP3
PRINT #BP3, “#” ; ‘ send reset … or anything command else …FOR I=1 to 9
L$=INPUT$(#BP3,LOF(#BP3)) ‘ Try to read BP3 responses characters …
PRINT I,len(L$),L$ ‘ in fact nothing is read …
next ICLOSE #BP3
END -
OK, Ian, … Found the problem …
Must use some delay for reading BP3 messages … Hi …
New one program that works …‘ Liberty Basic application code
‘ Written for BP3 … USB Bus Pirate …
‘ See http://www.sparkfun.com
‘ RS232 master commands … Through USB …mainwin 40 20
global time, nbl
time=10000‘ First open the COM port to the BP3
OPEN “COM4:115200,N,8,1,CS0,DS0,RS” FOR RANDOM AS #BP3PRINT “Sending Reset …”
PRINT #BP3, “#” ‘ send reset command …
call rd 2 ‘ read some response …PRINT #BP3, “I”; chr$(13) ; ‘ send Info command …
call rd 2 ‘ retrieve response …
CLOSE #BP3sub del time ‘ wait delay time
for i=0 to time
next i
end subsub rd nbl
FOR I=1 to nbl ‘ read nbl lines
call del time
L$=INPUT$(#BP3,LOF(#BP3)) ‘ Try to read BP3 responses characters …
PRINT L$;
next I
end subEND


11 comments
Comments feed for this article