[comp.sys.amiga] RS-232 & MIDI Interface

borzieri@king.ICO.Olivetti.Com (Ivan Borzieri) (09/17/90)

Hi,

I tried to write a little basic prog which reads from the RS-232 data coming
from my keyboard through a MIDI interface.

I tried to set the RS-232 at 9600,N,7,1 and something was read.
I then tried to set it at 19200,N,7,1 and something else was read ! (then
I got a crash)

How is that possible ?

I read that MIDI standard allows instruments to output data at a maximum of
31000 bauds. It means, I think, that if the RS-232 works at a maximum speed
of 19200, the MIDI device works as a buffer !

Does anyone know HOW I SHOULD SET RS-232 TO GET THE RIGHT DATA ?
Is it possible to write a simple program to catch dump data in basic or I
should use C ?

							Ivan Borzieri

UH2@psuvm.psu.edu (Lee Sailer) (09/18/90)

In article <49417@olivea.atc.olivetti.com>, borzieri@king.ICO.Olivetti.Com (Ivan
Borzieri) says:
>I tried to write a little basic prog which reads from the RS-232 data coming
>from my keyboard through a MIDI interface.

>I tried to set the RS-232 at 9600,N,7,1 and something was read.
>I then tried to set it at 19200,N,7,1 and something else was read ! (then
>I got a crash)

I believe that MIDI is quite different from RS-232.  Just because it
uses the same plug on the Amiga doesn't mean it uses the same *electrical*
characteristics.  That's why Amigas  need MIDI adapters.  This is a
simple device with a couple of resistors and whatever in it that
converts the signals at the serial port to MIDI.  The simple ones cost
about $40 US or so, and go up to maybe $99 US for ones with lots of
"features".

           lee

slfields@uokmax.uucp (Scott L Fields) (09/18/90)

In article <90260.142801UH2@psuvm.psu.edu> UH2@psuvm.psu.edu (Lee Sailer) writes:
>In article <49417@olivea.atc.olivetti.com>, borzieri@king.ICO.Olivetti.Com (Ivan
>Borzieri) says:
>>I tried to write a little basic prog which reads from the RS-232 data coming
>>from my keyboard through a MIDI interface.
>
>>I tried to set the RS-232 at 9600,N,7,1 and something was read.
>>I then tried to set it at 19200,N,7,1 and something else was read ! (then
>>I got a crash)
>
>I believe that MIDI is quite different from RS-232.  Just because it
>uses the same plug on the Amiga doesn't mean it uses the same *electrical*
>characteristics.  That's why Amigas  need MIDI adapters.  This is a
>simple device with a couple of resistors and whatever in it that
>converts the signals at the serial port to MIDI.  The simple ones cost
>about $40 US or so, and go up to maybe $99 US for ones with lots of
>"features".
>
>           lee

Actually, He was just off buy not going from 19,200 to 38,400. That is the
speed at which MIDI transmits and basically at rs232 levels as well. 
{not sure what having the data will mean unless you already know the
capabilities of your keyboard----aftertouch,attack,etc}

billsey@agora.uucp (Bill Seymour) (09/18/90)

In article <49417@olivea.atc.olivetti.com> borzieri@king.ICO.Olivetti.Com (Ivan Borzieri) writes:
:Hi,
:
:I tried to write a little basic prog which reads from the RS-232 data coming
:from my keyboard through a MIDI interface.
:
:I tried to set the RS-232 at 9600,N,7,1 and something was read.
:I then tried to set it at 19200,N,7,1 and something else was read ! (then
:I got a crash)
:
:How is that possible ?
:
:I read that MIDI standard allows instruments to output data at a maximum of
:31000 bauds. It means, I think, that if the RS-232 works at a maximum speed
:of 19200, the MIDI device works as a buffer !
:
:Does anyone know HOW I SHOULD SET RS-232 TO GET THE RIGHT DATA ?
:Is it possible to write a simple program to catch dump data in basic or I
:should use C ?

	MIDI only works at one baud rate, 31250 baud. You will need to read
the data at that rate in order to get correct data. A MIDI interface doesn't
buffer the data, it just isolates the data between the computer and all the
MIDI instruments.
	Try setting your software to use the serial port at the 31250 rate,
that should work for you.

:							Ivan Borzieri


-- 
     -Bill Seymour             ...tektronix!reed!percival!agora!billsey
=============================================================================
Bejed, Inc.       NES, Inc.        Northwest Amiga Group    At Home Sometimes
(503) 281-8153    (503) 246-9311   (503) 656-7393 BBS       (503) 640-0842

wayned@wddami.spoami.com (Wayne Diener) (09/18/90)

>In article <1990Sep17.223404.15640@agora.uucp> billsey@agora.uucp (Bill Seymour) writes:
>In article <49417@olivea.atc.olivetti.com> borzieri@king.ICO.Olivetti.Com (Ivan Borzieri) writes:
>:Hi,
>:
>:I tried to write a little basic prog which reads from the RS-232 data coming
>:from my keyboard through a MIDI interface.
>:
>:I tried to set the RS-232 at 9600,N,7,1 and something was read.
>:I then tried to set it at 19200,N,7,1 and something else was read ! (then
>:I got a crash)
>:
>:How is that possible ?
>
>	MIDI only works at one baud rate, 31250 baud. You will need to read
>the data at that rate in order to get correct data. A MIDI interface doesn't
>buffer the data, it just isolates the data between the computer and all the
>MIDI instruments.
>	Try setting your software to use the serial port at the 31250 rate,
>that should work for you.
>
>:							Ivan Borzieri
>
>-- 
>     -Bill Seymour             ...tektronix!reed!percival!agora!billsey

Not only that, but the MIDI signalling is done via a 20 MA current loop.
You have to convert  RS-232 <---> MIDI ... both ways.  For software support
get ahold of midi.library (available on lots of BBS's).  Yes, it's even
useable with BASIC (although if you insist on BASIC, at least use a 
compiled version.  AmigaBasic is just too slow to take in all the MIDI
data.)

--
|---------------------------------------------------------------|
|       //                  Wayne D. Diener                     |
|      //                   Spokane, WA                         |
|  \\ //     E-mail reply to:                                   |   
|   \X/      To: isc-br!hawk!wddami!wayned@uunet.uu.net         |

whinery@hale.ifa.hawaii.edu (Alan Whinery) (09/19/90)

In article <49417@olivea.atc.olivetti.com> borzieri@king.ICO.Olivetti.Com (Ivan Borzieri) writes:

>I tried to write a little basic prog which reads from the RS-232 data coming
>from my keyboard through a MIDI interface.
>
>I tried to set the RS-232 at 9600,N,7,1 and something was read.
>I then tried to set it at 19200,N,7,1 and something else was read ! (then
>I got a crash)
>How is that possible ?
Whenever the serial chip in your Amiga sees what it thinks is a start bit,
it will take eight samples at the current baud rate and then if it gets what 
it thinks is a stop bit, it will assume it has received a byte. SO, if the
data coming in is not at the same baud rate, you will get garbage based on 
some random falling edge as the start of the start bit, etc. 
>
>I read that MIDI standard allows instruments to output data at a maximum of
>31000 bauds. It means, I think, that if the RS-232 works at a maximum speed
>of 19200, the MIDI device works as a buffer !
Close, but no banana. The baud rate of specification MIDI data is ALWAYS
31250 baud. (Some manufacturers use 62500 for parameter loads, but that's 
not MIDI spec) RS-232c includes no specification for maximum speed, although
it does address limitations of transmission media (I think.) Your Amiga is
fully capable of doing RS232c at 100k baud or so, so 31250 MIDI is not a 
problem.

>
>Does anyone know HOW I SHOULD SET RS-232 TO GET THE RIGHT DATA ?
>Is it possible to write a simple program to catch dump data in basic or I
>should use C ?
There are two readily available ways to make BASIC do MIDI. ==>

1. Use Preferences to set your serial speed to 31250 baud (1.3 at least),
in BASIC, open SER: device like you would a file, read and write from/to it
and you will be able to mess around with MIDI or whatever it is you're 
trying to serialize. I have successfully done this, and although it is 
limited, it allows one to experiment and learn how MIDI works.

2. Get the publicly distributable Pregnant Badger MIDI libraries, which,
although written for use with C, do come with instructions for use with BASIC.
This is a much more involved approach, probably involving a couple of days
of experimentation and frustration and reading the manuals, unless you are
a STAR BASIC programmer.

>
>							Ivan Borzieri

Alan Whinery
Comedian, coyote, genius,
whinery@hale.ifa.hawaii.edu

FILLMORE@EMRCAN.BITNET (09/19/90)

Yes, it is possible to process MIDI data from AmigaBasic.  I did this a couple
of years ago when I first got my Amiga.  Of course you still need to buy a
MIDI interface to translate between the MIDI and RS-232 electrical signals.

The trick is to open the serial port at a legal baud rate and then switch
to the MIDI baud rate (31250), as follows:

  OPEN "com1:9600,n,8,1" AS 1
  adr1 = &HDFF
  adr2 = &H32
  adr = adr2+adr1*4096
  POKEW adr,(1000000!/(.2794*31250))

Then you can read and write using ordinary I/O statements, such as:

  IF LOC(1)<>0 THEN
    c$ = INPUT(1,1)
  END IF

The variable c$ will contain a byte of MIDI data if there is any present.
I wouldn't advise that you use this technique to play music because you
don't have any control over timing.  It works fine for dumping MIDI data
or for loading/dumping system exclusive data (I wrote a little patch
librarian in Basic).

Good luck!

________________________
Bob Fillmore, Systems Software & Communications     BITNET:  FILLMORE@EMRCAN
  Computer Services Centre,                         BIX:     bfillmore
  Energy, Mines, & Resources Canada                 Voice:   (613) 992-2832
  588 Booth St., Ottawa, Ontario, Canada  K1A 0E4   FAX:     (613) 996-2953