hi there,
i have two teensy LC boards connected TX to RX pin and GND. one teensy receives MIDI from usb and sends it out the serial port and the other receives from serial and sends back out to usb (MIDI).
i reconfigured the serial midi baud rate to be much higher then standard midi in order to speed up the "conversion" from usb to usb.
this generally works very well, but sometimes the receiving teensy freezes completely and only a reset helps. i have compiled the code with the "fastest" optimisation, could that lead to freezes? is there any benefit in my use case to use the "fastest" optimisation? i just want to send the usb MIDI as fast as possible to the other usb-port. how long can the wire from TX to RX be at 1.5Mb baud rate? would it be wise to use a small resistor?
find attached the code of the two boards:
usb to serial:
serial to usb:
i have two teensy LC boards connected TX to RX pin and GND. one teensy receives MIDI from usb and sends it out the serial port and the other receives from serial and sends back out to usb (MIDI).
i reconfigured the serial midi baud rate to be much higher then standard midi in order to speed up the "conversion" from usb to usb.
this generally works very well, but sometimes the receiving teensy freezes completely and only a reset helps. i have compiled the code with the "fastest" optimisation, could that lead to freezes? is there any benefit in my use case to use the "fastest" optimisation? i just want to send the usb MIDI as fast as possible to the other usb-port. how long can the wire from TX to RX be at 1.5Mb baud rate? would it be wise to use a small resistor?
find attached the code of the two boards:
usb to serial:
Code:
#include <MIDI.h>
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI1);
//MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, MIDI2);
elapsedMillis ledOnMillis;
void setup() {
pinMode(13, OUTPUT); // LED pin
digitalWrite(13, LOW);
MIDI1.begin(MIDI_CHANNEL_OMNI);
// MIDI2.begin(MIDI_CHANNEL_OMNI);
Serial1.begin(1500000);
// Serial2.begin(1500000);
// put your setup code here, to run once:
}
void loop() {
bool activity = false;
if (usbMIDI.read()) {
// get the USB MIDI message, defined by these 5 numbers (except SysEX)
byte type = usbMIDI.getType();
byte channel = usbMIDI.getChannel();
byte data1 = usbMIDI.getData1();
byte data2 = usbMIDI.getData2();
// byte cable = usbMIDI.getCable();
// forward this message to 1 of the 3 Serial MIDI OUT ports
if (type != usbMIDI.SystemExclusive) {
// Normal messages, first we must convert usbMIDI's type (an ordinary
// byte) to the MIDI library's special MidiType.
midi::MidiType mtype = (midi::MidiType)type;
// Then simply give the data to the MIDI library send()
MIDI1.send(mtype, data1, data2, channel);
// MIDI2.send(mtype, data1, data2, channel);
activity = true;
}
}
if (activity) {
digitalWriteFast(13, HIGH); // LED on
ledOnMillis = 0;
}
if (ledOnMillis > 15) {
digitalWriteFast(13, LOW); // LED off
}
// put your main code here, to run repeatedly:
}
serial to usb:
Code:
#include <MIDI.h>
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI1);
void setup() {
MIDI1.begin(MIDI_CHANNEL_OMNI);
Serial1.begin(1500000);
// put your setup code here, to run once:
}
void loop() {
if (MIDI1.read()) {
// get a MIDI IN1 (Serial) message
byte type = MIDI1.getType();
byte channel = MIDI1.getChannel();
byte data1 = MIDI1.getData1();
byte data2 = MIDI1.getData2();
// forward the message to USB MIDI virtual cable #0
if (type != midi::SystemExclusive) {
// Normal messages, simply give the data to the usbMIDI.send()
usbMIDI.send(type, data1, data2, channel, 0);
}
}
// put your main code here, to run repeatedly:
}