Skip to content

ESP32-S3 Serial.read() infinite loop #315

Open
@cyberdevnet

Description

@cyberdevnet

Context

Please answer a few questions to help us understand your problem better and guide you to a solution:

  • What board are you using ?

    • ESP32-S3-DevKitC-1 v1.1
  • How are you using MIDI ?

    • Hardware Serial (DIN plugs)
    • Other (BLE)
  • Is your problem related to:

    • MIDI Input (reading messages from other devices)
    • MIDI Output (sending messages to other devices)
  • How comfortable are you with code ?

    • Complete beginner
    • I've done basic projects
    • I know my way around C/C++
    • Advanced / professional

Describe your problem (what does not work):

I'm trying to implement a Serial (DIN) communication to a working BLE Project, so far I can read every MIDI messages coming from my BLE Input device but calling MIDI_Serial.read(); creates an infinite loop where my ESP32 continuosly fires the callback functions.
Should I call somewhere the end() method or my implementation is wrong?

Here the relevant code

#include "Arduino.h"
#include <MIDI.h>
#include <HardwareSerial.h>
#include "src/BLEMIDI/BLEMIDI_Transport.h"
#include "src/BLEMIDI/hardware/BLEMIDI_ESP32_NimBLE.h"
#include "src/midi/MidiIN.h"
#define RXD2 16
#define TXD2 17
BLEMIDI_CREATE_INSTANCE("MIDI_BLE_MEDUSA", MIDI)
MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, MIDI_Serial);

void setup()
{
    Serial.begin(115200);                         // setup HW serial for debug communication
    Serial2.begin(31250, SERIAL_8N1, RXD2, TXD2); // Serial2 (GPIO 16 & 17) for hardware-midi in/out
    MIDI.setHandleControlChange(handleControlChangeIN); // BLEMIDI CC Callback
    MIDI.setHandleProgramChange(handleProgramChangeIN); // BLEMIDI PC Callback
    MIDI.begin(MIDI_CHANNEL_OMNI);                      // Initiate BLEMIDI communications, listen to all channels
    MIDI_Serial.setHandleControlChange(handleControlChangeIN); // MIDI_Serial CC Callback
    MIDI_Serial.setHandleProgramChange(handleProgramChangeIN); // MIDI_Serial PC Callback
    MIDI_Serial.begin(MIDI_CHANNEL_OMNI);                      // Initiate MIDI_Serial communications, listen to all channels
}

void loop()
{
    if (BLE_isConnected && editSettings == 0)
    {
        MIDI.read();   // this works fine
    } 
    else if (Serial2.available() > 0 && editSettings == 0)
    {
        MIDI_Serial.read();  // this is being called in an infinite loop, it never stops receiving midi messages
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions