I was thinking to use the 2com interface to start with in my midibox sid. However at first I thought it would be possible to make a simple switch for midi / serial selection without any changes to the software and reprogramming the pics, but now I am not sure.
If it does require re-programming, would the following be ok to add to the main.asm of sid application so I can have my switch function?
USER_Init   Â
    movlw 0x00
    call MIOS_SRIO_TS_SensitivitySet
   Â
    movlw 0x00 ; common midi
    btfss PORTC, 4 ; rd4 is 1 is common midi
    movlw 0x01 ; to host
    call MIOS_MIDI_InterfaceSet
   Â
    ...  Â
I would use a 4052 and a switch to switch either the max232 or the 6n138 the rx/tx lines to pic, like so:
         +5
         |
         []10K
         |
      +--SW-+---- To J14 all cores
      |   |
      Gnd  |
         | 4052
         ---------
        | S0   |
        |     |
   Midi RX---|1y1   |
   Midi TX---|2y1   |
        |     |
   COM RX----|1y0   |
   COM TX----|2y0  1z|--- Pic RX
        |    2z|--- Pix TX
        | E S1  |
         ---------
         | |
         +--+
           |
           GND
SW is a simple switch like an on/off switch.
So the idea here is that the interface selection is controlled by a simple switch at power on for all cores.
Changing the MIOS startup will be difficult, since the bootstrap loader already enables the driver of this pin.
Yes, you can put the TRISD, 4 at the beginning of USER_Init, MIOS won’t overwrite this once more.
But take care: the driver of this pin will still be initialized at power-on for ca. 2 seconds. And if you would upload another application, you could also run in trouble. Therefore I recomment a resistor (let’s say 220 Ohm) between J14 and the switch in order to avoid a short.
Does this also take into account the different transfer rates of the connections (ie, does the Core have an auto-detect function)? Otherwise you’re going to run into trouble with MIDI being 31250 bps and serial being… well, whatever your PC’s serial port is set to.
Or is this just designed as a switch for the physical connection, and you otherwise have a device that does 31250 bps over an RS-232 link?
It will run at 38400 over serial with a drivers for several OS’s available. See the midibox-to-COM page or LTC module. Thorsten already made all this.
MIOS has this feature built-in, but normally it is controlled during programming time. This little add-on allows to change the interface type with a switch without the need for reprogramming the device id stuff, so you can easily use it directly with a laptop or in a midi-environment. It is not really auto-detect, but by re-using the J14 (touch sensor) pin, you can let the core (or all cores for the SID) know which interface type to configure. So it is only interface type at a time…