RS-485

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Mikat
Posts: 258
Joined: Wed Nov 29, 2006 6:32 pm
Location: Finland
Has thanked: 7 times
Been thanked: 36 times

RS-485

Post by Mikat »

Hi.
I was wondering is there any plans to make rs-485 communication on Flowcode 4?
If i am right,the rs-485 comm allows multiple devices on same 2 wire bus,so then building the network with pic and using just pic hardware is possible..
Correct if i am wrong,but the existing rs-232 component cant be use more than 2 pics communication because the tx pin is driven hi (or was it lo), so any other device connected on same bus and pin cant send anything because the pin is already driven...
What i like to have is the simplest network,where you can connect multiple devices,and get them communicate together,with no extra hardware..
<or is there change to get that tx pin float when the eusart module is active (the rx interrupt is active), then the pin can be driven by weak pu or pd resistor , witch allows the pin being driven by multiple devices..

Mika

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: RS-485

Post by Benj »

Hello Mikat

No current plans to do this but I agree it would be useful to have a bus that could control multiple in circuit devices. The I2C and SPI slave components would also come in handy. I will see if I get some time and try generating some basic custom beta versions of these components.

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times

Re: RS-485

Post by Sean »

We have implemented 9-bit data mode for the RS232 in Flowcode V4. This will allow the RS232 component to be used for RS485 comms simply by adding a suitable transceiver (ie SN75176) to the uart connections.

The transceiver enable/direction pins can be controlled by a single I/O line, managed by the Flowcode program, to enable RS485 transmission mode only when data is being sent. The transceiver will be in receive mode at all other times, with its bus driver outputs tri-stated.

9-bit data allows RS485 addressing to be used:
If the most siginificant bit is set, the remaining 8 bits are a node address.
If the most siginificant bit is clear, the remaining 8 bits are data.

Mikat
Posts: 258
Joined: Wed Nov 29, 2006 6:32 pm
Location: Finland
Has thanked: 7 times
Been thanked: 36 times

Re: RS-485

Post by Mikat »

Ben that would be REALLY nice,because i had multiple pic:s witch i like to put on same network,but the pcb:s are already made,and have only eusart rx and tx connections,so that makes Sean idea a bit difficult. And one pcb is so full components that putting the extra chip is impossible,that is the biggest problem,the pcb is inside eber d5w heater so the space is very limited..

Mika

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: RS-485

Post by Benj »

Hello Mika

OK here is some code I used to create a master / slave type setup between 3 16F870 PICmicros.

The master Tx pin must be connected to the slave Rx pins and visa versa.

The slave devices can also only write to the bus when the master is trying to receive data.

You should be able to put the functions into the supplementary code window and then use C code icons in your flowchart to call the functions.

Defines section

void synch_master_tx_mode (unsigned int send);
unsigned int synch_master_rx_mode (void);
void synch_slave_tx_mode (unsigned int send);
unsigned int synch_slave_rx_mode (void);

Code section

void synch_master_tx_mode (unsigned int send)
{
spbrg = 10; //Set Baud Rate
txsta.BRGH = 1; //Set High Speed Baud
txsta.SYNC = 1; //Set Synchronous Mode
rcsta.SPEN = 1; //Serial Port Enable
txsta.CSRC = 1; //Master Mode
txsta.TX9 = 1; //9 Bit Transmission
txsta.TXEN = 1; //Enable Transmission
txsta.TX9D = send >> 8; //Load 9th Data Bit
txreg = send; //Load 8 other bits
}

unsigned int synch_master_rx_mode (void)
{
unsigned int temp;
spbrg = 10; //Set Baud Rate
txsta.BRGH = 1; //Set High Speed Baud
txsta.SYNC = 1; //Set Synchronous Mode
rcsta.SPEN = 1; //Serial Port Enable
txsta.CSRC = 1; //Master Mode
rcsta.CREN = 0; //Disable continous Reception
rcsta.SREN = 0; //Disable Single Reception
rcsta.SREN = 1; //Enable single reception
temp = rcreg; //Read 8 other bits of reception
return (temp);
}

void synch_slave_tx_mode (unsigned int send)
{
txsta.SYNC = 1; //Set Synchronous Mode
rcsta.SPEN = 1; //Serial Port Enable
txsta.CSRC = 0; //Slave Mode
rcsta.CREN = 0; //Disable Reception
rcsta.SREN = 0; //??????????
txsta.TXEN = 1; //Enable Transmission
txreg = send; //Load 8 other bits
}

unsigned int synch_slave_rx_mode (void)
{
unsigned int temp;
txsta.SYNC = 1; //Set Synchronous Mode
rcsta.SPEN = 1; //Serial Port Enable
txsta.CSRC = 0; //Slave Mode
rcsta.CREN = 1; //Enable reception
temp = rcreg; //Read 8 other bits of reception
return (temp);
}

If you then create an int variable in Flowcode called data then the following example code will work to send or receive 9 bit data packets and place the data from or into the data variable.

Example Master Send
synch_master_tx_mode (FCV_DATA);

Example Master Receive
FCV_DATA = synch_master_rx_mode ();

Example Slave Send
synch_slave_tx_mode (FCV_DATA);

Example Slave Receive
FCV_DATA = synch_slave_rx_mode ();

In my application i used the 9th bit to be the address bit. When this was set the master was changing the device it was talking to. The other 8 bits corresponded to a device address and when a device received its address it switched to the active device. All other devices went back to sleep. Addresses were just assigned by creating byte variables containing a unique number and comparing this to the incoming data. When the 9th bit is not set I was just sending and receiving data from the enabled device. This was just my implementation though don't feel you have to follow this.

fresh
Posts: 47
Joined: Mon Jun 08, 2009 11:11 am

Re: RS-485

Post by fresh »

Hello Benj,
that's nice.
It is also feasible to create your example only in Flowcode without the c code icons?

regards Andreas

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: RS-485

Post by Benj »

Hello

Yes it is possible by using a custom component. There is a guide to creating these available from here.

http://www.matrixmultimedia.com/softwar ... owcode.pdf

fresh
Posts: 47
Joined: Mon Jun 08, 2009 11:11 am

Re: RS-485

Post by fresh »

Hello Benj,

thank you for the download Link.

Post Reply