MIDI causes crash on Teensy 4.1

Status
Not open for further replies.

PAAUX4

Well-known member
Running on a Teensy 4.1, this gets up to 185 bytes sent every time and then stops. Any ideas? Thanks.

Code:
#include <MIDI.h>

HardwareSerial serialPort0 = {Serial1}; //bi
HardwareSerial serialPort1 = {Serial7}; //bi
HardwareSerial serialPort2 = {Serial8}; //bi
HardwareSerial serialPort3 = {Serial4}; //out
HardwareSerial serialPort4 = {Serial3}; //out

	
MIDI_CREATE_INSTANCE(HardwareSerial, serialPort0, port0);
MIDI_CREATE_INSTANCE(HardwareSerial, serialPort1, port1);
MIDI_CREATE_INSTANCE(HardwareSerial, serialPort2, port2);
MIDI_CREATE_INSTANCE(HardwareSerial, serialPort3, port3);
MIDI_CREATE_INSTANCE(HardwareSerial, serialPort4, port4);

decltype(port0)* outHardwarePorts[] = {&port0, &port1, &port2, &port3, &port4};
decltype(port0)* inHardwarePorts[] = {&port0, &port1, &port2};

	void begin(){
		for(auto p : outHardwarePorts){
			p->begin();
		}
	}

void setup(){
	Serial.begin(9600);
	begin();
}

int bytesSent = 0;

void loop(){
	for(int p = 0; p<128; p++){
		delay(10);
		for(int po = 0; po<5; po++){
			int c =1;
			// MIDIports::MIDIPort mpo = static_cast<MIDIports::MIDIPort>(po);
			Serial.print("PITCH: ");
			Serial.println(p);
			Serial.print("PORT: ");
			Serial.println(po);
			delay(20);
			outHardwarePorts[po]->sendNoteOn(p, 100, c);
			bytesSent+=3;
			Serial.println(bytesSent);
			delay(20);
			outHardwarePorts[po]->sendNoteOff(p, 97, c);
			bytesSent+=3;
			Serial.println(bytesSent);
			delay(20);
			outHardwarePorts[po]->sendRealTime(midi::Continue);
			bytesSent++;
			Serial.println(bytesSent);
		}
	}
}
 
This should be easy for someone to solve. If nobody can solve it, looks like I am the most intelligent person here...
 
I don't think you're supposed to make copies of the serial ports. Not sure why the HardwareSerial copy constructor isn't deleted.
If you want to declare the serial ports separately, use references instead: HardwareSerial &serialPort0 = Serial1;

Pieter
 
I don't think you're supposed to make copies of the serial ports. Not sure why the HardwareSerial copy constructor isn't deleted.
If you want to declare the serial ports separately, use references instead: HardwareSerial &serialPort0 = Serial1;

Pieter

That is wonderful, Pieter. Thank you very much for your help.
 
Status
Not open for further replies.
Back
Top