User Tools

Site Tools


projects:pafront:rs485bus:comunication:comunication

Comunication (Komunikation)

Hardware base for the communication to the microcontroller at PA-Terminal is as mentioned the RS485-Bus, a serial bus. That is a serial communication that is extended from standard RS232 in two major points: While RS232 (serial com-Port for PCs) is a one to one connection with limited distance range, RS485 is at first point a bus: several particpants can join the bus. Second point ist the extended range of RS485, that might reach 1,6km (relate to data rate).

Comunication parameter:
Standard: RS485
mode: Halfduplex (2 wire)
Data rate: 9600Baud (ca. 100µS/Bit)
Databits: 8
Stopbits: 1
Parity: non
Control: Software
Package length: fix, 7 Byte
Several actors in place a one bus has to follow a special structure, because otherwise data collions migth ocoure like with a one way rail with two trains running in opposite direction towards each other or like in a confernce with several participants talking at the same time. PLC at one end acts as master and the PA-Terminals normaly listens as slaves. The sreens below demonstrate this communication: First channel there (Blue) shows the data flow on line, channel 4 (magenta) the internal sign for ongoing communication, channel 2 (red) an internal signal for the points of data sampling.
Hardware-Basis für die Komuniktion mit dem Microcontroller ist wie beschrieben der RS485 Standard, ein serieller Bus. Während die vom com-Port des PCs bekannte RS232-Schnittstelle nur eine eins-zu-eins Verbindung darstellt, ist der RS485-Standard in zwei wesendlichen Punkten ausgebaut: Es ist ein Bus an den mehrere Teilnehmer angeschlossen werden können und ausserdem können bis zu 1,6km Enfernung erreicht werden (Datenrate abhängig).

Kommunikationsparameter:
Standard: RS485
Modus: Halbduplex (2 Draht)
Datenrate: 9600Baud (ca. 100µS/Bit)
Datenbits: 8
Stopbits: 1
Parität: non
Flußsteuerung: Software
Telegrammlänge: fest, 7 Byte

Da hier ein Bus mit mehreren Teilnehmern eingesetzt wird muß eine feste Struktur eingehalten werden, da es sonst die gleichen Probleme gibt wie in einer Konferenz wo alle zur gleichen Zeit reden oder im Eingleisbahnverkehr, wenn sich zwei Züge frontal begegnen. Die SPS-Einheit an einem Ende (Master) hat die Hoheit, die Teilnehmer (Slaves) reagieren nur. Der Screenshot unten demonstriert dies Kommunikation: Dabei ist Kanal 1 (blau) der Verkehr auf der differentiellen Datenleitung, Kanal 4 (pink) das PA-Terminal interne Signal für einen aktiven Kommunikationsprozess, Kanal 2 (rot) ebenfalls intern, ein Hilfssignal für die Tastzeitpunkte.
Master-Slave-Kommunikation
Serial comunication between two independend partners have to be synchroniliazed allways at the distant ends of line: this has to be established via Start- and Stop Bit, which surrounds the eight data bits. Positiv half of the RS485-Bus differentiel signal (blue trace top left graph) will lead a positiv level if there is calm on the line and negativ half an inverted negativ one. A positiv differential signal about +200mV is then seen as a locical “1” and a negativ differenial signal below -200mV as an logical “0”. Values inside interval between this limits are forbidden and are present only for very slow transition times.
Therfore, in case calm ont the line, a logic “1” is be present on differential bus as well as an espially a high on positiv half. A command is given only by the communication master, that is the PLC-unit. He will start communication with a start bit, logic “0” and thereby a falling edge at positive signal branche. Slaves on the bus will listen to that and stopp imeadiately programm flow: they change in the communication part of internal software. All slaves synchronize to that falling edge. Master will then, after first start bit, put first data bit on the line which is taken after the time of one start bit and a half of a bit in the middle of first data bit. Following seven databits will be taken in periodes of ca. 100µs. End of first complete comamand byte will be then a stop bit as an logical “1”. Theoretically that could be followed by a pause, but real next byte with its it's start bit follows.
Command of master (7 Bytes) is adressed to a certain slave if a respond of that is requested. Only that slave respons with although exact 7 bytes. Non addressed slaves are switched taub for that time to avoid them understanding one slaves respond as master command. On the other hand master will release line after his command free to listen to slaves respond. On right top graphic different RS485 levels can be observed: those a related to master or slave driving the line. Different to RS232 communication with only two participants and short connections, data flow control has to be achieved via software control (protocoll): additional handshake signals as in last mentioned standard are not in place.
Further details according commands will be found in the describtion of software: Commands!
Bei einer seriellen Kommunikation müßen generell zwei autarke Teilnehmer an beiden Enden synchronisiert werden: das geschieht über das Start- und das Stobit, welche die 8 Datenbits umfaßen. Wenn Ruhe auf der Leitung herrscht, dann hat der positive Signalzweig des differentillen RS485-Buses (Blaue Spur) einen positiven Pegel und der negative Zweig einen entsprechend invertierten, negativen Pegel. Ist die Differenz größer als 200mV und positiv ist der Wert eine logische “1”, wenn die Differenz negativ kleiner als -200mV ist dies eine logische “0”. Werte im Intervall dazwischen sind verboten und werden nur bei Wechseln für nur sehr kurze Zeiten durchschritten.
Im Ruhezustand liegt also eine “1” auf der Leitung (und dem positiven Zweig). Ein Befehl geht dann vom Master, der SPS Einheit aus, alle Teilnehmer lauschen: Der Master sendet ein Startbit, das ist eine “0”, was also eine fallende Flanke im pos. Zweig bedeutet. Dies erkennen die Teilnehmer: d.h. per Interruped wird aus dem laufenden Programm in eine Komunikationsroutine gesprungen, alle Teilnehmer synchronisieren sich. Nach dem Startbit stellt dann der Master das erste Datenbit auf die Leitung, die Teilnehmer tasten nach 1 1/2 Bits, also nach dem Startbit und in der Mitte des ersten Datenbits ab und dann in der Periode von ca. 100µS die sieben folgenden Bits auf der Leitung. Das Ende der ersten Bytes im 10. Takt ist dann ein Stobit “1”. Dem könnte theoretisch eine Pause folgen, praktisch wird hier direkt das nächste Byte mit seinem Startbit hinterher geschoben.
Das Komando des Masters ist adressiert, wenn die Antwort eines bestimmten Teilnehmers erwartet wird. Nur dieser Teilnehmer antwortet mit ebenfalls genau 7 Byte. Damit nicht angesprochene Teilnehmer die Antwort des anderen nicht als evtl. Befehl des Masters hören, sind also alle Slaves für diese Zeit “taub” geschaltet. Dagegen schaltet natürlich der Master nach seinem Kommando auf Lauschen um die Antwort des Teilnehmers zu hören. Man sieht übrigen auf der Leitung unterschiedlich hohe Pegel von Sender und Empfänger, da ja auch verschiedene Treiber dann auf der einen oder anderen Seite aktiv sind. Anders als bei der RS232 Standard, mit nur zwei Teilnehmern und kurzem Kabel, muß die Datenflußsteuerung hier über Software (Protokoll) ausgeführt werden: zusätzliche Handschake-Signale wie im erwähnten Bus sind nicht vorhanden.
Weitere Details zu den verwendeten Befehlen findet man in der Beschreibung der Software: Instruktionen
projects/pafront/rs485bus/comunication/comunication.txt · Last modified: 2014/11/27 06:57 by carsten