Go Down

Topic: What's the maximum baud rate I can use with MIDIUSB and mocolufa? (Read 553 times) previous topic - next topic



I am developing a midi controller based on Arduino Mega 2560, so far everything is working fine, this is my first project in Arduino and I am finding the platform and the tools very intuitive.

I am trying to get the lowest possible latency, I didn't build my controller (physically) so I can't use it yet,  I am waiting for some components to arrive. In the mean time I want to be sure that the communication between the controller and the apps in my pc is as fast as possible, I am going to controller a looper and I need high accuracy.

I decided to use mocolufa firm in the atmega16u2 because it is really convenient to be able to use a jumper to switch between modes during development.

I am using the Arduino MIDI Library to generate the midi data. Docs in that library say that you can override the default midi baud rate in cause you are using MIDI over USB, you can read this in the midi_Settings.h header file. I have followed the instructions there and I can override this value without problems.

But any value higher than the default 31250 breaks the communication between my controller and any app reading midi in my computer. I use MIDI-OX to debug messages and Reaper for testing in a real world scenario. This is what I get in MIDI-OX when I try to send CC64 (sustain)

Code: [Select]
000010C4   2  --     FF    --    --   --  ---  System Reset

I have tried this values as the serial baud rate: 115200(which I don't think is a good value for the mega @16MHz), 250000, 500000 and 1000000.

Is this supposed to work, I mean using a value higher than 31250 for midi communication over USB. If so, where is the problem in my setup? could it be the mocolufa firm?

Thanks for your help.


Ok, I have found the solution reading the mocolufa code

Code: [Select]
  if ((PINB & 0x04) == 0) { /* Arduino-serial (JUMPER BTW PB2-GND) */
    mocoMode = 0;
    Serial_Init(9600, false);
  } else { /* Moco mode */
    mocoMode = 1;
    if ((PINB & 0x08) == 0) { /* high speed mode */
      highSpeed = 1;
      // UBRR1L = 1; /* 500K at 16MHz clock */
      UBRR1L = 0; /* 1M at 16MHz clock */
    } else {
      UBRR1L = 31; /* 31250Hz at 16MHz clock */
    UCSR1B = (1<<RXEN1) | (1<<TXEN1);
    PORTB = 0x0E;        /* PORTB1 = HIGH */

this is the relevant line:

Code: [Select]
    if ((PINB & 0x08) == 0) { /* high speed mode */

So there is a pin that enables high speed mode.

A jumper in this position enables high speed mode @ 1Mbps, so you have to configure your midi instance with the baud rate @ 1000000:

BTW, if you need precompiled .hex files to flash your atmel16u2 with  mocolufa you can find them here: https://github.com/user3bss/MocoLufa_Build

Go Up