PC controlled RS232 relay board

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
ossir
Posts: 27
Joined: Tue Oct 08, 2013 7:14 pm
Has thanked: 1 time
Been thanked: 1 time

PC controlled RS232 relay board

Post 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?
Attachments
rs232.fcf
(9 KiB) Downloaded 337 times

User avatar
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: PC controlled RS232 relay board

Post 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.

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: PC controlled RS232 relay board

Post 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
Attachments
rs232 V1.1.fcf
(15.84 KiB) Downloaded 342 times
Martin

ossir
Posts: 27
Joined: Tue Oct 08, 2013 7:14 pm
Has thanked: 1 time
Been thanked: 1 time

Re: PC controlled RS232 relay board

Post 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.

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: PC controlled RS232 relay board

Post 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
Martin

ossir
Posts: 27
Joined: Tue Oct 08, 2013 7:14 pm
Has thanked: 1 time
Been thanked: 1 time

Re: PC controlled RS232 relay board

Post by ossir »

Yes i have 5V, i connect it directly my pc motherboard COM port and try again.

ossir
Posts: 27
Joined: Tue Oct 08, 2013 7:14 pm
Has thanked: 1 time
Been thanked: 1 time

Re: PC controlled RS232 relay board

Post 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

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times

Re: PC controlled RS232 relay board

Post 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

ossir
Posts: 27
Joined: Tue Oct 08, 2013 7:14 pm
Has thanked: 1 time
Been thanked: 1 time

Re: PC controlled RS232 relay board

Post 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 :)

Post Reply