Es que RS-485 / RS-422 / RS-232 son todos asincronos.. A que te referis con que el protocolo es sincrono?.
Si vas a comunicarte por RS-485 se crea un protocolo para eso, no al revés, me refiero que no creas un protocolo y obligas a la capa fisica.
En el mejor caso creas un protocolo que sea independiente de la capa fisica. Y sea esta ultima quien transmita/reciba como ella puede.
Realmente no creo que necesites ninguna libreria, si queres hacer uso de las PLIB podes hacerlo. Pero alguna libreria mas que esas serian unicamente tuyas, creadas para tu proposito.
En el caso del HDLC. Se me ocurren varias formas:
- Transmitirlo por un medio asincrono a todo el Frame ( Por que podes enviarlo por sincrono o asincrono el frame completo introduciendo unos flag, lee wikipedia)
- O podes crear el soft , es decir manejar bit a bit las salidas para crear el protocolo sincrono, ademas vas a tener que agregar un integrado para la parte fisica, el cual puede ser diferencial la linea de datos, etc.
- O podes comprarte un integrado que lo haga por si solo a todo, incluso el manejo del HDLC y con buffer.
El tema es el receptor o lo que esta del otro extremo, si usa sincrono no vas a poder usar asincrono ( por RS-485 como queres ). Si son 2 microcontroladores o mas los que intentas unir entonces procede a ir por el RS-485
| Flag | Address | Control | Information | FCS | Flag |
| 8 bits | 8 or more bits | 8 or 16 bits | Variable length, n * 8 bits | 16 or 32 bits | 8 bits |
el receptor esta todo el tiempo comprobando que le llegue el delimitador que índica el comienzo de trama.
Sincrono significa que ademas de los datos se envia el reloj. Asincrono no es necesario enviar una señal de clock ( reloj ).
RS-485 es asincrono y multipunto ( es decir podes colgar varios de este ). Podes tambien usar HDLC, es decir el frame:
Flag Address Control Information FCS Flag 8 bits 8 or more bits 8 or 16 bits Variable length, n * 8 bits 16 or 32 bits 8 bits Citarel receptor esta todo el tiempo comprobando que le llegue el delimitador que índica el comienzo de trama.
Cuando implementes el HDLC es decir la trama de arriba todos los receptores van a esperar el flag, cuando lo encuentra siguen recibiendo sabiendo que lo que sigue es la direccion, si ocurre que la direccion NO es la del receptor entonces descarta todo lo que llega hasta la flag que indica el final de la trama. Si el coincide las direcciones entonces acepta la trama y respondera o no segun tengas definido que va a hacer. ( Esto trae una pequeña limitante, que es que el valor que uses de flag no pueda estar entre los datos. a no ser que ademas de las 2 flags uses una "demora" entre paquete y paquete, o uses una flag + cantidad de bytes a transmitir. Todo esto con un timeout si o si, por si hay un corte en la linea.
Acordate que siempre hay un Maestro y un esclavo, es decir que tenes un micro principal que habilita a los demas a responder. Si queres que todos sean capaz de iniciar una transferencia es un multi-maestro y se complica mucho mas. Todo va a depender de lo que tengas que hacer obviamente.
Asynchronous framing[edit]
When using asynchronous serial communication such as standard RS-232 serial ports, bits are sent in groups of 8, and bit-stuffing is inconvenient. Instead they use "control-octet transparency", also called "byte stuffing" or "octet stuffing". The frame boundary octet is 01111110, (7E in hexadecimal notation). A "control escape octet", has the bit sequence '01111101', (7D hexadecimal). If either of these two octets appears in the transmitted data, an escape octet is sent, followed by the original data octet with bit 5 inverted. For example, the data sequence "01111110" (7E hex) would be transmitted as "01111101 01011110" ("7D 5E" hex). Other reserved octet values (such as XON or XOFF) can be escaped in the same way if necessary.
Synchronous framing[edit]
On synchronous links, this is done with bit stuffing. Any time that 5 consecutive 1-bits appear in the transmitted data, the data is paused and a 0-bit is transmitted. This ensures that no more than 5 consecutive 1-bits will be sent. The receiving device knows this is being done, and after seeing 5 1-bits in a row, a following 0-bit is stripped out of the received data. If, after 5 consecutive 1-bits, the following bit is also a 1-bit, the receiving device knows that either a flag has been found (if the sixth 1-bit is followed by a 0-bit) or an error has occurred (if the sixth 1-bit is followed by seventh 1-bit). In the latter case, the frame receive procedure, depending on state, is generally either aborted or restarted.
Todo por que dice que HDLC es un protocolo sincrono al comienzo y te quedaste encerrado en esto.
El protocolo es como es el mensaje enviado, es decir cada tipo de frame enviado ( cata tipo de mensaje ), cada campo como esta compuesto etc.
El frame como decia puede ser enviado tanto asincronamente como sincronamente.
Si es de forma asincrona entonces se usa esa flag al comienzo etc, pero el problema era que no podrias usar la flag esa dentro de los datos, entonces debes hacer esto :CitarAsynchronous framing[edit]
When using asynchronous serial communication such as standard RS-232 serial ports, bits are sent in groups of 8, and bit-stuffing is inconvenient. Instead they use "control-octet transparency", also called "byte stuffing" or "octet stuffing". The frame boundary octet is 01111110, (7E in hexadecimal notation). A "control escape octet", has the bit sequence '01111101', (7D hexadecimal). If either of these two octets appears in the transmitted data, an escape octet is sent, followed by the original data octet with bit 5 inverted. For example, the data sequence "01111110" (7E hex) would be transmitted as "01111101 01011110" ("7D 5E" hex). Other reserved octet values (such as XON or XOFF) can be escaped in the same way if necessary.
Ahora si lo haces sincrono no sirve eso, sino que a medida que envias 1 por 1 los bits y detectar que son iguales que la flag se agregan bits.CitarSynchronous framing[edit]
On synchronous links, this is done with bit stuffing. Any time that 5 consecutive 1-bits appear in the transmitted data, the data is paused and a 0-bit is transmitted. This ensures that no more than 5 consecutive 1-bits will be sent. The receiving device knows this is being done, and after seeing 5 1-bits in a row, a following 0-bit is stripped out of the received data. If, after 5 consecutive 1-bits, the following bit is also a 1-bit, the receiving device knows that either a flag has been found (if the sixth 1-bit is followed by a 0-bit) or an error has occurred (if the sixth 1-bit is followed by seventh 1-bit). In the latter case, the frame receive procedure, depending on state, is generally either aborted or restarted.
Es todo lo que te interesa a vos de asincrono o sincrono el HDLC.. No te encerres por lo que dice al comienzo con que es "sincrono" nomas.
El modo asincrono tambien es para full-duplex. tiene un buffer de recepcion y transmision por separado.
Asincrono. Recorda que :
Sincrono es "Datos + Reloj"
Si vas a usar solo 1 par de cables ( 1 diferencial ) entonces solo podes enviar datos, si quisieras hacer un half-duplex sincrono, deberias tener 4 cables ( 2 pares diferenciales datos y reloj ).
La ventaja del sincrono es que es mas rapido, pero tiene como desventaja tambien llevar la señal de reloj.
La ventaja del asincrono es que no es necesario llevar señal de reloj, lo cual necesita menos cables para lo mismo, pero a costa de un par de bits mas reduciendo la velocidad de transferencia.
Resumen:
En tu PIC, UART y Asincrono, vas a tener que manejar ademas los Enable de recepcion y transmisión, con 2 pines aparte.
Si llega correctamente entonces seguro que es un problema del programa del receptor.