RS232 to USB Converter

Any general or miscellaneous queries that do not fit into the other forum catagories

Moderators: Benj, Mods

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

RS232 to USB Converter

Postby Spanish_dude » Fri Dec 10, 2010 4:08 pm

Hi,

For a project at school I needed to make a VBA program to communicate with there protoboard called "ADµC" (ADuC) through a COM port.
(Hyperterminal: Baud Rate 9600, No parity, 1 stopbit, 8 bits send/receive, Xon/Xoff)
Then sending a couple of commands like ":WDHello". (Write Display : "Hello") ...

This COM port is a RS232 to USB converter cable (USB as serial) and the program is working fine.

So I thought of doing something similar with a PIC microcontroller.

On my PIC programmer there's a PIC 16F877A with a 4MHz oscillator. I tried to send "Hello", through PORTC, to the hyperterminal, but nothing happens.
I think the TX and RX pins don't match the RS232 to USB, or maybe I'm setting something wrong in the RS232 component in flowcode v3 ?

I attached the program I'm using to send "Hello" through UART/USART

Can anyone help me ?

Rgds,

Nicolas L. F.

EDIT:

I just thought about something...
Is the output of the RS232, of the RS232 to USB cable, +12V and -12V ?
If so, it's obvious it doesn't work >_<.

EDIT 2:

Just as I thought, the output signal of the RS232 port is not TTL.
I suppose I need a MAX232...
Attachments
Flowcode1.fcf
RS232 Test File
(4 KiB) Downloaded 246 times

User avatar
Benj
Matrix Staff
Posts: 14567
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4598 times
Been thanked: 4239 times
Contact:

Re: RS232 to USB Converter

Postby Benj » Sat Dec 11, 2010 12:48 pm

Hello,

A MAX232 is probably the best method but there is another way to do this low cost.

http://www.bobblick.com/techref/project ... cdterm.gif

This uses two resistors and a diode and works nicely. Obviously its a hack and will not be as noise resistant as a MAX chip but I have used it personally and it works well.

User avatar
Benj
Matrix Staff
Posts: 14567
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4598 times
Been thanked: 4239 times
Contact:

Re: RS232 to USB Converter

Postby Benj » Sat Dec 11, 2010 12:51 pm

Note if you have already put 12V directly onto an I/O pin then you may want to test the pin with a LED etc to make sure it still functions.

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: RS232 to USB Converter

Postby Spanish_dude » Sun Dec 12, 2010 4:00 pm

I have 3 or 4 MAX232 so that won't be a problem, but I'm definitely going to try that "hack" ASAP.

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: RS232 to USB Converter

Postby Spanish_dude » Mon Dec 13, 2010 7:44 pm

Yes ,
I got it to work :mrgreen: !

EDIT:
Writing to the hyperterminal works great.
Reading from the hyperterminal works too, but the LCD's contrast is changing when I press on a key.

Pressing 'h' makes it brighter, and 'w' makes it darker.

It's a bit strange ...
Am I doing something wrong here ?

The flowcode program is something like :
1) Receive char
2) is char not equal to old_char
- 2 is false : go to 1)
- 2 is true : go to 3)
3) is char equal to 255
- 3 is false : clear screen and write variable char, then old_char = char and then go to 1)
- 3 is true : go to 1)

Rgds,

Nicolas Lopez F.

User avatar
Benj
Matrix Staff
Posts: 14567
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4598 times
Been thanked: 4239 times
Contact:

Re: RS232 to USB Converter

Postby Benj » Tue Dec 14, 2010 2:38 pm

Hello Nicolas,

Great you got it to work correctly. Have you wired up your own LCD or are you using an E-block? Could it be that you have left the contrast in of the LCD floating. Eg not connected a 10K pot between GND and 5V with the center tap going to the contast pin, pin3 of the LCD.

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: RS232 to USB Converter

Postby Spanish_dude » Tue Dec 14, 2010 3:04 pm

I'm using the LCD E-Block so the contrast is connected to a pot.

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: RS232 to USB Converter

Postby Spanish_dude » Wed Dec 15, 2010 3:43 pm

I think I found a bug in flowcode.

When I read two bytes from the RS232 comp and then compare them to something ex:

Code: Select all

char byte[2] = {0};

// read 2 bytes from RS232

if (byte[0] == 'W' && byte[1] == 'D')
    //do something
else
    //print error


I get a syntax error when doing that if statement and also when doing that in a while loop.
I tried "AND" instead of "&&" but it's the same result.

EDIT : Also when I manage to write an if statement with "&&" or "AND" the result is always false.

To be able to simulate the program I need to use multiple if statements.

Almost forgot,

I tried to use the Compare$() function but flowcode tells me there's a syntax error.
I'm using it like this:

Code: Select all

char retval = 0;
char cmd[3] = {0};

// read 2 bytes from RS232

retval = Compare$(byte, "WD", 1);


I don't see any error there.

Rgds,

Nicolas L. F.

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: RS232 to USB Converter

Postby Spanish_dude » Sat Dec 18, 2010 1:09 pm

Any ideas ? :roll:

User avatar
Benj
Matrix Staff
Posts: 14567
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4598 times
Been thanked: 4239 times
Contact:

Re: RS232 to USB Converter

Postby Benj » Tue Dec 21, 2010 3:42 pm

Hello,

Flowcode requires that you enter a string as the parameter rather then a byte. You could create a string variable of 1 element in the variable manager and then use a calculation to copy the byte variable into the string variable.

string[0] = byte

I'll have a look into the ANDed statements in an IF icon and see if I can replicate your findings.

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: RS232 to USB Converter

Postby Spanish_dude » Mon Dec 27, 2010 11:35 am

Hi,

I just tried my program with another LCD E-Block and it works without that contrast problem...
The other LCD E-Block won't work anymore, don't know why :|

Rgds,

Nicolas L. F.