Saturday, May 12, 2012

Linux and the Bus Pirate

The last few days, I have been using the Bus Pirate (BP) to debug and test my I2C User Interface for the Propeller.

After reading all of the Doc's and suggestions on how best to use the Bus Pirate on a Linux system (I use Ubuntu), I was under whelmed. The current suggestions include running; a  "minicon" Terminal Window connected to the USB port (i.e., /dev/ttyUSB0).

Some Terminal Windows are kind-of-dumb (not all), they do not know how to properly support "tabs", making the results from the BP kind-of useless. Especially the results from the BP I2C "v" command

And, as a Linux user, I want an easy-to-use BP command history recall stack. There is nothing worst than attempting to re-type (or cut-n-paste) a previous long BP command.

I wanted something easier - and there is something for free; (assuming you do not mind some supporting text around your BP command).

On your normal Command Line Window, at the Prompt, type the following. In this example, the Bash Shell is being used:

$   D='/dev/ttyUSB0'; cat < $D & stty 115200 < $D

This "cat" background task reads and displays data from the BP.

Then anything you direct to the "$D" port, is executed by the BP as a command;

$ echo "v" > $D; sleep 1; echo

Should return something like the following:

Pinstates:
1.(BR) 2.(RD) 3.(OR) 4.(YW) 5.(GN) 6.(BL) 7.(PU) 8.(GR) 9.(WT) 0.(Blk)
GND    3.3V   5.0V   ADC    VPU    AUX    CLK    MOSI   CS     MISO
P      P      P       I     I      I      I      I      I      I
GND    0.00V  0.00V   0.00V 0.00V  L      L      L      L      L



The "help" command is the "?" mark:

echo "?" > $D; sleep 1; echo


For my Real Time Clock testing:

$   echo "[0xD0 0][0xD1 r:7]" > $D; sleep 1; echo

Note: For the example, the above BP command requests the seven values from my DS3231M Real Time Clock and displays the results as:


I2C START BIT
WRITE: 0xD0 ACK
WRITE: 0x00 ACK
I2C STOP BIT
I2C START BIT
WRITE: 0xD1 ACK
READ: 0x20 ACK 0x22 ACK 0x07 ACK 0x04 ACK 0x10 ACK 0x05 ACK 0x12
NACK
I2C STOP BIT
I2C>



The values decode as: Time= 20:22:07, WeekDay= 04, Date= 10/05/12

If you want to re-execute the command, it is in the normal Unix Shell History command recall stack.

This makes my life easy, and it does not require a special minicom Terminal window to configure.

When finished; remove the "cat" command with normal Unix "kill" commands, or just close and reopen the window.

Yes, . . I know, for the non-Unix type people, the above looks like gibberish, but it works, and it works well.


UPDATE
I replaced the "cat" line above with the following, which makes the output much easier to read by breaking the lines into individual commands. Note: the "]" (stop) is no longer displayed, it is replaced with a Newline.

D='/dev/ttyUSB0'; cat < $D | tr "]" "\n" & stty 115200 < $D 

 --

No comments:

Post a Comment