Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 8 of 8

Thread: Midi sysex issues (hardware midi not usbMIDI)

  1. #1

    Midi sysex issues (hardware midi not usbMIDI)

    hi all. my first post!

    I am using a Teensy 4.0 as a midi device that pretends to be a Mackie MCU, which I can then use to remote control my DAW (Cubase).

    I have set it up to work with either usbMIDI or hardware midi, using the Teensy 3 circuitry described on this page: https://www.pjrc.com/teensy/td_libs_MIDI.html

    However I am having a problem with the hardware midi that doesn't occur with usbMIDI.

    If I keep my System Exclusive code disabled, it all works fine when connected via usb or midi cables. But when I enable it, it works fine via usb, but via midi cables odd things will happen once clusters of Midi System Exclusive data from DAW come through.

    Midi notes and controller data going in both directions works fine on both usbMIDI and hardware midi.

    These are the problems that occur, often in this order, but sometimes jumping straight to 3!

    1. my 2x NeoKey 1x4 devices which are connected via i2c might malfunction or freeze
    2. the serial connection might be lost and my PC can no longer detect it. The Teensy seems to keep functioning apart from that. Often fixed by restarting the Teensy, but sometimes requires a PC reboot.
    3. Always eventually the Teensy will lock up completely and become unresponsive. Requiring a reset. Or sometimes a PC reboot


    If I force the PC to send many SysEx messages in quick succession, by scrolling rapidly up and down the tracks, that will usually force the issue to occur immediately. but as I said if I am connected via usbMIDI, scrolling like this causes no issues.

    So in summary, clusters of sysex data over hardware midi seems to go wrong. Occasional Sysex messages are fine, and any other midi data is always fine.

    I am aware that SysEx is handled differently by usbMIDI vs hardware midi. eg usb has a buffer of 60bytes. Could that be the problem here? can I restrict the hardware midi to 60byte chunks in the same way? The MCU sysex data I'm dealing with is sometimes longer than 60bytes, but it never seems to be longer than ~150.
    Are there other differences between the way usb and hardware Midi types handle SysEx?
    Is it possible that a big block of midi data pulls too much power and disrupts some of the other hardware?

    I am running it all from a PC usb3 port, no additional power. I have tried various values of pull up resistor on the i2c pins, and it made no difference. I have also added capacitors between the power rails (5v/3.3v) and 0v in case it needed some smoothing. Made no difference.

    Any advice gratefully received.

    Thanks!

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,855
    Have you tied defining the sysex buffer to be,say, 200 bytes?

    Pete

  3. #3
    Senior Member
    Join Date
    Aug 2019
    Location
    Melbourne Australia
    Posts
    288
    In C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\MIDI\s rc\midi_settings.h
    Line 73 has:-
    Code:
    static const unsigned SysExMaxSize = 128;
    Try changing this to:-
    Code:
    static const unsigned SysExMaxSize = 256;
    Restart the IDE for this to take effect.

    Also, marginal (brand new) optocouplers exist. you might try a 1k resistor from 6N138 pin 7 to 0v.

  4. #4
    Thanks both for your suggestions!

    I tried increasing the max size, and noticed some much longer messages coming through, so increased some more.
    Sadly though the Teensy still reboots itself or freezes up after a short time of sysex messages coming through.
    I tried various value resistors between pin 7 on the 6N138 and 0v, and that didn't help.
    I also tried swapping for another brand new 6N138 I have. No difference.

    I'm pretty stuck. Any more suggestions appreciated! Thanks

  5. #5
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,855
    I think we're going to need to see the code.

    Pete

  6. #6
    I'm fairly certain the problem is related to the SSD1306 display I am using.

    So in summary:
    - sparse midi data works fine via USB midi or Hardware midi
    - dense midi data (lots of sysex, controllers and notes) works fine via USB midi, but causes severe instability via hardware midi
    - unplug the SSD1306 or comment out the code related to it, and it becomes perfectly stable.

    I am using the Adafruit_SSD1306 library.

    I added some timers in my code and can see that updating the SSD1306 takes 25.8ms, which is the slowest part of the whole project by a huge margin. Everything else combined seems to be less than a ms.

    I need a bigger screen anyway, so was planning to swap it out for a ILI9341 based display. I have never used one before. Are they much quicker, or should I expect similar problems?

    Thanks!

  7. #7
    oh, I should add that I did some optimisations to my code to ensure that the SSD1306 parts were all contained in one function only run when absolutely needed, which massively helps the stability. Also only update the parts of the screen that needed to change etc.

    But even when I had it only doing that function once a second it still got unstable after a minute or so rather than a few of seconds.

  8. #8
    I switched to an ILI9341 display and the problem has gone away! It seems pretty stable now.

    Updating the display has dropped from a guaranteed 25ms down to what seems to be less than a 10th of that, but more variable.

    So I am thinking the problem may have been the SSD1306 update was hogging too much CPU time in one block, and that was causing problems when dense clusters of midi arrived at the hardware midi input, in a way that didn't affect the USB Midi.

    Does that sound like a feasible explanation?

    Also, I couldn't get the Adafruit ILI9341 to work in 8bit parallel mode on the Teensy4.0. It said something about incompatible hardware and wouldn't compile. So I'm using SPI currently, which seems fine.

    Does parallel mode definitely work with Teensy?

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •