Garbled Serial Comm

26 May 2010

Serial Comm using the USBTX/USBRX seems to work fine.  Using another set of pins (e.g., p9/p10), the serial comm is garbled. 

I have two Putty sessions, one connected to USBTX/RX (com 11 on my pc) and the other to P9/P10 (com 12 on the pc).  The code attempts to get a char from either one, echo it, and transmit to the other. 

Anything I type into the com11 Putty is fine, but the echo'd response to com12 Putty is garbled.  Anything typed into the com12 Putty is garbled, as well as what is echo'd to the com11 Putty. 

Baud rates, etc. are supposedly set correctly. 

#include "mbed.h"

// term is attached to a serial port on the PC running Putty.  9600,8,n,1
// mbedUSB is the native mbed USB. A separate instance of Putty 
// runs on the PC attached to this com port - set to 19200,8,n,1

Serial term(p9, p10);
Serial mbedUSB(USBTX, USBRX); // tx, rx
BusOut BLUEleds(LED1, LED2, LED3, LED4);

int main() {

    int    cBytes;
    short    icnt=0;

// setup stuff
    mbedUSB.baud(19200);
    term.baud(9600);
    wait(.1);
    mbedUSB.format(8,Serial::None,1);
    term.format(8,Serial::None,1);
    wait(.1);
    
// announce you're ready
    mbedUSB.printf("\fThis is a test\n");
    term.printf("\fThis is a test, too\n");

// process keys
    BLUEleds = 0;
    while (1) {
         if (icnt++ == 0) BLUEleds = BLUEleds ^ 0x0A;   // i'm alive leds

// get char from USB term, echo locally and output to P9/p10 Term 
        if (mbedUSB.readable()) {       
            cBytes = mbedUSB.getc();    
            mbedUSB.putc(cBytes);
            term.putc(cBytes);
        }
// get char from p9/p10 Term, echo locally and output to USB term
      if (term.readable()) {
            cBytes = term.getc();
            term.putc(cBytes);
            mbedUSB.putc(cBytes);
      }
   }        
}

Two Putty Screens

26 May 2010 . Edited: 26 May 2010

Hi Stephen,

This sort of thing usually smells of baudrate configurations, but perhaps in this case it not being connected correctly to the PC. When you say it is connected to the serial on your PC, how exactly have you done this?

A mcu-PC connection usually needs a level converter to convert from TTL (transistor transistor logic) of a chip/microcontroller such as the mbed, and the RS232 interface usually found on PC hardware.

Perhaps you can share a little more about the hardware side of the setup which might help someone identify a gotcha.

Simon

26 May 2010

Simon,

This brings back memories from the bad old days of writing I/F code for Tektronix ASCII Terminals and such.

What I originally tried to connect was a "Matrix Orbital LCD2041" LCD panel.  This communicates RS232, default at 19200, 8,n,1.  Send it a byte, it displays a character based on internal mapping.  When I got just gibberish with this, I reasoned a terminal emulator program would be simpler.  Since my laptop has no RS232 port, I used a KeySpan Model USA-19HS USB<->RS232 adaptor.   Pin2 of the adaptor goes to a TX pin on mbed, and pin 3 of the adaptor goes to a RX pin on mbed (I was using 9/10). 

Note that when I connect the 19HS directly to the LCD panel via the db9, and use the Putty terminal, I can send happy characters to the LCD all day long - so it would seem to be something associated with connecting to the mbed. 

The TTL level idea sounds interesting.  Do I need some additional hardware like a TTL non-inverting buffer or something?

--stephen

26 May 2010

If your adapter has a DB9 connector, it expects RS232 levels - -3V to -15V for logical 1 and +3V to +15V for logical 0. TTL levels used by mbed are 0V for 0 and +3.3V for 1. To convert between RS232 and TTL you need a level shifter - the most common is MAX3222/3232 chip or a clone. Another likely possibility is that your adapter and/or LCD module already includes such converter, so you just need to bypass it.

26 May 2010

Hi Stephen,

Since you are going to have to put together some hardware to do some level shifting, may I be as bold to suggest one of these.

http://uk.farnell.com/ftdi/ttl-232r-3v3/cable-usb-to-ttl-level-seri-converter/dp/1329311

On the "jumper socket" end it talks TTL level serial so will wire up directly to your mbed, and on the other USB, so it appears as a virtual COM port (similar to mbed).

With 9 way D connectors rapidly vanishing from PCs and Laptops, might be a more future proof investment.

Cheers,
Chris

 

 

26 May 2010

Thanks Chris/Igor.  I'll give one or the other of these a go.

This proves what must be a law of nature.  One should never let a mechanical engineer near a breadboard. 

--stephen

26 May 2010
Stephen Price wrote:
Do I need some additional hardware like a TTL non-inverting buffer or something?

Hi Stephen

The conversion between TTL and true RS232 requires an inverting buffer and level shifting. You can use a dedicated chip like the Maxim MAX232. I've just used a MAX233 with the mbed which is a bit more expensive than the MAX232 but does not require any external components (just some links between pins).

If you have a TTL inverting buffer handy you could try that, but strictly the voltage level for RS232 logic 1 is -3 to -25 volts and logic 0 is +3 to +25 volts, so with an inverter you are relying on 0 volts being treated as a logic 1 (this is the case apparently with most UARTs). This is explained here, along with some transistor circuits as another alternative.

Regards
Daniel

27 May 2010

All,

As Igor suspected, the LCD module had some (well hidden and mostly undocumented) solder tabs adjacent to labels "TTL 232 I2C" and smt jumpers soldered in at the 232 locations.  Moving these to TTL makes this device work from mbed p9/p10.  I've ordered a few  MAX233 chips anyway for future projects.  Thanks for all the help.

--stephen