LPC2148 MIDI problem

Hi, am running out of options to check, so am hopeful community wisdom can help me out.

Am having a problem with something that should be really simple; receiving MIDI data on a serial port. I have done this many times on other micro’s; atmel, motorola, but the LPC2148 is giving me strange problems. Data that makes no sense and the LPC reporting framing and break errors.

Baud is 31250, 8N1. (A Bluetooth module connected to the same port receives data perfectly.)

I’ve looked at the pulses from the 4N35 optocoupler with a scope and they have proper definition and amplitude. Have also tried different settings for dividers and fractional divider and could tune it so that the framing errors disappear, got data that is close to the send value but not correct. This made me check the crystal caps and changed these as well, but didn’t help, results were exactly the same.

Odd thing is normal serial communication on the port works fine.

Sounds familiar? No?

Thanks for any hints!

It could be a software problem, are you sure your serial driver works correctly ?

Have you set up the PINSELx registers? If you don’t, then your RX and TX pins will likely default to GPIOs. See pages 75 - 80 in the LPC214x User Manual.

When I use the UART as a normal serial port at say 9600 or 38400 baud, it works fine, all data is accurate and no errors.

PINSEL0 has the correct bits 16+18 set.

It could perhaps be that the opto collector output series resistor has not the right value. I did change it from 330 to 3K otherwise it didn’t get full output amplitude. Increasing it some more could help getting better definition.

It might be interesting to know what the input resistance is on the UART port when configured as input.

Thanks for the suggestions so far!

If the LPC2148 works at normal baud rates, then either you have an incorrect calculation for the 31,250 baud rate or your optocoupler circuit isn’t wired properly. I have MIDI working with an LPC2148, but I’m using a Sharp PC900 optocoupler. The exact schematic I use can be found [here. Click on the hardware link on the left to see the schematic. I also power that section of the schematic at 5V so that my circuit complies to the MIDI spec.](http://www.borg.com/~jglatt/tech/midispec.htm)

Problem solved!

The 4N35 optocoupler needed a 47K clamping resistor from base to ground. This apparently stabilizes the output transistor. I did a survey on MIDI schematics using the 4N35 optocoupler on the net and found almost all of them have the base, pin 6, floating… except one that had a 100K clamp.

Brennen’s suggestion to run the opto’s output from 5V is not necessary as this is not part of the MIDI current loop. Running from 3V3 with an appropriate collector resistor is working fine as the transistor can easily been pulled into saturation.

Thanks for the help!

The output of the opto doesn’t need to be run at 5V since it interfaces with the microcontroller. I was referring to the other stuff in that circuit that I showed you that interfaces to the output side of the MIDI connection. It doesn’t really hurt anything to run the opto at 5V, though.