Midi 4.2 no activity on serial port

Status
Not open for further replies.

philjynx

Member
Hi, I know this has come up before, but I've found nothing that has resulted in a fix for me.

I have a teensy 3.2 which works fine with the 'bundled' MIDI library on Arduino 1.6.7 and teensyduino.
I need to have multiple midi instances (more than one uart connected din socket), so I've (temporarily) put MIDI 4.2 in my librarys folder.
I can get a clean compile of my sketch which runs just fine, except that it generates no activity on the serial port and responds to no input either.

Below are some fragments from the Midi 4.2 code. I've made one minor modification in order to try to see what's happening, some serial.print()s in the sending section.
Otherwise, it's all as is.

I have read posts that say the library on github doesn't work, but that a 'tagged' version does. I have downloaded and compared both, they are identical, so that didn't help.

This is driving me nuts.



This is a fragment from the top of Midi_defs.h
#pragma once

#include "midi_NamespacePW.h"
#include "HardwareSerial.h"
#if ARDUINO
#include <Arduino.h>
#else
#include <inttypes.h>
typedef uint8_t byte;
#endif


And later in midi_defs.h
/*! \brief Create an instance of the library attached to a serial port.
You can use HardwareSerial or SoftwareSerial for the serial port.
Example: MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, midi2);
Then call midi2.begin(), midi2.read() etc..
*/
#define MIDI_CREATE_INSTANCE(Type, SerialPort, Name) \
midi::MidiInterface<Type> Name((Type&)SerialPort);


#if defined(ARDUINO_SAM_DUE) || defined(USBCON)
// Leonardo, Due and other USB boards use Serial1 by default.
#define MIDI_CREATE_DEFAULT_INSTANCE() \
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
#else
/*! \brief Create an instance of the library with default name, serial port
and settings, for compatibility with sketches written with pre-v4.2 MIDI Lib,
or if you don't bother using custom names, serial port or settings.
*/
#define MIDI_CREATE_DEFAULT_INSTANCE() \
MIDI_CREATE_INSTANCE(HardwareSerial, Serial, MIDI);


#endif

within midi.hpp the actual 'sending code' - I've added some serial.print()s to see if this is getting exected.
template<class SerialPort, class Settings>
void MidiInterface<SerialPort, Settings>::send(MidiType inType,
DataByte inData1,
DataByte inData2,
Channel inChannel)
{
// Then test if channel is valid
if (inChannel >= MIDI_CHANNEL_OFF ||
inChannel == MIDI_CHANNEL_OMNI ||
inType < 0x80)
{
if (Settings::UseRunningStatus)
{
mRunningStatus_TX = InvalidType;
}
Serial.println("Don't send");
return; // Don't send anything
}

if (inType <= PitchBend) // Channel messages
{
// Protection: remove MSBs on data
inData1 &= 0x7f;
inData2 &= 0x7f;

const StatusByte status = getStatus(inType, inChannel);

if (Settings::UseRunningStatus)
{
if (mRunningStatus_TX != status)
{
// New message, memorise and send header
mRunningStatus_TX = status;
mSerial.write(mRunningStatus_TX);
}
}
else
{
// Don't care about running status, send the status byte.
mSerial.write(status);
}

// Then send data
mSerial.write(inData1);
Serial.println("sending data1");
if (inType != ProgramChange && inType != AfterTouchChannel)
{
mSerial.write(inData2);
Serial.println("sending data2");
}
}
else if (inType >= TuneRequest && inType <= SystemReset)
{
sendRealTime(inType); // System Real-time and 1 byte.
}
}
 
Please.. without indentation the code is difficult to read. Use the proper tags in the editor. Thank you.
 
Please.. without indentation the code is difficult to read. Use the proper tags in the editor. Thank you.

I agree with you. When I wrote it (the post, not the code - most of this is not my code), I couldn't see anything that allowed you to tab or format. After a bit of fiddling I found 'Go Advanced', which looked like it could be done there.
It would not let me increase the indent beyond the line above, so I found I couldn't present the code properly indented without editing the original authors code from one line to the one above which I don't think I should do, badly indented or not, it is at least the authors original code with my three debugging lines inserted. Someone will either have encountered this issue using Teensy 3.2 and Midi 4.2 or not. I'd love to present the code as it appears in my code editor, but have been unable to do so.
 
Hm, just a guess: You know that "Serial " is USB only ?
For the "real" Serial, use Serial1

Thanks,
I probably should be shot, I neglected to include my code which is:

...
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, RolandMIDI);
...

So, on the teensy 3.2 it's serial port One, i.e. pins 0 and 1 that I am using.
As I mentioned, incoming RX signals are happening fine, but outgoing TX signals - there are none, yet using the old 2.6 MIDI library it all works fine, so no hardware problem.
 
Status
Not open for further replies.
Back
Top