No serial output on UARTs when powered through 5V usb adapator.

02 Jun 2011

Hello,

Problem overview

I have a finished mbed project working fine as long as the USB is connected to a PC.

This project uses the 3 UARTs on p9/p10, p13/p14 & p28/p27 as Midi ports; 3 ins & 3 outs.

When the mbed is powered through an USB adapter, the input serials seems to work (program blinks leds 1 to 3 on each byte input on ports 1 to 3 ). But nothing is output.

Project description

In short, the box is a kind of midi merger/router/convertor. It can recognize certain Midi messages and then drop, transform messages types or parameters ranges and route to any outputs. The actual processing is defined in a separate text file easily editable and just copied to the mbed.

Program description

What the program does in short:

  • instanciate three MODSERIAL
  • open the local file system to read a "filter" definition file
  • parse the file and instanciate a vector of filter definitions
  • close the file
  • main loop is listening to inputs
  • on input reading is done until a complete midi message is received or no byte received after timeout,
  • the complete message is compared to filters
  • if it matches one, the resulting message is computed and sent to output 1 or/and 2 or/and 3.

Here are the MODSERIAL method i call around the program:

  • baud() : 31250 for midi
  • readable() : to check for ready input
  • getc() : to read byte
  • putc() : to output bytes

Nothing fancy, no interupt.

Final thoughts

I first suspected a faulty adapter and i have tried two different power adaptors (500ma and 1A) and an usb hub (1A) without success. I don't think its a power problem, the 5V required by the Midi ports is not drawing amps.

I now suspect some serial initializatin might fail when the USB tx and rx arn't connected and that would have some side effects in the other UARTs initialization... But it is just a wild guess from a novice in electronics (albeit professional developper).

Is there any recommendation for using mbed serial ports while using an independant power supply connected to its usb port ?

Thank you for your time and your suggestions.

Bernard

02 Jun 2011

Try using the GND/VIN pins instead of the USB connector.

02 Jun 2011

Quote:

if it matches one, the resulting message is computed and sent to output 1 or/and 2 or/and 3.

Not wanting to state the obvious but have you put some debugging in, say using USBTX/USBRX, to determine your logic really is resulting in a match and bytes should actually be being sent?

psuedo code

#include "mbed.h"
#include "MODSERIAL.h"

MODSERIAL s1(p9, p10);
MODSERIAL s2(p13, p14);
MODSERIAL s3(p28, p27);
MODSERIAL debug(USBTX, USBRX, 1024, 32);

int main() {
    bool match1 = false;

    s1.baud(31250);
    s2.baud(31250);
    s3.baud(31250);
    debug.baud(115200);

    debug.printf("Starting up...\n");

    while(1) {
        // Assume some logic to decide match
        if (match1) {
            s1.putc(c);
            debug.printf("s1:%d\n", c);
        }
    }
}

With a terminal connected at 115200baud via the USB you'll actually see something was indeed supposed to come out of, in the above case, s1.

If your terminal stays silent, you know you have a logic problem.

02 Jun 2011

I should add:-

Quote:

I now suspect some serial initializatin might fail when the USB tx and rx arn't connected and that would have some side effects in the other UARTs initialization... But it is just a wild guess

Nope, the serials are not "connected" in this way. You would be better publishing your program so we can see your code rather than a textual description.

07 Jun 2011

Hello Andy,

Tank you for your answers and sorry for the delay in my response; I was expecting an email notification for each post activity... Didn't get anything. I just looked up the forum and saw there are indeed responses waiting.

You idea to 'printf' is fine but... the issue only appears when USB is not connected to my PC. ;)

I have added some led blinking to my program: now led 4 blinks on each byte sent. In pseudo-code it is: led 4 on putc(...) led 4 off

Actually i see led 4 blinking fine. So i know i am really calling putc(). I have connected midi outputs to my PC and i am monitoring them with MidiOX and nothing comes up.

I have published my program here : http://mbed.org/users/Midimetric/programs/MidiTee/lsdtup I have also added to my notebook a snapshot of the shield I built : http://mbed.org/users/Midimetric/notebook/miditee/

I will try to monitor UART pins activity with an osc this evening. And i have to check also that mbed VU pin gives a steady 5V when powered like that.

07 Jun 2011

How do you have the 3 serial ports connected to the devices? Are you connecting the grounds from the devices to the mbed as well in addition to the serial in/out pins? In this thread, a similar problem was occurring since having the mbed plugged into the PC was probably providing a common ground over the USB connection but the external power supply wasn't

08 Jun 2011

The three input ports are connected through photocouplers. This is a Midi specification requirement. The three output ports are just connected through a resistor.

Since, input works and output doesn't, it makes sens to think the issue may be linked to powering isolation...

Here is a basic schema (inspired by Tom Scarff's, who does midi breakout boards for Arduino) /media/uploads/Midimetric/midi.png

I have connected an oscilloscope on pins 4 & 5 of the midi out ports. Actually i see midi messages as square spikes (histogram like) in both case (usb to PC / usb to wall socket) So the program (and Andy's library) are out of cause.

There are two differences i noted on the oscillosccope:

The "no signal" voltage is different, usb to PC: 1.5v, usb to wall: 2.v

This difference could be enough to disturb any device connected through midi ? I guess it may. Some voltage comparator could decide that below 1.8v is 'low', above 3.2v is 'high' but wouldn't know how to interpret 2v ?

I have measued the VU on the mbed, it is also a little different: 4.9v when connected to PC, 5.1v on wall adaptor.

The AC is very noisy when connected to wall

I can see square waveforms of about 0.2v range at several kilohertz frequencies. It looks like the power line is conveying other communication signals... Maybe i should try to insert some kind of filtering. I have made myself an usb filter with a big 3000µF capacitor and an inductor salvaged from an ATX power module(*). I will try to insert it between the adapter and the mbed this evening. More to come.

(*) I made this some weeks ago to solve analog input noise on the mbed. Values on the analog input where jumping all around the spectrum until i managed to filter the usb noise... Compared to the Arduino, the mbed is very sensible to external noises. There is some room for improvement there ;)

Todays' epilogue

I know i could have used a standard power adaptor connected to vin. But:

  • i need the usb connector on my box to be able to download a new filter definition text file.
  • the box, wich is a size of a cigarette box, is already stuffed (the six midi connectors take up 80% of the space). The meb and my midi shield are snugged into the 9V battery compartment. There is no much space left to add a power socket... (i will try to take a real picture of it).
08 Jun 2011

There is a possible issue with the MIDI interface circuit.

The TX signal on the mbed is a 3.3V signal. When it goes high, no current should flow through the MIDI loop. But current will flow, since R4 is referenced to +5, not +3.3. This off-state current will be approximately (5.0 - 3.3)/(R4 + R5), or 3.8mA.

That is probably enough to keep activated the opto-coupler inside the MIDI target device.

I see that your PC is supplying about 0.5V less than the wall device. That will reduce the off-state current, apparently enough so that the opto-coupler switches off. That must be why things work when you use the PC, but fail when you use the wall supply.

You could try connecting R4 to +3.3, and scaling R3 and R4 to 220 * 3.3/5.0 = 150 ohms each. That should help.

09 Jun 2011

Thanks Hexley, that looks like a very good explanation. I should have tested this powering scheme while on a breadboard... now i will have to cut trace and desolder.

09 Jun 2011

Bernard,

Before cutting any traces, you might try to 'touch up' your mbed code so that the TX pins' outputs are in open-collector mode. You should be able to change the mode after setting up the serial port configurations. I think you will find that the open-collector mode _is_ compatible with your 5V circuit.

09 Jun 2011

Fred,

I am not sure how to do that... something like ? :

    DigitalInOut  tx0( p28 ); tx0.mode( OPENDRAIN );
    DigitalInOut  tx1( p13 ); tx1.mode( OPENDRAIN );
    DigitalInOut  tx2( p9  ); tx2.mode( OPENDRAIN );

For those curious about my "MidiTee":

The Midi sockets

/media/uploads/Midimetric/dscf5508.jpg

The mbed fitting

/media/uploads/Midimetric/dscf5509.jpg

The mbed attached to the midi breakout board

/media/uploads/Midimetric/dscf5510.jpg

/media/uploads/Midimetric/dscf5511.jpg

mbed unplugged

/media/uploads/Midimetric/dscf5512.jpg

09 Jun 2011

Bernard,

I'm no expert, and others may have better advice. But, I was thinking that one would use direct 'bit fiddling' with '&' and '|' operators on the hardware register which controls the output pins' modes. Do the bit fiddling after all of the serial-setup library calls.

10 Jun 2011

Ok, i have studied the LPC17xx manual and i have found:

  • mbeds' P28 is LPCs' p0.10 (Txd2)
  • mbeds' P13 is LPCs' p0.15 (Txd1)
  • mbeds' P09 is LPCS' p0.0 (Txd3)
  • Changing open-drain mode is done by writting 1 bit per pin on the PINMODE_ODx register. (page 115)

So just going 'open drain' for p0.0, p0.10 and p0.15 whould need to 'or' binary 1000010000000001 on PINMODE_OD0 register like:

LPC_PINCON->PINMODE_OD0 |= 0x00008401

Is this right ?

But i don't know if i have also to change the 'pull' mode (down/up/floating)... (Changing pull-up mode is done by writting two bits per pin on the PINMODEx register. as per page 112)

Or maybe it is just the same as i wrote in my previous post... (as it seems there http://mbed.org/forum/mbed/post/733/)

11 Jun 2011

Your code looks right to me. I think the outputs default to 'float' (which is what you want), and the serial-setup functions do not change that. If so, that one line of code is all you need to add. If there is still a problem after that, you might try a debugging printf() that gives the read values of the Port_0 mode registers after serial-setup (for confirmation that they are still set to 'float').

11 Jun 2011

I have tested today:

Default status for PINMODE0 is floating (value 2 on each bit pair) I have tried the Open drain trick but it does not solve the problem.

Since the issue seems to lie in the USB 5V ( it is working on PCs' 4.9V but not on Adapter 5.1V ) i have tried some power adapter with selectable voltage and a 1.5mm barrel to USB adapter. It works when i select 4.5V on the adaptor!

Well... I have learned in a long carreer of developper that "when something works, don't fix it !". So i will leave it like this. At least i have learned something about mixing 5V rails and 3.3V signals ;) I will have to modify the Midi breakout schema on my next project (a midi surface control with 8 encoders & 24 buttons).

Thanks for your help.

11 Jun 2011

After checking the User Manual, I see that the power-up default for all of the pin-mode registers is listed as zero in section 8.4, which means the on-chip pull-up circuits are enabled. A value of 2 does select the 'float' mode. Did you actually add a line to your code that read and showed the values as '2', or is that information from elsewhere (i.e. serial-setup results)? On the I2C outputs, the open-drain pins are definately supposed to float all the way to +5V (if that is the pull-up's supply voltage). What voltage do you see across the opto-coupler in the open-drain '1' state?

Is there anyone else listening to this thread who can contribute their experience with 5V open-drain GPIO (vs serial) performance?

P.S. I suppose you could replace your external power-supply and USB splice connector with a diode between the mbed Vu and the MIDI +5V rail. While it is true that "What works, works.", I'm sure you are as curious as me to know what is really happening :-).

13 Jun 2011

O, this sounds like a curious mbed feature I discovered just now.

I was running a 5V LCD that works fine while PC USB connected - but LCD fails when external supply is used, and USB detached.

The 5V out on pin 39 of mbed vanishes if USB is pulled, and adding external power will not restore it!

The extract of the mbed schematic shows why this happens. The 5v regulator IC3 is supplied by VBUS only [the power supply from USB host PC]. Diode D1 prevents any other voltage source from providing the 5V power - it must do this, or else the 5V would be 9V or 14V or whatever Vin was.

Of course, VBUS could be diode-ORed from the external supply, but that would require a huskier 5V regulator in place of the low-power IC3 there today. Still, I think this is a bug, and a solution for 5V to be available without the USB is worth having, without having to add a 5V regulator to your own baseboards. A defined current limit combined with a 1W+ regulator IC would suffice to allow 110mA out [at 14V in] - good enough for many low-power peripherals like LCD, optoisolators, 5V-powered RS232 transceivers, etc.

/media/uploads/RodColeman/mbed_5v.jpeg

13 Jun 2011

@Fred:

Quote:

After checking the User Manual, I see that the power-up default for all of the pin-mode registers is listed as zero in section 8.4, which means the on-chip pull-up circuits are enabled.

Actually, what i have measured by reading PINMODE0 is that the value is binary 10 (=2) "floatting". Either the default is changed by mbed boot loader or by serial initialization, either the manual is not correct...

Quote:

P.S. I suppose you could replace your external power-supply and USB splice connector with a diode between the mbed Vu and the MIDI +5V rail. While it is true that "What works, works.", I'm sure you are as curious as me to know what is really happening :-).

I am not THAT curious ;) I think i will leave it like this.