A Serial Interface Project for the ZX-81 & TS/1000, Part II

See all articles from QZX v4 n4
Author(s): Ambrose Barry (W4GHV)
Publication: QZX
Pub Details: QZX v4 n4 (Volume 4, Issue 4)
Date: March 1986
Pages: 2-3

(based upon Vic Rice’s article from SYNC Magazine-Nov ’82)

A few additions to the schematic published last month. The first interface line (top left) goes to the system clock, the next one goes to +9 volts, and the third goes to ground. Actual pin numbers to the Timex/Sinclair will be provided in next month’s issue.

To utilize the RS-232 interface with a packet controller, we need a simple ‘terminal program’. The one presented this month is only a START. In fact it hasn’t been tested yet! There is lots of room for improvements like split screen transmit & receive, transmission of ‘canned messages’, etc.. Hopefully the experts will come to our rescue. If not, Alex & I will develop the program. Our simple term program does two things- it receives and it transmits. A few words about these steps.

Receiving data

1) First we initialize the UART’s control port to the receive mode

2) Next we check the Status Read flags for RXRDY, which tells us a character has been received.

3) When a character is received, move it from the data port to the computer’s memory.

4) Loop thru steps 2) & 3) until a carriage return (end of line) is received.

5) Translate the received ASCII characters to the Sinclair character set and display the result.

6) The TNC sends data to the RS-232 in packets (usually a line of text) as long as the RS-232 DTR line is high.

Transmitting data

1) First we initialize the UART’s control port to the transmit mode

2) Input a character from the Sinclair keyboard

3) Translate the character to ASCII

4) Check the Status Read flags for TXMT, which indicates the UART is ready to transmit a character.

5) When the UART is ready, POKE the translated character into the UART data port.

6) Loop thru steps 2) – 5) until a carriage return is sent.

7) The TNC does not transmit the typed characters as we type them, but sends them out in a packet. You can take two minutes thinking/typing a sentence, and the TNC only keys your transmitter for a few milliseconds to send the packet when you finally get around to hitting a carriage return. Would you believe about 10 or so people can share a SINGLE frequency, at the SAME time! If your packet collides with someone else’s, the TNC is smart enough to send it again. A bit different from RTTY, you say?

Here’s our first cut at a term program, with a discussion following it, describing the programming of the UART.

10 LET C = 8192
20 LET D = 8193
30 LET M = 123
40 POKE C, 64
50 POKE C, M
60 POKE C, 22
70 LET X$ =""
80 IF PEEK C = 133 THEN GOTO 80
90 LET X$ = X$+CHR$ (PEEK D)
100 IF PEEK D = 13 THEN GOTO 120
110 GOTO 80
120 FOR P = 1 TO LEN X$
130 LET Y = CODE (X$(P TO P))
140 LET Y = Y -27
150 IF Y <31 THEN LET Y = Y+ 7
160 IF Y <28 THEN LET Y = 0
170 PRINT CHR$ Y;
180 NEXT P
190 PRINT
200 INPUT X$
210 CLS
220 POKE C, 64
230 POKE C, M
240 POKE C, 49
250 FOR Q = 1 TO LEN X$
260 LET Y$ = X$(Q TO Q)
270 LET Y = CODE Y$
280 IF Y$<"A" THEN LET Y = Y+ 20
290 IF Y$>"9" THEN LET Y = Y+ 27
300 IF Y$=" " THEN LET Y = 32
310 IF PEEK C<> 133 THEN GOTO 310
320 POKE D,Y
330 NEXT Q
340 IF PEEK C<> 133 THEN GOTO 340
350 POKE D, 13
360 GOTO 40

Looking at some of the line numbers above:

The variables C and D refer to the UART’s CONTROL and DATA port addresses. They are fixed, determined by the hardware configuration.

The variable M is for the mode setting. A complete description of programming the UART is NOT going to be given. The purpose of this interface is to communicate at 300 baud with a TNC-2. For M = 123 as in line 30, this sets the UART up for 1 stop bit, even parity, parity checking enabled, 7 data bits/character, and a baud rate of 300. To alter this setup, we alter the 123 value by subtracting 32 for odd parity, subtracting 16 to disable parity, subtracting 1 for 1200 baud (good luck running the Sinclair at this rate), or we add 4 if 8 data bits/character is desired.

Poking a 64 to the control port (line 40) resets the UART.

Poking a 22 to the control port (line 60) sets the UART up to receive, asserting DTR (Data Terminal Ready), so the TNC-2 will send some characters. Poking a 49 (line 240) will set up the transmit mode.

In line 80, we loop looking for a 133, which indicates DSR -Data Set Ready (TNC-2 is ready), TXMT transmitter is empty -the buffer is ready to send another character, and RXRDY- receive buffer is ready to receive another character. If all this occurs, we read in a character. At 300 baud, each received character takes about 35 milliseconds, but we still don’t have enough time to convert it and display. So we wait until one complete line is received and then convert and display. The TNC-2 has a 2K RAM buffer, so it doesn’t lose any of the incoming characters (from the VHF channel).

To test things out, jumper pins 2 & 3 of the RS-232 connector, and jumper pins 5 & 6. Then when you type characters, they should be displayed. If characters are lost when connected to the TNC, we may have to add a line just prior to line 120 which will drop DTR to tell the TNC we are temporarily busy. Since our Sinclair does not have a Control key, we will need to re-program the TNC to accept something that is on our keyboard. I’m not quite sure how to do this. We could find out the ASCII equivalent of the ** key, for example, on the Sinclair and issue the following to the TNC: COMMAND n where n is the decimal ASCII equivalent of the ** key.

See you next month.