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?
PC controlled RS232 relay board
- 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
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.
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.
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.
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.
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
-
- 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
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
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
Re: PC controlled RS232 relay board
Code works in simulation, but not in my circuit.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.
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.
I changed output to D0 and added led, still it is not printing letters and led is off.
I changed output to D0 and added led.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
Code works in simulation but not in my circuit, it is not printing even "test", only shows 16 x bar.
-
- 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
Hi ossir,
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:
If it's a 5V supply then I suspect your USB to USART won't last to long?
Martin
Did you take into account:ossir wrote:Code works in simulation but not in my circuit, it is not printing even "test", only shows 16 x bar.
Since you have changed B0 to D0, you can change port of LCD back to portB?medelec35 wrote:To avoid corruption of characters on LCD, I have changed LCD from PortB to portC
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:
What is voltage have you connected microntroller to?ossir wrote: - I use CP2102 Module USB to USART(UART) 3.3V TTL USB To COM ----> MAX232 --->MCU, TX and RX pins
If it's a 5V supply then I suspect your USB to USART won't last to long?
Martin
Martin
Re: PC controlled RS232 relay board
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.

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

- 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
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
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
I removed led resitor temporarily and then it started to workLeighM 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
