Flowcode y RS485

Foro para hablantes de español que deseen escribir en su lengua materna.

Moderator: Benj

Post Reply
Fer_taca
Posts: 91
Joined: Fri Oct 27, 2017 9:50 am
Has thanked: 13 times
Been thanked: 10 times
Contact:

Flowcode y RS485

Post by Fer_taca »

Quisiera empezar a probar las comunicaciones con el protocolo RS485.
Dentro de Flowcode no veo ningún componente especifico para este tipo de comunicaciones.
Veo en la ayuda que para poder utilizar este tipo de comunicaciones se puede utilizar el componente RS232 seguido de un driver del tipo MAX3078. ¿Esto es lo correcto y se pueden utilizar las mismas macros que para las comunicaciones RS232?

Muchas gracias de antemano por la aclaración.

F.

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

Re: Flowcode y RS485

Post by LeighM »

Yes, you can use the UART (RS232) component,
but you will need to drive the RE/DE control with another port/pin

Fer_taca
Posts: 91
Joined: Fri Oct 27, 2017 9:50 am
Has thanked: 13 times
Been thanked: 10 times
Contact:

Re: Flowcode y RS485

Post by Fer_taca »

LeighM wrote:Yes, you can use the UART (RS232) component,
but you will need to drive the RE/DE control with another port/pin
Gracias, por la respuesta.
Me podía indicar un pequeño ejemplo de forma básica como se realizaría ese control.

F.

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

Re: Flowcode y RS485

Post by LeighM »

The usual way to do this is to connect RE and DE together into one port pin.
Keep that pin low to receive data on the bus, then when you need to transmit data turn the pin high, transmit that data, then wait a while and take the pin low again ready to receive. The wait is to give the last transmitted byte time to leave the UART shift register.

Fer_taca
Posts: 91
Joined: Fri Oct 27, 2017 9:50 am
Has thanked: 13 times
Been thanked: 10 times
Contact:

Re: Flowcode y RS485

Post by Fer_taca »

Gracias de nuevo LeighM, por su amable respuesta.
Revisando los ejemplos d la Wiki, he realizado y adjunto un par de ficheros de como pienso que básicamente es la forma de realizar la transmisión y recepción.
La conexión sería punto a punto (un máster se comunica con un solo esclavo y al revés)
Seguro que tengo algo mal. Tendría inconveniente en indicarmelo
Muchas gracias de antemano.

F.
Attachments
RS485_Rx_01.fcfx
(11.21 KiB) Downloaded 257 times
RS485_Tx_01.fcfx
(10.91 KiB) Downloaded 244 times

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

Re: Flowcode y RS485

Post by LeighM »

Attached is a modified Rx, to show you how to receive the values.
It is best to avoid delays on receive otherwise you can miss received characters.
Also, on both programs, you need to disable flow control.
flow_off.jpg
flow_off.jpg (22.26 KiB) Viewed 11276 times
In your transmit program you read both values from Port A, is that intended?
You need to use an output icon to control your RE/DE pins.
If you are sending more than one value byte/character, you will need to send a "start" code to synchronise the receiver with the transmitter.
Attachments
RS485_Tx_01.fcfx
(10.66 KiB) Downloaded 241 times
RS485_Rx_01.fcfx
(10.15 KiB) Downloaded 252 times

Fer_taca
Posts: 91
Joined: Fri Oct 27, 2017 9:50 am
Has thanked: 13 times
Been thanked: 10 times
Contact:

Re: Flowcode y RS485

Post by Fer_taca »

Una vez más gracias LeighM,

Acabo de descargar lo que me ha adjunto y revisarlo con detenimiento.
Si me surge cualquier duda ya consultaré de nuevo.

F.

Fer_taca
Posts: 91
Joined: Fri Oct 27, 2017 9:50 am
Has thanked: 13 times
Been thanked: 10 times
Contact:

Re: Flowcode y RS485

Post by Fer_taca »

Respecto al transmisor:
Es cierto que se me olvido el activar el pin RE/DE y con respecto al envío de los valores del puerto A, según estaba en mi fichero solo era por practicar cierto que debería de enviar los 2 valores a la vez.
Según su comentario si se necesita enviar 2 bytes seguidos debería insertar el bloque de inicio como me indica entre ambos valores.
(ver figura adjunta)

Veo que al después del ultimo delay se vuelve a poner el pin de control a 0= para inhabilitar la transmisión. Pero así ¿no se queda en modo recepción?
Justo al final del while me ha colocado un retardo de 50 segundos. ¿es necesario un valor tan alto?

Respecto al receptor:
Co respecto al pin de control me confundí, ya que cree una variable para ese fin, pero me falto inicializarla al valor correcto. Del resto del fichero me ha quedado bastante claro salvo una cuestión ¿aquí no seria necesario el colocar al final de la recepción el pin de control =1?

Perdón por mi ignorancia.
F.
Attachments
Sin título.png
(48.6 KiB) Downloaded 3576 times

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

Re: Flowcode y RS485

Post by LeighM »

Según su comentario si se necesita enviar 2 bytes seguidos debería insertar el bloque de inicio como me indica entre ambos valores.

According to your comment, if you need to send 2 bytes in a row, you should insert the start block as indicated between the two values.
No, you only need to do the Initialise once at the start of your program.
Veo que al después del ultimo delay se vuelve a poner el pin de control a 0= para inhabilitar la transmisión. Pero así ¿no se queda en modo recepción?
Justo al final del while me ha colocado un retardo de 50 segundos. ¿es necesario un valor tan alto?
Respecto al receptor:
Co respecto al pin de control me confundí, ya que cree una variable para ese fin, pero me falto inicializarla al valor correcto. Del resto del fichero me ha quedado bastante claro salvo una cuestión ¿aquí no seria necesario el colocar al final de la recepción el pin de control =1?

I see that after the last delay the control pin is reset to 0 = to disable transmission. But doesn't it stay in reception mode?
Just at the end of the while I placed a 50 second delay. Is such a high value necessary?

Regarding the receiver:
With respect to the control pin, I got confused, since I created a variable for that purpose, but I have to initialize it to the correct value. From the rest of the file it has been quite clear to me except for one question, would it not be necessary here to place the control pin = 1 at the end of the reception?
Regarding your 50 second delay - it depends how often you need to send the data, it's up to you.

The RE/DE pin is to be set low to receive and high to transmit.
The normal is for all attached devices to stay in receive mode until they need to transmit.
In your case, if one device only transmits and the other only receives, you could permanently set the direction for each end
(transmitter: RE/DE high, receiver RE/DE low)

Fer_taca
Posts: 91
Joined: Fri Oct 27, 2017 9:50 am
Has thanked: 13 times
Been thanked: 10 times
Contact:

Re: Flowcode y RS485

Post by Fer_taca »

LeighM,
Una vez más muchas gracias por su pronta respuesta. De la misma me ha quedado claro todos los conceptos que me ha explicado excepto una cosa ya que en un post anterior me indico lo siguiente:
If you are sending more than one value byte/character, you will need to send a "start" code to synchronise the receiver with the transmitter

Según esto y de acuerdo a mi ultima figura adjuntada me sobraría el bloque de reinicializar la comunicación y por tanto colocar los bloques (2 bytes) de la transmisión uno de tras de otro. Si es así no entiendo que código de "start" habría que colocar para sincronizar el receptor con el emisor en caso de enviar mas de un byte.

Pretendo entender bien el funcionamiento básico de esta comunicación, dado que la pretensión final es la de comunicar por medio del master el estado de una serie valores(pines y bytes A/D) al esclavo para que una vez recibidos los procese y actúe de acuerdo a los mismos. De la misma forma pasado un tiempo que sea el esclavo el que envíe otros datos al master para su procesamiento. este ultimo sería de forma cíclica.

F.

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

Re: Flowcode y RS485

Post by LeighM »

If sending more than one byte you need to think about creating a simple protocol.
Why? Because if you send value A, then value B, then repeat, if the receiver gets out of sync, say due to a missed character, then it would be receiving A as B, and B as A.
You might be better to convert the values to a numeric string, so for example if A = 22 and B = 33 then create and send a string with:
S,22,33
where it starts with an S and ends with CR/LF (carriage return/line feed)
If you look at an ASCII table you will see other characters such as STX and ETX which have historically been used to indicate start and end of text.

Alternatively, if you are always going to have a relatively long delay between the packets of data then you can ignore the above and just send the raw data bytes as you do now. But ensure that the receiver re-synchronises after detecting the delay gap. Such that it ignores the data if it does not get all bytes in the packet (currently just the two).

Fer_taca
Posts: 91
Joined: Fri Oct 27, 2017 9:50 am
Has thanked: 13 times
Been thanked: 10 times
Contact:

Re: Flowcode y RS485

Post by Fer_taca »

Muchas gracias nuevamente LeighM ,

Me ha quedado perfectamente claro la explicación dada.
Como lo que quiero es empezar e ir entendiendo como funciona el sistema. Inicialmente voy a empezar con retrasos grandes para comprobar la transmisión-recepción.
Según vaya avanzando y entendiendo el sistema, lo iré ampliando/modificando creando un protocolo bien definido para evitar la perdida de datos y/o recepción de datos incorrectos.

Pero, ¿hay que realizar algo especial para asegurar que el receptor vuelva a sincronizarse después del retraso?

F.

Post Reply