Page 1 of 1

PC controlled RS232 relay board

Posted: Thu Jul 10, 2014 4:06 pm
by ossir
Hello

I'm making relay board which can be controlled by pc with RS232.

My plan is:

- Board has 4-8 channel
- I make software which can send letter "A" to MCU to control relays.
- In the MCU code will compare that, if received letter is "A", then B0 go high
or if received letter is "B", then B0 go low.

My problem now is that MCU can't receive those leters. I try to made test code that will prints received letters to LCD.
Usually it prints nothing or something random marks or letters.

- MCU is 16f887 with external 4Mhz crystal.
- I use CP2102 Module USB to USART(UART) 3.3V TTL USB To COM ----> MAX232 --->MCU, TX and RX pins
- I use Arduino serial monitor tool to send letters to COM port.
- I scoped MCU RX pin and it get pulses when i send something with arduino monitor tool.

I attached my test code.

Can some one please help me with this receive problem?

Re: PC controlled RS232 relay board

Posted: Thu Jul 10, 2014 4:37 pm
by Benj
Hello,

Try this, I have modified your file slightly so it is hopefully easier to see whats going on.

I also set the RS232 component to use the hardware UART which is on pins C6 and C7.
rs232.fcf
(10.5 KiB) Downloaded 319 times
Let me know how you get on.

Edit: Just noticed that i'm toggling portB 0 but this is also used for the LCD component, just so you are aware there is a clash.

Re: PC controlled RS232 relay board

Posted: Thu Jul 10, 2014 4:59 pm
by medelec35
Hi ossir,
Here is my version,
I was modifying flowchart, while Ben was posting.
So rather than delete it, I thought I would still share it.
I have use a slightly different method so you get the choice.
RS232 interrupt has been enabled so you will need to use RC7 (Pin 26)
RX Interrupt will not simulate in flowcode, therefore when simulation is required, a call macro must be enabled.
Before compiling to target, RX Interrupt must be disabled or hardware will not work as intended.
I have also modified flowchart to allow Letters from A to Z to have control.
Only one switch component will only allow 10 letters.
So for anymore than 10 you will need to add additional switch components.


I did notice a conflict on your Flowchart.
You wanted B0 to change but you have also used B0 for LCD.
To avoid corruption of characters on LCD, I have changed LCD from PortB to portC

Edit: Looks like Ben has noticed too.

Martin

Re: PC controlled RS232 relay board

Posted: Thu Jul 10, 2014 8:36 pm
by ossir
Benj wrote:Hello,

Try this, I have modified your file slightly so it is hopefully easier to see whats going on.

I also set the RS232 component to use the hardware UART which is on pins C6 and C7.
rs232.fcf
Let me know how you get on.

Edit: Just noticed that i'm toggling portB 0 but this is also used for the LCD component, just so you are aware there is a clash.
Code works in simulation, but not in my circuit.
I changed output to D0 and added led, still it is not printing letters and led is off.

medelec35 wrote:Hi ossir,
Here is my version,
I was modifying flowchart, while Ben was posting.
So rather than delete it, I thought I would still share it.
I have use a slightly different method so you get the choice.
RS232 interrupt has been enabled so you will need to use RC7 (Pin 26)
RX Interrupt will not simulate in flowcode, therefore when simulation is required, a call macro must be enabled.
Before compiling to target, RX Interrupt must be disabled or hardware will not work as intended.
I have also modified flowchart to allow Letters from A to Z to have control.
Only one switch component will only allow 10 letters.
So for anymore than 10 you will need to add additional switch components.


I did notice a conflict on your Flowchart.
You wanted B0 to change but you have also used B0 for LCD.
To avoid corruption of characters on LCD, I have changed LCD from PortB to portC

Edit: Looks like Ben has noticed too.

Martin
I changed output to D0 and added led.
Code works in simulation but not in my circuit, it is not printing even "test", only shows 16 x bar.

Re: PC controlled RS232 relay board

Posted: Thu Jul 10, 2014 9:01 pm
by medelec35
Hi ossir,
ossir wrote:Code works in simulation but not in my circuit, it is not printing even "test", only shows 16 x bar.
Did you take into account:
medelec35 wrote:To avoid corruption of characters on LCD, I have changed LCD from PortB to portC
Since you have changed B0 to D0, you can change port of LCD back to portB?

I have tested both Ben's and my flowchart on hardware and I can confirm both work as expected.
After pressing A PORT D0 went high.
After pressing B PORT D0 went low.
If your hardware does not do the same then you do have an hardware issue.

One other thing I have noticed is:
ossir wrote: - I use CP2102 Module USB to USART(UART) 3.3V TTL USB To COM ----> MAX232 --->MCU, TX and RX pins
What is voltage have you connected microntroller to?
If it's a 5V supply then I suspect your USB to USART won't last to long?

Martin

Re: PC controlled RS232 relay board

Posted: Fri Jul 11, 2014 9:25 am
by ossir
Yes i have 5V, i connect it directly my pc motherboard COM port and try again.

Re: PC controlled RS232 relay board

Posted: Fri Jul 11, 2014 10:42 am
by ossir
I tested Ben's flowchart with motherboard COM port and still i do not get letter to LCD.

MAX232 pin R1OUT voltage level is 3V, so should it be about 5V?

Here is my schematic.
Image

Re: PC controlled RS232 relay board

Posted: Fri Jul 11, 2014 12:05 pm
by LeighM
looking at the MAX232 datasheet, R1OUT can drop to 3.5V with a 3k load (~1mA)
you might need to check the value of your R1
the MAX232 can sink more current, 3mA, so you might be better connecting the LED to 5v rather than 0v. Also that way the LED will flash on when you receive data

Re: PC controlled RS232 relay board

Posted: Fri Jul 11, 2014 1:48 pm
by ossir
LeighM wrote:looking at the MAX232 datasheet, R1OUT can drop to 3.5V with a 3k load (~1mA)
you might need to check the value of your R1
the MAX232 can sink more current, 3mA, so you might be better connecting the LED to 5v rather than 0v. Also that way the LED will flash on when you receive data
I removed led resitor temporarily and then it started to work :)