Page 1 of 1
RS232 to USB Converter
Posted: Fri Dec 10, 2010 4:08 pm
by Spanish_dude
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...
Re: RS232 to USB Converter
Posted: Sat Dec 11, 2010 12:48 pm
by Benj
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.
Re: RS232 to USB Converter
Posted: Sat Dec 11, 2010 12:51 pm
by Benj
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.
Re: RS232 to USB Converter
Posted: Sun Dec 12, 2010 4:00 pm
by Spanish_dude
I have 3 or 4 MAX232 so that won't be a problem, but I'm definitely going to try that "hack" ASAP.
Re: RS232 to USB Converter
Posted: Mon Dec 13, 2010 7:44 pm
by Spanish_dude
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.
Re: RS232 to USB Converter
Posted: Tue Dec 14, 2010 2:38 pm
by Benj
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.
Re: RS232 to USB Converter
Posted: Tue Dec 14, 2010 3:04 pm
by Spanish_dude
I'm using the LCD E-Block so the contrast is connected to a pot.
Re: RS232 to USB Converter
Posted: Wed Dec 15, 2010 3:43 pm
by Spanish_dude
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.
Re: RS232 to USB Converter
Posted: Sat Dec 18, 2010 1:09 pm
by Spanish_dude
Any ideas ?
Re: RS232 to USB Converter
Posted: Tue Dec 21, 2010 3:42 pm
by Benj
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.
Re: RS232 to USB Converter
Posted: Mon Dec 27, 2010 11:35 am
by Spanish_dude
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.