Asynchronous serial + clock signal

I would like to communicate with an old electronic device which offers a bidirectional digital data interchange interface based on asynchronous serial protocol (8251A IC on the device): LSB first, 8 data bits, 2 stop bits, odd parity, and a Baud rate of 31.25 kHz .

The physical connection consists on 7 wires (3 wires in each direction plus a shared ground):

  1. Rx Busy [out]
  2. Rx Data [in]
  3. Rx Clock [in]
  4. Ground
  5. Tx Busy [in]
  6. Tx Data [out]
  7. Tx Clock [out]

Signals are standard TTL 0-5V, except the Rx Busy output, which is an open collector pulldown.

[EDIT] Communication is full duplex.

Despite the communication being asynchronous, Rx clock is actually being generated by the transmitter, so that the receiver's UART samples the incoming signal at a pace imposed by the transmitter.

While writing this post, I was temped to write "strobe" instead of "clock"; but observing the circuit of the old electronic device, I found that the outbound clock signal is actually generated by a ceramic resonator running at 4 MHz; this is then divided:
- by 2 => 2 MHz: is the input main clock of the 8251A
- by 128 => 31.25 kHz: is the transmission clock that is fed into the 8251A [TxC] AND output to the [Tx Clock] wire

I suppose that the Serial library is noway useful to handle such a communication; moreover I suspect that builtin USART of the AVR is not able to natively accomplish the task (I've read the datasheet and I didn't find anything regarding external clock for USART operations)

One option could be:

  • For transmission: setup a timer-based interrupt (at the 31.25 * 2 = 62.50 kHz frequency) and generate the outbound clock signal [Tx Clock] and, in the same time, send data [Tx Data] together with start/stop/parity bits
  • For reception: attach an interrupt routine to the digital pin bound to the [Rx Clock] signal: the routine should then handle the [Rx Data] pin; once again, framing logic has to be handled in software..

1st question: could this be a feasible approach? I'm somewhat concerned about CPU time spent in interrupt handling; second, protocol handling logic (especially for reception) could not be so easy..

Another solution could be: use an external USART :innocent:

2nd question: could be this a better approach? Using USART chips is a completely new territory for me, so suggestions are welcome on which IC to consider in order to integrate with an Arduino board... [P.S: the IC on the old electronic device is a PD8251AC or a MSL8251AP]

Sorry for the long post, but I hope that I was clear enough.

Thank you in advance.

Ale

No need for interrupt handling as far as receiving is concerned. BUT, how does you machine know it is going to be receiving a message and not try to send a message at the same time? OR is it FULL DUPLEX? If it is, you have a REAL problem.

Hi Paul. Yes, it's full duplex. I forgot to mention it in my post.

Start by sending charaters in one direction and verify it works. Reverse the direction and verify.
Communication is fun but can easily get difficult. As already told, some kind of protocol, rules for the "chat" are needed. Time out if no message arrives in time etc.

The it is not possible with a single device. At least not with the usual Arduino.

I would use a rising edge interrupt for receiving. Each rising edge, sample the data line. If you aren't in the middle of a character and the input is HIGH (idle) do nothing. If it's LOW you have your start bit so you start accumulating bits until you have the data and parity and the two Stop bits. Then check parity and stop bits before putting the character in the buffer.

For transmitting, I'd just clock out the bits in software. Since you are providing the transmit clock the timing iisn't at all critical.

I had to go look at an 8251 data sheet. Been 50 years since I touched one. The clock signal for either the TX or RX is NOT symmetrical and they don't seem to be identical. There was not a lot of information on using an external clock for the chip.

Have you confirmed that the data rate is 31.25kHz? If that's the clock fed into the TxC and RxC pins of the UART, it could be 16x or 64x the actual data speed, unless the UART is configured for a 1x clock (which I THINK would be unusual. the use of a 16x clock would be one of the reasons to use a UART instead of just some shift registers, in those days.)

In any case, it looks like the data being sent by your device is standard format, and I'd expect that an Arduino UART port configured for a bitrate of 31250 (or 31250/16) could receive data from your device while completely ignoring the TxC pin - the whole point of a multiplied clock is to be able to sample the data somewhere OTHER than the "edge" of the pulse.

Data TO the 8251 is more of a problem. if it's in 1x clock mode, it's going to be sampling data on the rising edge of the RxC signal, and you want that to occur sometime near the middle of the data bit, For that to happen, you'd have to somehow synchronize the transmission of data from the AVR to that clock. Certainly doing a full software-uart-style operation would work, but you MIGHT be able to get by by waiting for a falling edge (and a bit of delay?) before starting a standard Serial.print() at the correct bitrate, sort of:

    while (digitialRead(RXC_PIN) == HIGH)
      ; // wait for falling edge of clock
    delayMicroseconds((1.0/31250)/4);  // wait till halfway through low state of clock
    Serial.write(data);    // write the actual data.

It might need some adjusting because I'm not sure of the exact time delay between doing Serial.print() and the start bit coming out of the TX pin.

The point is that an Asynchronous data format is designed not to need the exact Rx or Tx clocks. If the 8251 is operating in 16x clock mode and the clock pins are being driven directly off a divider of a resonator, I'd expect that you could read and write to it with Serial configured for 1953bps, and it would work fine without paying any attention to the clock signals...

The clock signal for either the TX or RX is NOT symmetrical

I didn't see anything like that at 8251A Datasheet PDF Download - Intel - nor anything that implied that TxC/RxC needed to be anything other than a (possibly not identical) square wave.
Just "Data is sampled on the rising edge of RxC" and "The falling edge of TxC shifts out data" (maybe that's what you meant by "asymmetrical"?)

What I saw was the on and off time for the TX and the RX clocks were not symmetrical and not the same values for each clock. But perhaps it turns out it is a "don't care".

Not really helping but the datasheet of the 328P does mention synchronous operation.

"Synchronous operation" usually omits the start and stop bits.
The 8251 has a synchronous mode too, and it's different than the 1x external clock mode in async mode.

The it is not possible with a single device. At least not with the usual Arduino

That was my suspect... I am increasingly convinced that an additional IC must be used.. maybe just an 8251!

Yes, 328P is capable of synchronous serial operations. But this is a different (mixed) situation: the communication is asynchronous, BUT here the transmitter sends its own clock signal to the receiver... as it was synchronous mode (like in I2C)!

That does not solve the full duplex problem.
Does the mystery device send with no external stimulus? OR can it be set to only send when queried by a device connected to the serial connection? Is there any configuration that will allow only half duplex communication?

For the sake of completeness, this topic was already discussed in this forum, without success:

https://forum.arduino.cc/t/midi-juno-60-dcb-to-midi-converter-need-help/78000/5
https://forum.arduino.cc/t/serial-data-to-analog-synthesizer/170144/3
https://forum.arduino.cc/t/arduino-comme-dcb-to-midi-converter-pour-controler-juno60/77807

Each time the attempt was to assume that, the receiver and transmitter frequencies being the same, the receiver can then ignore the inbound clock signal; with this assumption in mind, the Serial library is then used.

In order to be as much as possible clear, this is the circuit of the digital interface in the old electronic device:

In the lower part, you can see the 4 MHz crystal that:

  • clocks (2 MHz) the 8251
  • clocks (31.25 kHz) the TxC (8251 transmission clock) AND the outbound TX CLK signal on the wire

Moreover, you can see that inbound RX CLK signal is fed directly from the wire to the RxC (5251 receiver clock)

Another extract from the service manual from which I excerpted the drawing:

dcb_interface_2

And from the 8251 specs:

dcb_interface_4

dcb_interface_3

According to this documentation, the usage of the 8251 is totally legitimate, although totally weird and unusual. 8251 main clock is 2 MHz, TxC is locally generated at 31.25 kHz and transmitted to the receiver; RxC is generated on the other party. The factor is 1 for both TxC and RxC, they both have reasonably similar frequencies and these are abundantly less than 30 times the CLK frequency.

I'm convincing myself that Arduino alone is not enough: an external USART chip is needed. What do you think?

And I am convinced the mystery device could NEVER be full duplex in operation. I hated working with any device with an 8251. So user hostile. There were USARTS that were so much more friendly. I NEVER encountered a full duplex device, ever, in that time frame.

More over, the schematic shows you can use ANY clock signal to send to the device, so a 1200 or even 2400 bps clock will work.

What baud rates can the software serial for the Arduino be set to? I presume you have looked that up.

What baud rates can the software serial for the Arduino be set to? I presume you have looked that up.

300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 31250, 38400, 57600, and 115200

Assume the 300 would still allow the old device to read and process the data. Now we need to find where the software serial generates it's clock and pick it up to send with the data. How do you feel about writing your own software serial code?

How do you feel about writing your own software serial code?

Never tried before, but it's not far beyond my skills...

Assume the 300 would still allow the old device to read and process the data.

OK, let's assume it, but I don't understand where this road leads. The objective is to talk in serial at 31.25 kHz, sending the clock and the busy signals together with the serial signal... And performing transmission and reception in the same time. Please let me understand what is your plan :slight_smile:

PS: DCB is one ancestor of MIDI (same bps). Transmitted data consists of instructions that switch on and off sound generation circuits. In the case of the old electronic device, each packet of data consists of 8 consecutive bytes. At 300 bps, only ~3 packets per second could be sent, and this is not acceptable for musical purposes.

You other device only supplies the clock signal when IT transmits. So that is fixed in frequency, unless you decide to change the clock, which is not impossible, The processor there will not care.
On the other side, the clock the Arduino supplies is not material to the processor on the far end. It will only care about the completed character in the USART buffer.

Think about using the Arduino to make the clock for both ends. The clock ONLY signals the 8251, not the accompanying microprocessor, It could care less.
If this were my project, I would bypass all the stuff leading to the 8251 clock pin and supply a standard clock of your choice from your Arduino. Then you have a much faster clock for both ends. The only magic is the clock generator logic for the TX side of the 8251.

The number of packets per second has no bearing on the 8251 clock rate. The 8080 or 8085, or whatever controls that. On the Arduino side, your program will determine when to send packets, not the communication clock.