Why Setting the Wrong MIDI Baud Rate?

Status
Not open for further replies.

chrisgr99

Member
I'm running the following program on a Teensy LC, which based on examples should be sending "hairless midi" at 115200 baud out the default serial port. However my other device which I know can receive midi at 115200 baud fails to receive it. Looking at the the output on my scope and analyzing the timing of the bit transitions, I can see that the baud is almost exactly 31250 baud, so I assume that for some reason "MySettings" is not changing the baud rate from the default. What could the problem be? I'm running a recent version of the MIDI library installed through Visual Micro.

#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>

struct MySettings : public midi :: DefaultSettings {
static const long BaudRate = 115200;
static const unsigned SysExMaxSize = 128;
};

MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial1, MIDI, MySettings)

void setup()
{
MIDI.begin();
}

void loop()
{
MIDI.sendNoteOn( 42, 85, 1);
delay(2);
MIDI.sendNoteOff(42, 85, 1);
delay(4);
}
 
This problem seems to be related to the Teensy. I tried running it on an Arduino UNO and it gives the correct baud rate of 115200.
 
I have no idea why the MIDI library isn't using the custom baud rate setting.

But I did a quick test here. This seems to make it work:

Code:
void setup()
{
  MIDI.begin();
  Serial1.begin(115200);
}

file.png

My best guess is this is very likely a bug in the MIDI library. Might be worth opening an issue on that library's issue tracker?

Also... you're aware Teensy LC can do real class-compliant USB MIDI, right? No need for hairless & extra hardware.

https://www.pjrc.com/teensy/td_midi.html
 
I have two versions of a MIDI library on my system. The one in the TeensyDuino distribution does not have BaudRate in the DefaultSettings struct (in midi_Settings.h) whereas the one I've installed in my libraries directory does. I don't know if that's significant but it might explain what you are seeing.

Pete
 
I have no idea why the MIDI library isn't using the custom baud rate setting.

Thanks! Resetting the baud rate does fix the problem.

Code:
void setup()
{
  MIDI.begin();
  Serial1.begin(115200);
}

The reason for the TTL midi is that Teensy is acting as a peripheral to another custom board I developed, and that board has the USB midi port for the overall device.
 
Status
Not open for further replies.
Back
Top