protocol icon indicating copy to clipboard operation
protocol copied to clipboard

Half Duplex Serial

Open dtex opened this issue 9 years ago • 8 comments
trafficstars

My use case it to control a Dynamixel servo which uses Half Duplex Serial. The solutions I've found online use a tri-state octal buffer and a single digital pin to control data direction. I can add an expander in Johnny-Five that adds the direction pin and wraps existing serial but I want to make sure that direction pin doesn't belong in firmata.

Thoughts?

dtex avatar Jun 06 '16 00:06 dtex

Found a related issue:

https://github.com/firmata/arduino/issues/159

dtex avatar Jun 06 '16 00:06 dtex

It depends on how many changes are necessary. If adding support for half-duplex serial is simply a matter of using the existing Serial protocol and toggling a specified digital pin on each state change then that may make sense to add as an addendum to Firmata Serial protocol definition. In that case any Firmata host that already supports Serial would just need to add an additional parameter to specify the direction pin. However if there are nuances per specific hardware, then it would be better to handle the direction pin separate from the Serial protocol.

soundanalogous avatar Jun 06 '16 00:06 soundanalogous

The only thing I've seen in addition to changing the state of the pin is a brief pause (400us) when switching from transmit to receive.

The Serial Config command would change to:

0  START_SYSEX      (0xF0)
1  SERIAL_DATA      (0x60)  // command byte
2  SERIAL_CONFIG    (0x10)  // OR with port (0x11 = SERIAL_CONFIG | HW_SERIAL1)
3  baud             (bits 0 - 6)
4  baud             (bits 7 - 13)
5  baud             (bits 14 - 20) // need to send 3 bytes for baud even if value is < 14 bits
6  rxPin            (0-127) [optional] // only set if platform requires RX pin number
7  txPin            (0-127) [optional] // only set if platform requires TX pin number
8  dirPin           (0-127) [optional] // only set if half duplex data flow pin is required
6|8|9 END_SYSEX     (0xF7)

and then just make the changes in Configurable Firmata:

If that sounds reasonable, I'll give it a shot.

dtex avatar Jun 06 '16 15:06 dtex

Seems this could work. The implementation will be tricky however, because you'll need to track dirPin with the portId in order to support READ_CONTINUOUSLY mode.

soundanalogous avatar Jun 06 '16 18:06 soundanalogous

I was thinking I can just track it in an array, the same way that serialBytesToRead is tracked by port.

dtex avatar Jun 06 '16 19:06 dtex

yeah it may be time to add an array of structs

soundanalogous avatar Jun 06 '16 19:06 soundanalogous

Structs like this?

struct port
{
    int serialBytesToRead,
    unsigned long lastReceive,
    unsigned char maxCharDelay,
    int lastAvailableBytes,
    byte rxPin,
    byte txPin,
    byte dirPin
};

dtex avatar Jun 06 '16 19:06 dtex

yeah but without the rx and tx pins since those are simply passed to the SW Serial constructor

soundanalogous avatar Jun 06 '16 20:06 soundanalogous