This page covers the details of MIDI communication on the BX-24.
To send MIDI out from the BX-24, you use the serial commands. You need to set the baudmode to match MIDI settings. You can’t use COM3 for MIDI, because it can’t reach the required baud rate, so you have to use COM1. Wiring is as follows:
You can only set the COM1 serial port to a rate close enough to the baudrate necessary for MIDI. This means you won’t be able to use debug.print statements in your program, as the baud rate will be wrong for the BX-24 development environment. It also means that you can’t use just any I/O pins. You have to use the TX and RX pins of the BX-24 for your output and input, respectively (pins 1 and 2).
I find it’s best to disconnect the MIDI output from the TX pin while programming, to minimize the ubiquitous "Error Halting BX-24" message, then reattach it once the program’s downloaded.
call openCom(1, 9600, inputBuffer, outputBuffer) register.ubrr = 14
This opens the COM1 serial port, then resets the baud rate to 30,720 baud, the closest it can get to MIDI’s 31,250 baud.
Then, you send messages according to the MIDI spec. For example, a noteon channel 1, middle C (note 69), medium velocity (velocity 64) would be:
dim midiCmd as byte dim note as byte dim velocity as byte ... midiCmd = 144 note = 69 velocity = 64 call putQueue(OutputBuffer, midiCmd, 1) call putQueue(OutputBuffer, note, 1) call putQueue(OutputBuffer, velocity, 1)
and a noteoff for the same would be:
midiCmd = 128 note = 69 velocity = 0 call putQueue(OutputBuffer, midiCmd, 1) call putQueue(OutputBuffer, note, 1) call putQueue(OutputBuffer, velocity, 1)