RS232 to USB Converter
-
- Posts: 594
- Joined: Thu Sep 17, 2009 7:52 am
- Location: Belgium
- Has thanked: 63 times
- Been thanked: 102 times
RS232 to USB Converter
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...
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 532 times
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: RS232 to USB Converter
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: RS232 to USB Converter
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 594
- Joined: Thu Sep 17, 2009 7:52 am
- Location: Belgium
- Has thanked: 63 times
- Been thanked: 102 times
Re: RS232 to USB Converter
I have 3 or 4 MAX232 so that won't be a problem, but I'm definitely going to try that "hack" ASAP.
-
- Posts: 594
- Joined: Thu Sep 17, 2009 7:52 am
- Location: Belgium
- Has thanked: 63 times
- Been thanked: 102 times
Re: RS232 to USB Converter
Yes ,
I got it to work
!
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.
I got it to work

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.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: RS232 to USB Converter
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 594
- Joined: Thu Sep 17, 2009 7:52 am
- Location: Belgium
- Has thanked: 63 times
- Been thanked: 102 times
-
- Posts: 594
- Joined: Thu Sep 17, 2009 7:52 am
- Location: Belgium
- Has thanked: 63 times
- Been thanked: 102 times
Re: RS232 to USB Converter
I think I found a bug in flowcode.
When I read two bytes from the RS232 comp and then compare them to something ex:
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:
I don't see any error there.
Rgds,
Nicolas L. F.
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 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);
Rgds,
Nicolas L. F.
-
- Posts: 594
- Joined: Thu Sep 17, 2009 7:52 am
- Location: Belgium
- Has thanked: 63 times
- Been thanked: 102 times
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: RS232 to USB Converter
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 594
- Joined: Thu Sep 17, 2009 7:52 am
- Location: Belgium
- Has thanked: 63 times
- Been thanked: 102 times
Re: RS232 to USB Converter
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.
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.