Flowcode V3 RS232 Component -> RS485 UPDATED

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Flowcode V3 RS232 Component -> RS485 UPDATED

Postby Ron » Sun Mar 06, 2011 5:00 pm

Hello,

EDIT NOTE: Much of the original post is gone since I have figured out some of my questions myself.

I want to communicate between multiple PIC's via RS485. I am hoping I can do this by using the RS232 component in Flowcode V3. I have attached a schematic that makes sense to me. I have a situation with my requirements.

1) I use RS232 to download my program to the PIC (via bootloader) so I have a MAX232 on board.
2) I also want to use RS485 but the PIC only has 1 serial port on it. I think I will use SN65LBC184PE4 for RS485 driver (128 nodes, good ESD protection).

I will add the following to the circuit:

LED's for RX and TX
.1uF cap between +V and GND
Possibly need DPDT switch, see questions later in post.
On board terminating resistor with 1x3 header/jumper to enable/disable.

I want to be able to use both the RS232 AND RS485 but not at the same time, (RS232 to download program to MCU, RS485 when program is running on MCU).

I will add a daughter board that plugs into my main MCU board.

The Slaves may or may not be powered from the same power supply as the Master.

I want to use 2 RJ45 connectors on the daughter board for RS485 field connections.

I will use (2-3) 1x3 headers/sockets to connect my daughter board to the main board. I have RX/TX/GND/+5V/Enable/extra pin

Questions I need help with please.

1) Is it as simple as using the Flowcode V3 RS232 component to drive the RS485 driver plus an output to control RE & DE?

2) Can both the Max232 and the RS485 driver be connected to RX & TX in parallel and function normally? OR Do I need to put a DPDT switch in line with RX & TX to switch between the Max232 and RD485 driver?

3) If the Slaves use a different power supply than the Master, do I need to tie the grounds of the slaves to the Master? I really do not want to do this but could as the Ethernet cables I want to use has 4 conductors (2 for COMM, 2 for Ground). Is there an Isolator i can use to avoid connecting the grounds if it is necessary?



Thank you for your time, it is greatly appreciated.

Ron
Attachments
485 Driver.jpg
Simple PIC to RS485 driver circuit I found on web.
485 Driver.jpg (10.51 KiB) Viewed 3425 times
Ron
 
Posts: 225
Joined: Wed Apr 11, 2007 6:15 pm
Has thanked: 2 times
Have thanks: 0 time

Advertisement

Re: Flowcode V3 RS232 Component -> RS485 UPDATED

Postby Benj » Mon Mar 07, 2011 11:33 am

Hello Ron,

1) Is it as simple as using the Flowcode V3 RS232 component to drive the RS485 driver plus an output to control RE & DE?


Yes it should be this simple. :mrgreen:

2) Can both the Max232 and the RS485 driver be connected to RX & TX in parallel and function normally? OR Do I need to put a DPDT switch in line with RX & TX to switch between the Max232 and RD485 driver?


I would add the switch otherwise the two receive lines would always be fighting each other for control. Switch guarantees that there wont be a problem down the line with programming or your RS485 comms.

3) If the Slaves use a different power supply than the Master, do I need to tie the grounds of the slaves to the Master? I really do not want to do this but could as the Ethernet cables I want to use has 4 conductors (2 for COMM, 2 for Ground). Is there an Isolator i can use to avoid connecting the grounds if it is necessary?


Yes I think you will need to connect the ground power rail between the RS485 nodes. If you have spare connections in your cable then you might as well use them and the ground may help to act as an extra bit of shielding from surrounding noise.
Regards Ben Rowland - Matrix Multimedia Ltd
For access to the Flowcode v4 forum topic - Click here
For access to the Flowcode v5 forum topic - Click here
User avatar
Benj
Matrix Staff
 
Posts: 7909
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix Multimedia Ltd
Has thanked: 1014 times
Have thanks: 1336 times

Re: Flowcode V3 RS232 Component -> RS485 UPDATED

Postby Ron » Wed Mar 09, 2011 12:45 am

Hi Ben,

Thank you for your help.

Can you tell me if Flowcode generates a "start" bit. I have found a hardware solution to driving the RS485 drivers RE/DE pin. It is actually very neat. The driver is enabled on the leading edge of the "start" bit and is disabled a few micro seconds after it sees the leading edge of the stop bit. This helps cut down on timing issues with slaves on the network.

If Flowcode does not generate a "start" bit is there any way I can do it manually?

Off topic, is there any RS2323 to Ethernet chips out there?

Thank you,

Ron
Ron
 
Posts: 225
Joined: Wed Apr 11, 2007 6:15 pm
Has thanked: 2 times
Have thanks: 0 time

Re: Flowcode V3 RS232 Component -> RS485 UPDATED

Postby Benj » Wed Mar 09, 2011 10:45 am

Hello Ron,

Yes the RS232 component automatically produces the start bit and the stop bit when sending out data.

We use a Wiznet module (IIM7010A) that is basically SPI to Enthernet and this works with the Flowcode TCP and Webserver components.

I also found this article by searching google for ethernet uart.
http://www.maxim-ic.com/app-notes/index.mvp/id/704
Regards Ben Rowland - Matrix Multimedia Ltd
For access to the Flowcode v4 forum topic - Click here
For access to the Flowcode v5 forum topic - Click here
User avatar
Benj
Matrix Staff
 
Posts: 7909
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix Multimedia Ltd
Has thanked: 1014 times
Have thanks: 1336 times

Re: Flowcode V3 RS232 Component -> RS485 UPDATED

Postby Ron » Wed Mar 09, 2011 4:54 pm

Hello Ben,

Another question regarding the RS232 component. I have been speaking with people about the hardware method of dropping the enable bit on the RS485 driver via 555 timer and they do not like it. They say that more often than not the issue is not that the slave begins transmitting/responding to soon (which is why you want to drop the enable on the leading edge of the stop bit), but rather the enable bit on the Master is dropped before the last byte is "fully" sent from the TX buffer. They say that depending on the buffer size in the MCU this can be a problem and that I should monitor the PIC to see when the TX buffer is empty before dropping the RS485 enable (via pic output pin).

They like controlling the enable bit from a pin on the MCU.

Question 1 - Have you guys ever used the hardware method of controlling the RS485 enable bit with the Flowcode RS232 component (or do you tie the enable to a pin on the MCU)?

Question 2 - How does the RS232 component work? Does it monitor the TX buffer and wait for it to be empty before leaving the component?

Question 3 - There will be an RS232 % error on both of the PICs that will be communicating. Each will be less than .7%. Is this an issue (.69% and .2% I think) across the RS485 drivers? My packets are no larger than 8 bytes long.

I am going to order a PCB and they are expensive so I do not want to go down the wrong path if I can help it.

Thank you,

Ron
Ron
 
Posts: 225
Joined: Wed Apr 11, 2007 6:15 pm
Has thanked: 2 times
Have thanks: 0 time

Re: Flowcode V3 RS232 Component -> RS485 UPDATED

Postby Benj » Fri Mar 11, 2011 5:54 pm

Hello Ron,

In answer to your questions.

1) You could use a standard I/O pin and handle this yourself before and after sending data. Alternaitvly you could customise the RS232 send function so that it automatically handles the enable output for you.

2) The send Byte RS232 macro checks that nothing is in the outgoing buffer and then sends the byte. Once the byte has been passed to the peripheral the function returns. If you need the function to wait until the byte is sent out then you could add the following to the end of the send byte macro using the code customisation feature.

while (ts_bit(txsta, TRMT) == 0); //While TSR Full

3) Errors that small should be negligible and you should not have any problems.

I agree, PCBs are expensive, im on the 3rd revision of some of my custom boards. Very annoying when you make a mistake.
Regards Ben Rowland - Matrix Multimedia Ltd
For access to the Flowcode v4 forum topic - Click here
For access to the Flowcode v5 forum topic - Click here
User avatar
Benj
Matrix Staff
 
Posts: 7909
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix Multimedia Ltd
Has thanked: 1014 times
Have thanks: 1336 times

Re: Flowcode V3 RS232 Component -> RS485 UPDATED

Postby Ron » Sat Mar 12, 2011 4:15 am

Hi Ben,

Thanks for your help.

Regarding your answers (I am using V3 of Flowcode).

1) Do you mean hard code my control of the enable/disable RS485 driver output within the "RS232 Send Function"? How is this done?

2) Is this code customization available in V3? If it is, where do I find it and how would I do it? If it is available, I would want to do "answer 1", set RS485 driver to TX and when the packet is sent and the buffer is empty change the RS485 driver back to RX. The reason I am trying to figure this out as I expect that timing issues can occur and I do not want to disable the TX mode of the RS485 driver to soon. Some of the new PICS have up to 4 words RX and TX buffers now. If/when Flowcode supports these newer PICs I will need to upgrade to Vx.

I am very excited, love the article on RS485, I however cannot load the examples into V3, I would like to see how Sean did it.


Can Flowcode 4 open/modify Flowcode 3 projects without any issues? I realize that if I modify the project with V4 that V3 may not be able to open it anymore.
Can V4 and V3 reside on the same PC without any issues?


Thank you very much!

Ron
Ron
 
Posts: 225
Joined: Wed Apr 11, 2007 6:15 pm
Has thanked: 2 times
Have thanks: 0 time

Re: Flowcode V3 RS232 Component -> RS485 UPDATED

Postby Benj » Mon Mar 14, 2011 2:31 pm

Hi Ron.

1) Yes you can do this by opening the RS232 Component C file from the components directory and editing the macro. If you do this then remember to ensure the tris is setup correctly to allow for the output.

2) Code customization is a v4 feature only.

3) V4 can open v3 projects without any issues just dont save the file from v4 and you will be ok to open in either version.

4) Flowcode versions 3 and 4 can happily work together on the same machine.
Regards Ben Rowland - Matrix Multimedia Ltd
For access to the Flowcode v4 forum topic - Click here
For access to the Flowcode v5 forum topic - Click here
User avatar
Benj
Matrix Staff
 
Posts: 7909
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix Multimedia Ltd
Has thanked: 1014 times
Have thanks: 1336 times

Re: Flowcode V3 RS232 Component -> RS485 UPDATED

Postby Ron » Mon Mar 14, 2011 4:06 pm

Hi Ben,

Thanks again for the help.

1) Due to my very limited ability with "C" I am just going to turn on/off the output like normal to change modes.

2) Can I put this line of code in a V3 "C" block to wait before disabling the TX?

while (ts_bit(txsta, TRMT) == 0); //While TSR Full

Please confirm the required sequence.

A) Turn ON the TX Enable - RX disable output (NOT RE & DE tied together both to a single PIC pin).

B) Send my packet via RS232 component (loop for many bytes).

C) After the last byte is gone have "C" block with the line of code above.

D) Turn off the TX enable output once TRMT <> 0.

3) If I open my V3 project in V4 can I simply save it and it will now compile in V4 and run on my PIC without issue? Or do I need to go through and set up clock speed, rs232 component again etc......

Thank you,

Ron
Ron
 
Posts: 225
Joined: Wed Apr 11, 2007 6:15 pm
Has thanked: 2 times
Have thanks: 0 time

Re: Flowcode V3 RS232 Component -> RS485 UPDATED

Postby Ron » Thu Apr 21, 2011 1:02 am

Hi,

I am very confused regarding RS485 circuits connecting to PIC 16F/18F.

I find 2 basic circuits regarding BIAS resistors typically found at the Master.

Many online:
Pin 6 is tied to +5V
Pin 7 is tied to GND

Matrix MM Board:
Pin 6 is tied to GND
Pin 7 is tied to +5V

I want to experiment with SN75176 and MAX3085.

Which way is correct or can it be done either way (why)?

Thank you,

Ron
Ron
 
Posts: 225
Joined: Wed Apr 11, 2007 6:15 pm
Has thanked: 2 times
Have thanks: 0 time

Re: Flowcode V3 RS232 Component -> RS485 UPDATED

Postby Sean » Thu Apr 21, 2011 1:25 pm

Bias is not used as frequently as termination, but can be used to impose a logic state if the bus lines are not being driven (all network transmitters disabled). The bias state requirement can depend on the application.

If the normal J5 and J15 jumpers are connected to enable bias (connecting pins 1-2, 5-6), the bias will cause all receivers to read a zero state when nothing is transmitting. In UART based applications this could cause the false detection of a start bit. To force a logic 1 bias, the jumper would need to be cross-connected (connect pins 1-5, 2-6).
User avatar
Sean
Flowcode V4 User
 
Posts: 542
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 5 times
Have thanks: 33 times

Re: Flowcode V3 RS232 Component -> RS485 UPDATED

Postby Ron » Thu Apr 21, 2011 5:08 pm

Hello Sean,

Thank you, that helps a great deal :).

Ron
Ron
 
Posts: 225
Joined: Wed Apr 11, 2007 6:15 pm
Has thanked: 2 times
Have thanks: 0 time

Re: Flowcode V3 RS232 Component -> RS485 UPDATED

Postby Ron » Fri May 20, 2011 4:12 am

Hi,

I had asked earlier in this post how to determine if a byte is still in the TX buffer.

Ben provided this line of code.

while (ts_bit(txsta, TRMT) == 0);

Flowcode V3 gives me this error when I compile it, any ideas on how to correct this error?

:\Back Up Items\Step By Step\Flowcode Projects\18F 5 SEQ PAUSE REV 11 BETA\184620 5 Seq PAUSE REV 11 BETA.c(27649:9): error: unknown identifier 'ts_bit'
E:\Back Up Items\Step By Step\Flowcode Projects\18F 5 SEQ PAUSE REV 11 BETA\184620 5 Seq PAUSE REV 11 BETA.c(27649:9): error: failed to generate expression
E:\Back Up Items\Step By Step\Flowcode Projects\18F 5 SEQ PAUSE REV 11 BETA\184620 5 Seq PAUSE REV 11 BETA.c(27649:9): error: invalid operand 'ts_bit(txsta, 0x00000001) '
E:\Back Up Items\Step By Step\Flowcode Projects\18F 5 SEQ PAUSE REV 11 BETA\184620 5 Seq PAUSE REV 11 BETA.c(27649:35): error: failed to generate expression
E:\Back Up Items\Step By Step\Flowcode Projects\18F 5 SEQ PAUSE REV 11 BETA\184620 5 Seq PAUSE REV 11 BETA.c(27649:35): internal error: failed to generate 'while' expression
E:\Back Up Items\Step By Step\Flowcode Projects\18F 5 SEQ PAUSE REV 11 BETA\184620 5 Seq PAUSE REV 11 BETA.c(27649:2): error: error in 'while' loop statement

Thank you,

Ron
Ron
 
Posts: 225
Joined: Wed Apr 11, 2007 6:15 pm
Has thanked: 2 times
Have thanks: 0 time

Re: Flowcode V3 RS232 Component -> RS485 UPDATED

Postby Benj » Fri May 20, 2011 9:58 am

Hello Ron,

Sorry ts_bit is a v4 command.

change this to test_bit().

So the command becomes.

while (test_bit(txsta, TRMT) == 0);
Regards Ben Rowland - Matrix Multimedia Ltd
For access to the Flowcode v4 forum topic - Click here
For access to the Flowcode v5 forum topic - Click here
User avatar
Benj
Matrix Staff
 
Posts: 7909
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix Multimedia Ltd
Has thanked: 1014 times
Have thanks: 1336 times


Return to Flowcode V2 & V3

Who is online

Users browsing this forum: No registered users and 1 guest