Go to Triangle Digital Support Home Page TDS2020F TECHNICAL MANUAL
Hardware support
Serial communications
Live website search
Enter key words
 

SERIAL COMMUNICATIONS

DEFINITIONS

'KEY

( - a )

Address of user variable vectoring KEY

'KEY?

( - a )

Address of user variable vectoring KEY?

'EMIT

( - a )

Address of user variable vectoring EMIT

'ACCEPT

( - a )

Address of user variable vectoring ACCEPT

*EMIT

( c - )

(#SERIAL2.TDS) Send lower byte of c to serial Port 2

*KEY

( - c )

(#SERIAL2.TDS) Receive binary byte c from serial Port 2

*KEY?

( - f )

(#SERIAL2.TDS) True if data pending on serial Port 2

<2

(  -    )

(#SERIAL2.TDS) Start of structure

 

 

    <2 . Port 2 I/O . 2>

<ACCEPT>

( a n - )

Take up to n chars from serial Port 1 to address a

<EMIT>

( c - )

Send lower byte of c to serial Port 1

<KEY>

( - c )

Receive lower byte of c from serial Port 1

<KEY?>

( - f )

True if data pending on serial Port 1

1FORTH

(  -    )

(#SERIAL2.TDS) Redirect serial I/O to Port 1

1NOBODY

(  -    )

(#SHELTER.TDS) Empty serial 1 input buffer, throw away contents

232OFF

(  -    )

Turn serial ports off to save power

232ON

(  -    )

Turn serial ports on after saving power

2>

(  -    )

(#SERIAL2.TDS) End of structure

 

 

    <2 . Port 2 I/O . 2>

2BAUD

( n - )

(#SERIAL2.TDS) Set serial Port 2 to baud rate n and initialise serial Port 2 & fifo buffer

2FORTH

(  -    )

(#SERIAL2.TDS) Redirect serial I/O to Port 2

2NOBODY

(  -    )

(#SERIAL2.TDS) Empty serial 2 input buffer, throw away contents

ACCEPT

( a n - )

Vectored word. Normally does <ACCEPT>

BAUD

( n - )

Set serial Port 1 to baud rate n

EMIT

( c - )

Vectored word. Normally does <EMIT>

KEY

( - c )

Receive binary byte c from serial Port 1

KEY?

(  -    )

Vectored word. Normally does <KEY?>

PAGE

(  -  )

Uses EMIT . Clear screen and home cursor

SHELTER

(  -    )

(#SHELTER.TDS) Convert serial Port 1 input to interrupt version with fifo buffer

FILES

Some of the words supporting serial communications are in files, not the Forth ROM. The following files redefine some of them. See also QUAD SERIAL PORT, page 310 for additional ports.

 

#CAN-SER.TDS

Controller Area Network (CAN bus) and serial port intercommunication.

#SERIAL2.TDS

Provides interrupt driven second serial port. Input data is put in a fifo buffer.

#EXTSER2.TDS

(comes with Update Service) Same but with fifo in extended memory.

#EXTXONOF.TDS

(comes with Update Service) Like #EXTSHEL.TDS but with handshaking.

#SHELTER.TDS

(comes with Update Service) Interrupt-driven serial Port 1 input with fifo buffer.

#EXTSHEL.TDS

(comes with Update Service) Same but with fifo in extended memory.

#XONXOFF.TDS

(comes with Update Service) Like #SHELTER.TDS but with handshaking.

HARDWARE

Inputs to the serial ports can be true RS232 levels (at least �3.0V) or just TTL. The outputs are at least �5.0V under a 3k load. The steady state is the negative voltage, which is logic 1 in RS232 terms. The voltages are generated on the TDS2020F from the +5V output of the regulator. No negative supply is needed and the card can be run from a single battery of +6V to 16V.

To save power the serial port drive chip can be turned off. This is described in LOW POWER OPERATION, page 89.

SERIAL PORT 1

Pin connections:

SIN1 Serial input 1

pin a25

 

SOUT1 Serial output 1

pin c25

 

Serial Port 1 is a hardware UART built into the H8/532 microprocessor. See the Hardware Manual Section 14 for details not here or in the Word List. Baud rates supported on serial Port 1 are:

 

Transmit:

38400 31250 19200 9600 4800 2400 1200 600 300 150 75

Receive:

38400 31250 19200 9600 4800 2400 1200 600 300 150 75

 

At power-up the default baud rate is 9600. Note the 31250 baud rate for MIDI use. Transmit and receive baud rates are always the same as each other. Serial Port 1 is used for developing software but can also form part of the application.

Change the baud rate as needed, e.g. 1200 BAUD . Include BAUD in the initialisation of your program if serial Port 1 is to be used at a speed other than 9600 baud. The default mode is 8 data bits, one start and one stop bit but can be changed to other protocols including synchronous use.

The input and output words on serial Port 1 are all vectored and can be redirected to other peripherals as needed. See EMIT in the word list for an example. See LIQUID CRYSTAL DISPLAYS, page 101 for others.

File #SHELTER.TDS is an interrupt driven version of the software for serial Port 1, available with the Update Service. Received characters will not be missed at 9600 baud even when the Forth program is busy doing other work-they are stored in a circular buffer until needed. The position and size of the buffer are user adjustable. The word SHELTER should be executed (once only) to initialise the system.

SHELTER revectors input to the new routine and so shelters the application program from any problem of fast serial input bursts. Its use is advised whenever receiving data from another computer but keypad input is usually slow enough not to require it.

An extended version #XONXOFF.TDS, also part of the Update Service, performs all the functions of #SHELTER.TDS but adds X-on X-off handshaking. There are also versions that use RAM memory in the 32-pin socket to allow bigger buffers.

SERIAL PORT 2

Pin connections:

SIN2 Serial input 2

pin c14

 

SOUT1 Serial output 2

pin c13

 

Serial Port 2 is implemented in software written in machine code. It is not built into the Forth ROM but comes as file #SERIAL2.TDS on disk. If you will be using serial Port 2 incorporate this as part of your applications software.

Although software, it allows a foreground program to continue while asynchronous data is input to serial Port 2. The data received is placed under interrupt into a circular buffer from where it can be taken as needed by the foreground program. This is broadly equivalent to #SHELTER.TDS for serial Port 1.

The interrupt routine uses the 8-bit timer and its associated output compare registers. They should not be used elsewhere in the application.

Put xxxx 2BAUD before second serial port will be needed (execute once only), ideally in the word executed at power-up, where xxxx is the baud rate, e.g.  1200 2BAUD .

Use *KEY and *EMIT to receive and send one byte on serial Port 2. Or use the structure <2 . something here . 2> to temporarily redirect EMIT and KEY to serial Port 2.

Both reception and transmission of each data bit occurs under interrupt so that the main program does not have to hang around servicing the serial port for the duration of the whole byte. Remember for example that after *EMIT the data will still be in the process of transmission while you are executing the words which follow *EMIT 

Baud rates supported on serial Port 2 are:

 

Transmit:

19200

9600

4800 2400 1200 600 300 150 75

Receive:

n/a

n/a   

4800 2400 1200 600 300 150 75

 

Transmit and receive baud rates are always the same as each other but the program is capable of modification to make them different.

The data format is one start bit, 8 data bits and one or more stop bits. If 7 bits plus parity is needed this can be provided at a higher level. The software looks very like a real UART to the main program.

For use with 0V/+5V levels instead of RS232, see GPS SOFTWARE CUSTOMISATION, page 324.

Go to Triangle Digital Support Home Page Go to top   Next page