DESIGNING AN IEEE-488 RECEIVER WITH THE SYM
Part 1: Implementing the IEEE-488 Bus on a SYM-1
Larry Isaacs, COMPUTE Staff
This article is the first in a series on the use of a single board computer as a dedicated interface. In this section I will describe the design of an interface connecting a Spinwriter to the PET IEEE-488 Port using a SYM-1. If you have a need for an interface or controller, but not much experience using single board computers, this series should provide some pointers on how to go about implementing one.
In this article, the discussion of the IEEE-488 Bus will be limited to that which is relevant to the PET, and to how the PET sends data to a printer. Also, when the software to be presented is too general to give the actual assembly language, it will be given in PASCAL. The listings should be readable, even if you haven't had much exposure to PASCAL. The names used in the PASCAL listings will correspond to the names used in the assembly language listings. The following notes should help if you haven't seen PASCAL before.
- PASCAL uses “ : = ” for the assignment operator; “ = ” is used only for comparisons.
- The “;” is used to separate statements.
- When statements are enclosed between a “begin” and an “end;”, it means that that block of statements may be treated as if they were one statement. The programs are indented to help show which “end;”'s go with which “begin”'s.
DIVIDE AND CONQUER: A STARTING POINT
One of the most effective ways to handle design problems is to successively divide the required functions into small sets of sub-functions. Once the complexity of a sub-function has been reduced to a manageable level, then it is implemented.
The first division of the PET-to-Spinwriter interface is shown in Listing 1.
Listing 1.
program PETTOSPINWRITERINTERFACE; procedure INIT; begin…end; {initialization} procedure PRINT; begin…end; {send chr. to Spinwriter} procedure CYCLE; begin…end; {get byte from IEEE} procedure INTERFACE; begin…end; {main interface software} begin {PET to Spinwriter Interface} INIT; INTERFACE end.
Here, the interface task has been divided into four sub-functions. The task of the INIT procedure will become apparent as the other parts of the software are written. The INTERFACE procedure will contain the intelligence of the interface. The exact function of INTERFACE can't be determined yet, so this sub-function will be dealt with later.
The PRINT and CYCLE sub-functions will be used by INTERFACE to communicate with the PET and the Spinwriter. Unlike the others, the functions of PRINT and CYCLE are sufficiently narrow in scope to be implimented at this point. Both will involve dealing with hardware as well as software. But once done, most of the hardware details will be taken care of.
The purpose of this routine is to handle all of the requirements for communicating with the Spinwriter. To do this, one must first consult the Spinwriter and SYM-1 documentation:
Our Spinwriter has a serial interface. This means we can use the serial interface software provided in the SYM-1 Monitor to send characters to the Spinwriter. The Spinwriter Product Description manual reveals that CARRIER DETECT (pin 8 on the RS232 connector), DATA SET READY (pin 6), and CLEAR TO SEND (pin 5) must be high (between +3 and +12 volts) for the Spinwriter to operate. This was simple to take care of since the SYM-1 provides this voltage at the corresponding locations of the T connector.
The Product Description manual also reveals a way of increasing throughput by using the ETX/ACK protocol. This makes use of the 256 character receive buffer found in the Spinwriter. You use this protocol by sending data blocks of up to 254 characters followed by an ETX character (control C). When the Spinwriter withdraws the ETX character from the receive buffer, it transmits an ACK character (control F) to indicate the buffer is empty and ready for another block of characters. This will allow the SYM to transmit at 1200 baud, and let the Spinwriter print at its maximum speed. All of this leads to Figure 1 which shows how to attach the required RS232 connector to the SYM.
After the proper initialization, the OUTCHR subroutine in the SYM Monitor can be used to send characters to the Spinwriter, and the INCHR subroutine to receive the ACK character involved with the protocol.
Figure 1. SYM to Spinwriter Hardware
The assembly language for PRINT is shown in Listing 2.
Listing 2
0111- 20 47 8A 1570 PRINT JSR OUTCHR ;PRINT AND INC. COUNT 0114- E6 00 1580 INC *COUNT 0116- D0 0C 1590 BNE RETURN 0118- A9 03 1600 ACK LDA #$03 ;ASCII ETX 011A- 20 47 8A 1610 JSR OUTCHR 011D- 20 58 8A 1620 JSR INCHR ;WAIT FOR ACK 0120- A9 02 1630 LDA #$02 0122- 85 00 1640 STA *COUNT 0124- 60 1650 RETURN RTS
CYCLE
The function of CYCLE is to read the byte on the data lines during a byte transfer cycle on the IEEE bus. In some cases, the INTERFACE sub-function will need to know the state of some of the other signals during the transfer. CYCLE should therefore sample the signal lines as well.
All the information needed for the IEEE part of the interface can be found in the Commodore CBM manual. The information in this section will deal only with the byte transfer cycle. The remaining information will be presented in the next part of this article. In the discussion below, reference is made to active and inactive devices. An active device is simply one which is participating in the current transfer cycle. Before continuing, you may want to refer to Table 1 which lists the IEEE signals and a brief description of their function. In this table, Listener refers to the receiving device, and Talker refers to the sending device.
The IEEE bus make use of three handshake signals. These are the NRFD, NDAC, and DAV lines. When the CYCLE routine is entered, both the PET, the SYM, and any other active devices are expecting a byte transfer to take place. This means that NRFD and NDAC are low, and NDAV is high. At this point CYCLE sets NRFD high, indicating the SYM is ready to proceed with the byte transfer. Since the NRFD signal line is Wire-ORed, any active device can hold the NRFD line low. This means the cycle doesn't proceed until all active devices indicate they are ready.
Once NRFD goes high, the PET responds by placing the byte to be transferred on the DIO lines and then setting DAV low to indicate valid data. When CYCLE sees DAV go low, it should read the data lines and then sample the signal lines. Now CYCLE sets NDAC high to indicate that the data has been accepted. The NDAC line is also Wire-ORed, so the other active devices must indicate they have accepted the data before the cycle can finish.
When the PET sees the NDAC line go high, it sets DAV low. Once CYCLE sees the DAV line go high, it resets NDAC to the low state completing the cycle. Now CYCLE returns to the calling software. Refer to Listing 3 for the assembly language for this routine.
Listing 3
00E7- A9 03 1390 CYCLE LDA #$03 00E9- 8D 00 A8 1400 STA @2IORB ;NRFD=1 NDAC=0 00EC- 2C 00 A8 1410 @1 BIT @2IORB ;TEST DAV 00EF- 70 FB 1420 BVS @1 ;BRANCH IF DAV=1 00F1- 6A 1430 ROR A 00F2- 8D 00 A8 1440 STA @2IORB ;NRFD=0 NDAC=0 00F5- AD 01 A8 1450 LDA @2IORA 00F8- 49 FF 1460 EOR #SFF 00FA- 85 02 1470 STA *DATA 00FC- AD 00 A8 1480 LDA @2IORB 00FF- 85 01 1490 STA *SIGNALS 0101- A9 00 1500 LDA #$00 0103- 8D 00 A8 1510 STA @2IORB ;NRFD=0 NDAC=1 0106- 2C 00 A8 1520 @2 BIT @2IORB 0109- 50 FB 1530 BVC @2 ;BRANCH IF DAV=0 010B- A9 01 1540 LDA #$01 010D- 8D 00 A8 1550 STA @2IORB ;NRFD=0 NDAC=0 0110- 60 1560 RTS
TABLE 1
NAME | SET BY | DESCRIPTION |
DIO1-DIO8 | Talker | Data Input/Output. These lines carry the commands and data. |
NRFD | Listener | Not Ready for Data. When low, it means the device is not ready to receive data. It is set high when the device is ready. |
DAV | Talker | Data Valid. When high, it means the data on the data lines is not valid. It is set low once all NRFD goes high and valid data has been placed on the data lines. |
NDAC | Listener | Not Data Accepted. When low, it means that the data has not been accepted. It is set low once DAV goes low and the data has been latched. |
ATN | Talker | Attention. Signals that the byte on the DIO lines is a command. |
EOI | Talker | End Or Identify. Signals that the last data byte is being transferred. |
IFC | Interface Clear. Resets all devices. |