RS-232

From C64-Wiki
Jump to navigationJump to search
Stub This article is very short and not very detailed. Please help to improve it.
RS232 interface for User Port

RS-232 is a communications standard developed for computers. The Commodore 64 does not have the standard implementation and needs to be adapted to communicate with standard RS-232 computers or peripherals. The decision for this was based on keeping the price of the C64 as low as possible.

RS-232 communications are handled through the User Port. Access through this port is done by POKE commands. Refer to User Port for more specific information.


C64 - RS232 interface[edit | edit source]

From HwB
 User Port C64                                           C64 RS232
                       _________
                      |         |
   PA2 M-----------11-|         |-14------------------- TXD (2)
   PB1 D-----------10-|         |--7------------------- RTS (4)
   PB6 K-----------12-| MAX 232 |-13------------------- CTS (5)
 FLAG2 B---X--------9-|         |--8------------------- RXD (3)
   PB0 C---|          |         |--3--|+-|
   VCC 2-----------16-|         |--1-----|              DB25 plug
   GND N------X----15-|         |
              X--|+-2-|         |--5--|+-|
              X--+|-6-|_________|--4-----|
              |
              |---------------------------------------- GND (7)

-|+- capacitor 22µF/16V
-  +

Programming in BASIC[edit | edit source]

The programming of this interface can be done in BASIC with the normal input/output commands (OPEN, CLOSE, PRINT#, CMD, GET#, INPUT#) and the system variable ST, but with the following caveats:

  • The OPEN command allocates two data buffers of 256 bytes (one for output and one for input) and will in the process run the CLR command, which clears all variables! If the program has less than 512 bytes variable memory free, the last part of the BASIC program is overwritten!
  • CLOSE removes both buffers and clears the variable memory again. If data is in the output buffer then it will also removed. Check that the output buffer is empty before closing.
  • Using INPUT# isn't recommended, because it hangs the program and must be stopped with RUN/STOP +RESTORE .


Example Listing

10 REM *************** control register settings
15:
20 BR=6: REM 300 baud 
30 DB=0: REM 8 data bits (one a parity bit, see line 80) 
40 SB=0: REM 1 stop bit
45:
50 REM *************** command register settings
55:
60 HS=1   : REM X-wire
70 UA=0   : REM full duplex
80 PA=160 : REM mark parity (8.databit always 1)
90:
100 REM ************** general settings
105:
100 LF=20: REM logical file number (any will do)
110 GA=2a: REM device number of RS-232 interface
120 SA=0e: REM secondary address
125:
200 OPEN LF,GA,SA, CHR$(BR+DB+SB) + CHR$(HS+UA+PA)

After that you can use the following commands:

Links[edit | edit source]

WP-W11.png Wikipedia: RS-232
WP-W11.png Wikipedia: Baud
WP-W11.png Wikipedia: V.28
WP-W11.png Wikipedia: TTL
  • DIY RS-232 Language German
  • Modern Alternative: [1] Simulant User Port to rs232 serial adapter