[comp.arch] programming the com port

wsdwgk@eutrc3.urc.tue.nl (g.v.kooij) (09/28/89)

Hello

I want to program the 8250 in a PC clone to communicate with a MIDI device,
which uses the standard MIDI baudrate of 31250 baud. Unfortunately, my docs
say that you can only program it for 9600 (and slower), 19200 and 38400.
Is it possible to do what I want ? Or should I buy additional hardware ??

greetings

Guido

troy@mr_plod.cbme.unsw.oz (Troy Rollo) (10/03/89)

From article <927@eutrc3.urc.tue.nl>, by wsdwgk@eutrc3.urc.tue.nl (g.v.kooij):
wsdwgk> Hello

wsdwgk> I want to program the 8250 in a PC clone to communicate with a MIDI device,
wsdwgk> which uses the standard MIDI baudrate of 31250 baud. Unfortunately, my docs
wsdwgk> say that you can only program it for 9600 (and slower), 19200 and 38400.
wsdwgk> Is it possible to do what I want ? Or should I buy additional hardware ??

Yes - you need to know a little about the operation of the UART chip in the COM ports.
Firstly, we all know about the documentation for the serial ports - how INT 14H can
initialise/operate both COM ports. Don't you believe it. It simply doesn't work. No
explaination, no reason, nothing. It just doesn't work. In fact, as far as I know,
no IBM communications software uses INT 14H to communicate with the COM ports.

So you will need to get a full data sheet for the 8250 and use that. In particular,
you will be interested in ports 3f8 and 3f9 when DLAB is 1. These are the baud rate
divisor bytes.

The procedure to store a value into these is:

	IN al, 3fbh
	OR al, 80h
	OUT 3fbh, al
	MOV al, low_byte
	OUT 3f8h, al
	MOV al, high_byte
	OUT 3f9h, al
	IN al, 3fbh
	AND al, 7fh
	OUT 3fbh, al

The clock rate for the UART is 1.8432 MHz, implying that the value for the
divisor should be 589, or 2 (high), 77 (low). I have a sneaking suspicion that
this needs to be divided by 16... or perhaps even multiplied by 16..... try
all of those and see.

Now the problem with INT14? Well, I have had a guess as to what the problem is, but
I haven't been able to test it. At boot time, COM interrupts are disabled, and
from memory (when I traced INT14), it set up the serial port to use interrupts,
which were simply being masked off by the PIC. You should be able to enable them
with the following:

	cli
	mov al, 13h
	out 20h, al
	mov al, 8
	out 21h, al
	mov al, 9
	out 21h, al
	mov al, 0a4h
	out 21h, al
	sti

Briefly, this reconfigures the PIC to let the normal interrupts (disk, keyboard
and real time clock) through, as well as the two serial interrupts. If you have
a hard disk, you will need to change 0a4h to 084h, which enables everything
except for the printer, and the unused interrupt.

Note that this disables the second PIC on an AT or better. If you are using
interrupts from devices connected to this, you will need to go through a slightly
longer procedure, which I don't have.
___________________________________________________________
troy@mr_plod.cbme.unsw.oz.au	Make our greenies useful!
The Resident Fascist		Put them in the army!

scott@bbxsda.UUCP (Scott Amspoker) (10/04/89)

In article <446@usage.csd.unsw.oz> troy@mr_plod.cbme.unsw.oz writes:
>From article <927@eutrc3.urc.tue.nl>, by wsdwgk@eutrc3.urc.tue.nl (g.v.kooij):

>>[somebody wants to use com port for MIDI]

>[advises that INT 14H doesn't work very well]

It is true.  There is no standard interrupt service of the com ports
on a PC.  If you intend to *really* use the com ports (especially for
MIDI) you will have to write your own driver that includes interrupt
handling (this shouldn't be a major task).

I can't comment on the ability to run the com port at 31k baud but I
remember reading an article a few years ago describing how to modify
a standard PC communications adapter to support MIDI.  It involved
making a small mod to the card itself (breaking a connection and adding
a jumper).  This left me with the impression that you could not use the
communications adapter in its normal state for MIDI.  I'm sorry I can't
tell you more.  I would advise checking into this further.  If all else
fails then check out the Roland MPU-401.  Not only does this guarantee
you MIDI capability but there is plenty of existing MIDI software that
supports the MPU-401.

-- 
Scott Amspoker
Basis International, Albuquerque, NM
(505) 345-5232

clyde@hitech.ht.oz (Clyde Smith-Stubbs) (10/05/89)

From article <446@usage.csd.unsw.oz>, by troy@mr_plod.cbme.unsw.oz (Troy Rollo):
> From article <927@eutrc3.urc.tue.nl>, by wsdwgk@eutrc3.urc.tue.nl (g.v.kooij):
> wsdwgk> Hello
> 
> wsdwgk> I want to program the 8250 in a PC clone to communicate with a MIDI device,
> wsdwgk> which uses the standard MIDI baudrate of 31250 baud. Unfortunately, my docs
> wsdwgk> say that you can only program it for 9600 (and slower), 19200 and 38400.
> wsdwgk> Is it possible to do what I want ? Or should I buy additional hardware ??
> 
> The clock rate for the UART is 1.8432 MHz, implying that the value for the
> divisor should be 589, or 2 (high), 77 (low). I have a sneaking suspicion that
> this needs to be divided by 16... or perhaps even multiplied by 16..... try
> all of those and see.

Nope, 1.8432Mhz divided by 31250 is 59, not 589. And therein lies a problem. The
actual division value you program in has to be 

	Clock rate/baud rate/16

and 1843200 Hz/31250 bps/16 gives us a value of 3.686. There is no way to
program fractional division ratios. That is why 38400 baud can be programmed
but not 31250. 38400 requires a division ratio of 3, which is an integer.
That is actually why the crystal frequency was chosen. To program 31250
you will need to change the crystal. You could use

	clock rate = baud rate*16*N

where N is any integer (i.e. the division ratio you will end up with)

So keeping it close to the original,

	clock rate = 31250 * 16 * 3 = 1.5Mhz

In other words, change the crystal to 1.5MHz and program the baud rate
division to 3 and you will get 31250 baud.
Maybe this where 31250 came from? It obviously can be generated from clock
rates which are fairly rounded numbers.
------------------------
Clyde Smith-Stubbs
HI-TECH Software, P.O. Box 103, ALDERLEY, QLD, 4051, AUSTRALIA.

ACSnet:		clyde@hitech.ht.oz
INTERNET:	clyde@hitech.ht.oz.au		PHONE:	+61 7 300 5011
UUCP:		uunet!hitech.ht.oz.au!clyde	FAX:	+61 7 300 5246
-- 
Clyde Smith-Stubbs
HI-TECH Software, P.O. Box 103, ALDERLEY, QLD, 4051, AUSTRALIA.
INTERNET:	clyde@hitech.ht.oz.au		PHONE:	+61 7 300 5011
UUCP:		uunet!hitech.ht.oz.au!clyde	FAX:	+61 7 300 5246