Trouble with MIDI serial communications.

Started by Craig March 4, 2007
I have a working BasicX-24 system which takes keyboard on/off
messages and creates MIDI messages to an electronic keyboard. This
has worked fine for over a year.

I am creating a 2nd system to convert MIDI messages on the fly for a
friend who has a non-MIDI Standard system.

On booting the BasicX-24 I successfully generate a bunch of test note
on then note off messages.

Code below:
=================================Dim ScanClockCount As Byte
Call ClearQueue(InComm)
Call ClearQueue(OutComm)
For ScanClockCount = 35 To 55
Delay (0.1)
OutputData(1) = 144
OutputData(2) = ScanClockCount
OutputData(3) = 64
Call PutQueue(OutComm, OutputData, 3) 'send all data for this
note
Delay (0.1)
OutputData(1) = 144
OutputData(2) = ScanClockCount
OutputData(3) = 0
Call PutQueue(OutComm, OutputData, 3) 'send all data for this
note
Next

============================
Again, the code above works fine. I cannot seem to get the parsing
code to work so I simply tried to take whatever came in and send it
right back out. This does not work either. At most maybe a single
note will play and never turn off.

It is almost like when I do the "GetQueue" for the current byte count
I may be disturbing any bytes which may still be coming in. I did not
think that would happen.

Note: I have verified that I am safe with RAM usage and the code is
minimal. (much less than the working system)

InComm and OutComm are dimensioned (1 to 59) and InputData is (1 to
45). I am only sending single notes (3 bytes each) so I am no where
near buffer overflow.

See code below:
=====================================Do
Count = GetQueueCount(InComm) 'look for number of bytes in input
queue.
If Count > 0 Then 'data in input buffer ready to process
Call GetQueue(InComm, InputData, Count) 'transfer data from
input queue to array
For Lc = 1 To Count
OutputData(Lc) = InputData(Lc)
Next
Call PutQueue(OutComm, OutputData, CInt(Count))
End If
Loop
==========================================Any help would be appreciated.
Thanks,
Craig
> ... InComm and OutComm are dimensioned (1 to 59) and InputData is (1
to 45). I am only sending single notes (3 bytes each) ...

I don't know much about MIDI on the BX-24 beyond the rate issue, but I
have an unrelated suggestion. If you don't need to have large buffers,
save the RAM space to eliminate the possibility - perhaps likelihood -
that you've crashed the stack.

For testing, if you only need to send three bytes, try three-byte
stacks, or maybe six, but there's no need to allocate 59 bytes in early
code testing.

Another simple technique is to insert a line here or there that simply
turns on, or toggles, one of the processor LEDs to determine where the
code is failing or looping.
Tom
Should read:

For testing, if you only need to send three bytes, try three-byte
_queues_, or maybe six...
Tom
I have gutted the program and reduced the input/output buffer arrays
to minimum size to try and locate the problem and now I am beginning
to question the Sharp 6N138 opto-isolator. This program (see below)
should now simply get a byte from the input queue and send a single
byte to the output queue.

On boot, the program sends out a series of 10 note on/note off
messages and the electronic keyboard plays those perfectly so for
now, I believe the output code and hardware can be assumed to be fine.

However, no way can I pass MIDI data through the code below. The MIDI
source is normaly connected directly to the electronic keyboard. This
new converter simply is placed in series with that functioning MIDI
cable.

Has anyone successfully used the 6N138 for MIDI? It looks like some
pretty poor rise time response on the scope. Right now, unless I am
brain dead (good possibility) I don't think the BasicX-24 or code is
the problem.

I used the schematic from "Physical Computing's web site":
http://www.tigoe.net/pcomp/midi.shtml
=========== CODE ============Lc = 1
Do
Count = GetQueueCount(InComm) 'look for number of bytes in input
queue.
If Count > 0 Then 'data in input buffer ready to process
Call GetQueue(InComm, InputData, 1)
OutputData(Lc) = InputData(Lc)
Call PutQueue(OutComm, OutputData, 1)
End If
Loop

=========== END CODE ===========--- In b..., "Tom Becker" wrote:
>
> Should read:
>
> For testing, if you only need to send three bytes, try three-byte
> _queues_, or maybe six...
> Tom
>
Tom Becker had a good idea to place a resistor to ground from the base
of the 2nd darlington transistor (internal to the Opto-isolator) to
sharpen the rise time. It did in fact do that however still no joy.

It seems I cannot get the 2nd BX-24 to understand a valid byte from a
known good source (1st BX-24) using a MIDI baud rate 30,720 (as close
as this chip can get to the standard of 31,250).

I even tried removing the opto-isolator from the circuit and driving
the RX pin directly and still no joy.

This has been discussed before but has anyone had serial communication
issues using Comm1 on the BX-24 original version Vs. the new high speed
version? My 2nd BX-24 is the latest version. I have set both BX-24
register.ubrr and this works fine for my original BX-24 and seems to
work fine for at least the output (TX) of the 2nd BX-24.

Side Note: In development mode, using 38Kbaud, PC to BX-24, I had fed
this new program over 2000 Note on/Off and control messages from an
existing MIDI file using a test VB program as fast as the VB program
could read the file and spit the bytes out. The program worked
perfectly converting the required control messages and leaving the note
on/off messages alone.