Note: The WBus hardware as described here is used by the Wisp programmer but should not be used by new designs.
WBus is a daisy-chain multi-drop pseudo RS-232 bus that I use to connect
a number of PIC-based lab devices to the serial port of my PC.
The main features of WBus are:
summary
| DB9 pin | name | use |
|---|---|---|
| 2 | RxD | This is the serial line from the devices to the host. This line is driven low (high impedance) by each device. It is driven high (lower impedance) by a device which is transmitting. |
| 3 | TxD | This is the serial line from the host to the devices. This line is driven by the host. |
| 5 | Gnd | This is the ground for both serial lines. |
The RS-232 levels on the RxD line are determined by the devices.
Each device pulls this line low by a high impedance (100k)
to ground, and can drive it high (to +5V) via a 330 ohm resistor and
a 1n4148 diode. The diode can be omitted when the device output
is high or high-impedance (never low).
The resulting levels are not standard RS-232,
but they are acceptable to most RS-232 receivers.
The inteface described above is non-echoing.
The interface shown below uses only one pin of the PIC but echoes the
characters sent by the host PC back to the host.
Both echoing and non-echoing interfaces are allowed and can
be used on the same daisy-chain.
All communication is initiated by the host (exception: the
passthrough mode).
To avoid communication overruns the protocol requires that
In most cases the protocol requires a device to echo
any received character back to the host, highest bit cleared
and converted to uppercase, but otherwise unchanged.
The exceptions are:
The voltage levels on the TxD line are determined by the RS-232 driver in the host.
The devices should be able to withstand these levels (unloaded up to +/- 30V).
For a PIC-based device at least a resistor (100k) between the
TxD line and the PIC pin will be needed to limit the current through the protection diodes,
but the circuit below is to be preferred because it limits the voltage on the PIC pin to the
operational range allowed by the manufacturer.
interface
The devices are connected in multi-drop fashion to the serial line.
Each device receives whatever the host sends to it, and
the host receives whatever any device sends, plus (when at least
one echoing device is connected) whatever it sends itself.
The correct use of the protocol ensures that only one device
sends at any time, and no device sends while the host PC sends.
(Otherwise the host would probably receive garbage.)
protocol
The host should assume that a character is lost when it does
not receive an expected response within 1 second.
All characters sent by the host (except in passthrough mode
have the highest bit set. When the host receives a character with the
highest bit set it ignores the character.
This echoing must not be confused with the echoing caused by
an echoing interface, which echoes the character exactly as sent.
| mode | serial line break | HELLO command | PASSTHROUGH command |
|---|---|---|---|
| sleep | goto attention | ignored | ignored |
| attention | remain in attention | if ID matches     then goto active     else remain in attention |
goto sleep |
| active | goto attention | if ID matches     then remain active     else goto attention |
goto passthrough |
| passthrough | goto attention | ignored | ignored |
| format | name | effect |
|---|---|---|
| "break" | Break |
A break condition on the serial line forces the device to the attention mode.
After the break condition the host sends four 0 characters. This can be used by devices with an unreliable clock to calibrate their timing. The host should not rely on the correct reception of these 0's. A break condition is recognised in all modes. |
| abcdH | Hello |
Depending on the value of abcd the device will go to the
attention or active mode:
A Hello command is recognised only in the attention and active modes. |
| N | Next |
The device will echo (instead of the N) the next character from its buffer.
There should not be any other commands between the command which
has set the buffer and the N commands which retrieve the contents of the buffer.
The Next command is recognised only in the active mode. |
| P | Passthrough |
A device which is in the active mode and supports
passthrough will echo the P and enter the passthrough mode.
A device which is in the active mode but does not support
passthrough will remain in active mode and echo a ? instead of the P.
A device which is in the attention mode will enter
the sleep mode.
A device can define arguments to the passtrough command which select different passthrough modes. This does not affect other devices. The Passthrough command is recognised only in the attention and active modes. |
| Q | Query |
The device copies its ID to its buffer.
The host can use N commands to retreive the ID.
The Query command is recognised only in the active mode. |
| T | Type |
The device copies its type (4 characters) to its buffer.
The host can use N commands to retreive the type.
This should be used by a host program to check whether an activated
device is of the type it expects.
The Type command is recognised only in the active mode. |
| abcdU | Burn |
The ID abcd is burned into the device.
The Burn command is recognised only in the active mode. |
| V | Version |
The device copies its version (4 characters) to its buffer.
The host can use N commands to retreive the type.
This should be used by a host program to check
(after it has checked the device type) whether
the device is of a firmware version which it can handle.
The Version command is recognised only in the active mode. |
notespolling
When a tool on the host wants to get the attention of particular
device it must
The first step (serial-line break) takes some time.
It can be omitted when the host knows for sure that all devices are in
active or attention mode (because the same host has previously
issued a serial-line break and no passthrough,
so no device can be in sleep or passthrough mode).
half-duplex
A device should take care that it does not start transmitting before
the command character from the host is fully transmitted, including
one stop bit. Likewise the host should not start transmitting the
next character before the echo is fully received. This is especially
important for devices which bit-bang the serial line without
interrupt support.
no passthrough
A device does not need to implement the passthrough mode.
(In fact, most devices will not.) But the device must still
implement the sleep mode and hence recognise a serial-line break.
Otherwise it could misinterpret the communication between the
host and a secondary device.
no programmable ID
For a device which does not contain a permanent storage which is
under firmware control it might not be practical to implement
the Burn command. Instead the device could have a few dip switches
to set (at least a few bits of) its id, or (less good) it could
have a hardcoded ID. In the latter case the maker should assign
IDs sequentially to each individual device to minimise the change
that a user gets two devices with identical IDs. A device which does
not implement the Burn command should of course echo a '?' instead of the 'B'.
restoring the RS-232 level
Some PC's do not accept the TTL-like levels produced by WBus devices.
In such a case an
RS-232 restoring dongle
can be put between the PC and the Wbus.
| 24-APR-2000 | 2.00 |
|
| 1998 | 1.XX | first version(s) |