This documentation is out of date.

The new version of the documentation is here: https://cannylogic.com/docs

Difference between revisions of "CANNY 7, UART Driver"

From CANNY Wiki
Jump to: navigation, search
[unchecked revision][unchecked revision]
(Driver registers)
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
=== General description ===
 
=== General description ===
 
  
 
Two of eleven IO channels (#9 and #10) CANNY 7 supports '''[https://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter UART]''', '''[https://en.wikipedia.org/wiki/RS-232 RS-232]''' serial protocols data transmission/reception. It  may be used to connect the controllers with each other or with external equipment supporting this communications protocols. The channels may be activated independently of each other and have individual data speed setting, protocol type and configuration, pull up line.
 
Two of eleven IO channels (#9 and #10) CANNY 7 supports '''[https://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter UART]''', '''[https://en.wikipedia.org/wiki/RS-232 RS-232]''' serial protocols data transmission/reception. It  may be used to connect the controllers with each other or with external equipment supporting this communications protocols. The channels may be activated independently of each other and have individual data speed setting, protocol type and configuration, pull up line.
Line 9: Line 8:
 
'''[https://en.wikipedia.org/wiki/RS-232 RS-232]''' implementation by using both  '''[https://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter UART]''' data channels , allows to exchange data with other '''[https://en.wikipedia.org/wiki/RS-232 RS-232]''' device in a duplex mode, i.e. one channel to perform data sending and on the other to simultaneously receive data.
 
'''[https://en.wikipedia.org/wiki/RS-232 RS-232]''' implementation by using both  '''[https://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter UART]''' data channels , allows to exchange data with other '''[https://en.wikipedia.org/wiki/RS-232 RS-232]''' device in a duplex mode, i.e. one channel to perform data sending and on the other to simultaneously receive data.
  
'''[https://en.wikipedia.org/wiki/Modbus Modbus]''' protocol in CANNY7 controllers implemented as over '''[https://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter UART]''' as over '''[https://en.wikipedia.org/wiki/RS-232 RS-232]'''. As ADU (Application Data Unit) used compact binary option Modbus RTU. Checking the data integrity carried out by automatically calculated checksum (CRC). Package size is limited to 16 bytes including the CRC.
+
'''[https://en.wikipedia.org/wiki/Modbus Modbus]''' protocol in CANNY7 controllers implemented as over '''[https://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter UART]''' as over '''[https://en.wikipedia.org/wiki/RS-232 RS-232]'''. As ADU (Application Data Unit) used compact binary option Modbus RTU. Checking the data integrity carried out by automatically calculated checksum (CRC). Package size is limited to 32 bytes including the CRC.
  
 
{|
 
{|
Line 30: Line 29:
 
{|border="1" style="border-collapse:collapse;" align="left" width="100%"
 
{|border="1" style="border-collapse:collapse;" align="left" width="100%"
 
|- align="center" valign="top"
 
|- align="center" valign="top"
!width="250px"|Address
+
!width="250px"|Register
 
!Expected values
 
!Expected values
 
|- valign="top"
 
|- valign="top"
|
+
|style="padding-left:0.5em;"|UARTx Mode Setup Register
{|border="0" align="left"
+
|- valign="top"
+
|style="padding-left:0.5em;"|UART1 Mode Setup Register
+
|- valign="top"
+
|style="padding-left:0.5em;"|UART2 Mode Setup Register
+
|}
+
 
|valign="top"|
 
|valign="top"|
 
{|border="0" align="left"
 
{|border="0" align="left"
 
|- valign="top"
 
|- valign="top"
|width="70px" style="padding-left:0.5em;"|1...65535
+
|width="70px" style="padding-left:0.5em;"|1...N
 
|style="padding-left:0.5em;"|=
 
|style="padding-left:0.5em;"|=
 
|style="padding-left:0.5em;"|set controller channel configuration, which determines current operation mode and parameters (given the special constant from the constants directory);
 
|style="padding-left:0.5em;"|set controller channel configuration, which determines current operation mode and parameters (given the special constant from the constants directory);
Line 49: Line 42:
 
|width="70px" style="padding-left:0.5em;"|0
 
|width="70px" style="padding-left:0.5em;"|0
 
|style="padding-left:0.5em;"|=
 
|style="padding-left:0.5em;"|=
|style="padding-left:0.5em;"|disconnect the channel from UART driver, return channel control to IO channels driver and allow status changing from the functional diagram.
+
|style="padding-left:0.5em;"|disconnect the channel from UARTx driver, return channel control to IO channels driver and allow status changing from the functional diagram.
 
|}
 
|}
 
|- valign="top"
 
|- valign="top"
|
+
|style="padding-left:0.5em;"|UARTx Receive Timeout Setup Register, bits
{|border="0" align="left"
+
|- valign="top"
+
|style="padding-left:0.5em;"|UART1 Receive Timeout Setup Register, bits
+
|- valign="top"
+
|style="padding-left:0.5em;"|UART2 Receive Timeout Setup Register, bits
+
|}
+
 
|
 
|
 
{|border="0" align="left"
 
{|border="0" align="left"
Line 64: Line 51:
 
|width="70px" style="padding-left:0.5em;"|1...65535
 
|width="70px" style="padding-left:0.5em;"|1...65535
 
|style="padding-left:0.5em;"|=
 
|style="padding-left:0.5em;"|=
|style="padding-left:0.5em;"|stop data reception, if during the time for which a specified number of data bits can be recd, line was not recorded any potential change and the line is in the passive state.;
+
|style="padding-left:0.5em;"|stop data reception, if during the time for which a specified number of data bits can be recd, line was not recorded any potential change and the line is in the passive state;
 
|- valign="top"
 
|- valign="top"
 
|width="70px" style="padding-left:0.5em;"|0
 
|width="70px" style="padding-left:0.5em;"|0
Line 103: Line 90:
 
Named constants that represent UART configuration parameters combination, available to the user in the "UART / RS-232 modes" CannyLab constants directory, which can be accessed via function block entry context menu having "constant" type.
 
Named constants that represent UART configuration parameters combination, available to the user in the "UART / RS-232 modes" CannyLab constants directory, which can be accessed via function block entry context menu having "constant" type.
  
UART / RS-232 / Modbus driver diagnostic registers.
+
UART / RS-232 / Modbus Diagnostic Registers.
 
{|border="1" style="border-collapse:collapse;" align="left" width="100%"
 
{|border="1" style="border-collapse:collapse;" align="left" width="100%"
 
|- align="center" valign="top"
 
|- align="center" valign="top"
!width="250px"|Address
+
!width="250px"|Register
 
!Return values
 
!Return values
 
|- valign="top"
 
|- valign="top"
|
+
|style="padding-left:0.5em;"|UARTx Overflow Register
{|border="0" align="left"
+
|- valign="top"
+
|style="padding-left:0.5em;"|UART1 Overflow Register
+
|- valign="top"
+
|style="padding-left:0.5em;"|UART2 Overflow Register
+
|}
+
 
|valign="top"|
 
|valign="top"|
 
{|border="0" align="left"
 
{|border="0" align="left"
Line 128: Line 109:
 
|}
 
|}
 
|- valign="top"
 
|- valign="top"
|
+
|style="padding-left:0.5em;"|UARTx Receive Error Register
{|border="0" align="left"
+
|- valign="top"
+
|style="padding-left:0.5em;"|UART1 Receive Error Register
+
|- valign="top"
+
|style="padding-left:0.5em;"|UART2 Receive Error Register
+
|}
+
 
|
 
|
 
{|border="0" align="left"
 
{|border="0" align="left"
Line 147: Line 122:
 
|}
 
|}
 
|- valign="top"
 
|- valign="top"
|
+
|style="padding-left:0.5em;"|UARTx Ready To Send Register
{|border="0" align="left"
+
|- valign="top"
+
|style="padding-left:0.5em;"|UART1 Ready To Send Register
+
|- valign="top"
+
|style="padding-left:0.5em;"|UART2 Ready To Send Register
+
|}
+
 
|
 
|
 
{|border="0" align="left"
 
{|border="0" align="left"
Line 167: Line 136:
 
|}
 
|}
  
UART / RS-232 / Modbus driver receive registers.
+
UART / RS-232 / Modbus Receive Registers.
 
{|border="1" style="border-collapse:collapse;" align="left" width="100%"
 
{|border="1" style="border-collapse:collapse;" align="left" width="100%"
 
|- align="center" valign="top"
 
|- align="center" valign="top"
!width="250px"|Адрес
+
!width="250px"|Register
!Возвращаемые значения
+
!Expected values
 
|- valign="top"
 
|- valign="top"
|
+
|style="padding-left:0.5em;"|UARTx Data Set Ready Register
{|border="0" align="left"
+
|- valign="top"
+
|style="padding-left:0.5em;"|UART1 Data Set Ready Register
+
|- valign="top"
+
|style="padding-left:0.5em;"|UART2 Data Set Ready Register
+
|}
+
 
|valign="top"|
 
|valign="top"|
 
{|border="0" align="left"
 
{|border="0" align="left"
Line 192: Line 155:
 
|}
 
|}
 
|- valign="top"
 
|- valign="top"
|
+
|style="padding-left:0.5em;"|UARTx RTU Received Register
{|border="0" align="left"
+
|- valign="top"
+
|style="padding-left:0.5em;"|UART1 RTU Received Register
+
|- valign="top"
+
|style="padding-left:0.5em;"|UART2 RTU Received Register
+
|}
+
 
|
 
|
 
{|border="0" align="left"
 
{|border="0" align="left"
Line 211: Line 168:
 
|}
 
|}
 
|- valign="top"
 
|- valign="top"
|
+
|style="padding-left:0.5em;"|UARTx Idle Register
{|border="0" align="left"
+
|- valign="top"
+
|style="padding-left:0.5em;"|UART1 Idle Register
+
|- valign="top"
+
|style="padding-left:0.5em;"|UART2 Idle Register
+
|}
+
 
|
 
|
 
{|border="0" align="left"
 
{|border="0" align="left"
Line 230: Line 181:
 
|}
 
|}
 
|- valign="top"
 
|- valign="top"
 +
|style="padding-left:0.5em;"|UARTx Received Data Length Register
 
|
 
|
 
{|border="0" align="left"
 
{|border="0" align="left"
 
|- valign="top"
 
|- valign="top"
|style="padding-left:0.5em;"|UART1 Received Data Length Register
+
|width="70px" style="padding-left:0.5em;"|0...32
|- valign="top"
+
|style="padding-left:0.5em;"|UART2 Received Data Length Register
+
|}
+
|
+
{|border="0" align="left"
+
|- valign="top"
+
|width="70px" style="padding-left:0.5em;"|0...16
+
 
|style="padding-left:0.5em;"|=
 
|style="padding-left:0.5em;"|=
 
|style="padding-left:0.5em;"|a value, equal to the number of data bytes in the packet received via respective UART channel..
 
|style="padding-left:0.5em;"|a value, equal to the number of data bytes in the packet received via respective UART channel..
Line 248: Line 193:
 
{|border="0" align="left"
 
{|border="0" align="left"
 
|- valign="top"
 
|- valign="top"
|style="padding-left:0.5em;"|UART1 Received Data Register b1:b0
+
|style="padding-left:0.5em;"|UARTx Received Data Register D1:D0
 
|- valign="top"
 
|- valign="top"
 
|style="padding-left:0.5em;"|...
 
|style="padding-left:0.5em;"|...
 
|- valign="top"
 
|- valign="top"
|style="padding-left:0.5em;"|UART1 Received Data Register b15:b14
+
|style="padding-left:0.5em;"|UARTx Received Data Register D31:D30
|- valign="top"
+
|style="padding-left:0.5em;"|UART2 Received Data Register b1:b0
+
|- valign="top"
+
|style="padding-left:0.5em;"|...
+
|- valign="top"
+
|style="padding-left:0.5em;"|UART2 Received Data Register b15:b14
+
 
|}
 
|}
 
|
 
|
 
{|border="0" align="left"
 
{|border="0" align="left"
 
|- valign="top"
 
|- valign="top"
|width="70px" style="padding-left:0.5em;"|0...65535
+
|width="70px" style="padding-left:0.5em;"|0...0xFFFF
 
|style="padding-left:0.5em;"|=
 
|style="padding-left:0.5em;"|=
 
|style="padding-left:0.5em;"|respective data byte values, UART reception buffers of each channel by two bytes to the register.
 
|style="padding-left:0.5em;"|respective data byte values, UART reception buffers of each channel by two bytes to the register.
Line 269: Line 208:
 
|}
 
|}
  
Регистры передачи драйвера UART / RS-232 / Modbus.
+
UART / RS-232 / Modbus Transmit Registers.
 
{|border="1" style="border-collapse:collapse;" align="left" width="100%"
 
{|border="1" style="border-collapse:collapse;" align="left" width="100%"
 
|- align="center" valign="top"
 
|- align="center" valign="top"
!width="250px"|Адрес
+
!width="250px"|Register
!Ожидаемые значения
+
!Expected values
 
|- valign="top"
 
|- valign="top"
|
+
|style="padding-left:0.5em;"|UARTx Request To Send Register
{|border="0" align="left"
+
|- valign="top"
+
|style="padding-left:0.5em;"|Регистр начала передачи UART1
+
|- valign="top"
+
|style="padding-left:0.5em;"|Регистр начала передачи UART2
+
|}
+
 
|valign="top"|
 
|valign="top"|
 
{|border="0" align="left"
 
{|border="0" align="left"
 
|- valign="top"
 
|- valign="top"
|width="70px" style="padding-left:0.5em;"|1
+
|width="70px" style="padding-left:0.5em;"|≥ 1
 
|style="padding-left:0.5em;"|=
 
|style="padding-left:0.5em;"|=
 
|style="padding-left:0.5em;"|to load data from the transfer registers in the respective channel UART transmit buffer;
 
|style="padding-left:0.5em;"|to load data from the transfer registers in the respective channel UART transmit buffer;
Line 294: Line 227:
 
|}
 
|}
 
|- valign="top"
 
|- valign="top"
 +
|style="padding-left:0.5em;"|UARTx RTU Transmit Register
 
|
 
|
 
{|border="0" align="left"
 
{|border="0" align="left"
 
|- valign="top"
 
|- valign="top"
|style="padding-left:0.5em;"|Регистр признака RTU буфера передачи данных UART1
+
|width="70px" style="padding-left:0.5em;"|≥ 1
|- valign="top"
+
|style="padding-left:0.5em;"|Регистр признака RTU буфера передачи данных UART2
+
|}
+
|
+
{|border="0" align="left"
+
|- valign="top"
+
|width="70px" style="padding-left:0.5em;"|1
+
 
|style="padding-left:0.5em;"|=
 
|style="padding-left:0.5em;"|=
|style="padding-left:0.5em;"|команда драйверу дописать к сообщению в буфере передачи соответствующего канала драйвера UART контрольную сумму в формате Modbus RTU, сформировав для отправки пакет данных в соответствии с протоколом Modbus RTU;
+
|style="padding-left:0.5em;"|a command to the driver, to add to the message in the appropriate channel of UART driver's transmit buffer, the checksum in the Modbus RTU format, to form a data packet, to send in accordance with Modbus RTU protocol;
 
|- valign="top"
 
|- valign="top"
 
|width="70px" style="padding-left:0.5em;"|0
 
|width="70px" style="padding-left:0.5em;"|0
 
|style="padding-left:0.5em;"|=
 
|style="padding-left:0.5em;"|=
|style="padding-left:0.5em;"|передавать данные буфера передачи соответствующего канала драйвера «как есть».
+
|style="padding-left:0.5em;"|transmit data from the corresponding channel driver buffer "as is".
 
|}
 
|}
 
|- valign="top"
 
|- valign="top"
 +
|style="padding-left:0.5em;"|UARTx Transmit Data Length Register
 
|
 
|
 
{|border="0" align="left"
 
{|border="0" align="left"
 
|- valign="top"
 
|- valign="top"
|style="padding-left:0.5em;"|Регистр длины сообщения передачи UART1
+
|width="70px" style="padding-left:0.5em;"|0...32
|- valign="top"
+
|style="padding-left:0.5em;"|Регистр длины сообщения передачи UART2
+
|}
+
|
+
{|border="0" align="left"
+
|- valign="top"
+
|width="70px" style="padding-left:0.5em;"|0...16
+
 
|style="padding-left:0.5em;"|=
 
|style="padding-left:0.5em;"|=
|style="padding-left:0.5em;"|количество байт данных, которое будет необходимо передать в линию, при получении команды на отправку соответствующего канала драйвера UART.
+
|style="padding-left:0.5em;"|the number of data bytes that will be transmitted to the line, when receiving a command to send on the corresponding channel of UART driver.
 
|}
 
|}
 
|- valign="top"
 
|- valign="top"
Line 331: Line 252:
 
{|border="0" align="left"
 
{|border="0" align="left"
 
|- valign="top"
 
|- valign="top"
|style="padding-left:0.5em;"|Регистр сообщения передачи UART1 b1:b0
+
|style="padding-left:0.5em;"|UARTx Transmit Data Register D1:D0
 
|- valign="top"
 
|- valign="top"
 
|style="padding-left:0.5em;"|...
 
|style="padding-left:0.5em;"|...
 
|- valign="top"
 
|- valign="top"
|style="padding-left:0.5em;"|Регистр сообщения передачи UART1 b15:b14
+
|style="padding-left:0.5em;"|UARTx Transmit Data Register D31:D30
|- valign="top"
+
|style="padding-left:0.5em;"|Регистр сообщения передачи UART2 b1:b0
+
|- valign="top"
+
|style="padding-left:0.5em;"|...
+
|- valign="top"
+
|style="padding-left:0.5em;"|Регистр сообщения передачи UART2 b15:b14
+
 
|}
 
|}
 
|
 
|
 
{|border="0" align="left"
 
{|border="0" align="left"
 
|- valign="top"
 
|- valign="top"
|width="70px" style="padding-left:0.5em;"|0...65535
+
|width="70px" style="padding-left:0.5em;"|0...0xFFFF
 
|style="padding-left:0.5em;"|=
 
|style="padding-left:0.5em;"|=
|style="padding-left:0.5em;"|значения соответствующих байт данных для передачи по соответствующему каналу драйвера UART, по два байта на регистр.
+
|style="padding-left:0.5em;"|values of the respective data bytes for transmission via respective UART driver channel, two bytes to the register.
 
|}
 
|}
 
|}
 
|}
 
<br clear="all">
 
<br clear="all">
  
=== Работа контроллера в режиме UART ===
+
=== Controller operation in UART mode ===
  
Работая в режиме UART контроллер может осуществлять полудуплексный прием/передачу данных по одному проводу.
+
Operating in UART mode, the controller can perform half-duplex data transmission/reception on a single wire.
  
Пример функциональной диаграммы для получения данных по UART.
+
An example of a functional diagram for receiving data by UART.
  
 
[[File:6_8_3_1.png|center]]
 
[[File:6_8_3_1.png|center]]
  
Пример функциональной диаграммы для передачи данных по UART.
+
An example of a functional diagram for transmitting data by UART.
  
 
[[File:6_8_3_2.png|center]]
 
[[File:6_8_3_2.png|center]]
Line 367: Line 282:
  
 
{|
 
{|
|valign="top" style="padding-left:0.5em;"|''Примечание:''
+
|valign="top" style="padding-left:0.5em;"|''Note:''
|valign="top" style="padding-left:0.5em;"|''Особое внимание следует обратить на то, что для избежания коллизий, при отправке данных, необходимо строго контролировать регистр готовности буфера передачи данных канала UART: если буфер не готов, значит в данный момент драйвером выполняется прием данных — отправка данных должна быть отложена.''
+
|valign="top" style="padding-left:0.5em;"|''Particular attention should be paid to the fact that in order to avoid collisions while sending data, it is necessary to strictly control UART channel data ready to send buffer: if the buffer is not ready, then at the moment the driver is receiving data, sending data should be postponed.''
 
|}
 
|}
  
=== Работа контроллера в режиме RS-232 ===
+
=== Controller operation in RS-232 mode ===
  
Работая по протоколу RS-232 контроллер может использовать каждый их своих каналов передачи данных только в симплексном (однонаправленном) режиме. При использовании сразу обоих каналов UART, которые работают независимо друг от друга, возможно организовать дуплексный режим обмена информацией по двум проводам: один канал — только прием, второй — только передача.
+
Operating on the RS-232 protocol controller can use each of its data transfer channels only in simplex (unidirectional) mode. When using both UART channels, which operates independently of each other, it is possible to organize a full-duplex mode of data transmission via two wires: one channel - only reception, the second - the only transmission.
  
Пример функциональной диаграммы для работы с RS-232. Получая данные по каналу UART2, при условии, что значение полученных байтов b1:b0 равно «0хAAAA», контроллер отправляет, по каналу UART1, 2 байта данных, содержащих значение «0xBBBB».
+
An example of a functional diagram working with RS-232. Receiving data through UART2, provided that the value of bytes D1: D0 is "0xAAAA", the controller sends, via UART1, 2 bytes of data containing the value «0xBBBB».
  
 
[[File:6_8_4_1.png|center]]
 
[[File:6_8_4_1.png|center]]
  
=== Реализация Modbus RTU ===
+
=== Modbus RTU implementation ===
  
Драйвер UART/RS-232 включает в себя функционал автоматического формирования и проверки контрольной суммы по стандарту Modbus RTU, что упрощает включение контроллера в сеть работающую по данному протоколу. Управлять формированием контрольной суммы передаваемых сообщений и её проверкой при приёме можно через соответствующие регистры драйвера.
+
UART/RS-232 driver includes functionality automatically create and verify the checksum using the Modbus RTU standard, which simplifies controller inclusion to the network operating under this protocol. Manage checksum formation for messages to be transmitted and its verification at reception is possible through the appropriate driver registers.
  
 
{|
 
{|
|valign="top" style="padding-left:0.5em;"|''Примечание:''
+
|valign="top" style="padding-left:0.5em;"|''Note:''
|valign="top" style="padding-left:0.5em;"|''При работе в режиме Modbus регистр чтения длины UARTx содержит значение с учетом принятых байт контрольной суммы (CRC), т. е. на 2 байта больше чем длина полезной нагрузки сообщения. При отправке пакета Modbus значение регистра установки длины сообщения UARTx также должно быть увеличено на 2 байта для возможности размещения и пересылки CRC.''
+
|valign="top" style="padding-left:0.5em;"|''When operating in Modbus mode, UARTx received data length register, contains the value concidering received checksum byte (CRC), those 2 bytes greater than the length of the payload of the message. When sending a Modbus packet, UARTx transmit data length register value must also be increased by 2 bytes to accommodate and transfer CRC.''
 
|}
 
|}
  
Пример функциональной диаграммы работы контроллера в режиме MASTER-узла Modbus поверх RS-232. Выполняя диаграмму, контроллер периодически отправляет SLAVE-узлу с адресом 0х20 запрос на получение от него значения из Modbus-регистра данных с адресом 0х0001. Получение ответа на свой запрос MASTER сопровождает коротким включением своего зеленого светодиода.
+
An example of a functional diagram of controller operating in Modbus MASTER-node mode over RS-232. Performing the diagram, the controller periodically sends to SLAVE-node with address 0x20 a request to receive from it the value of the Modbus-data register with address 0x0001. Getting an answer to its request, the MASTER accompanies with short blinking of green LED.
  
 
[[File:6_8_5_1.png|center]]
 
[[File:6_8_5_1.png|center]]
  
Строка запроса, при обмене данными между устройствами, будет выглядеть так:
+
A query string, when communicating between these devices will look like:
 
-> '''20 03 00 01 00 01 D3 7B'''
 
-> '''20 03 00 01 00 01 D3 7B'''
  
Адрес опрашиваемого устройства: 0x20 (байт b0 регистра приема сообщения UART2 b1:b0).
+
Polled device address: 0x20 (D0 byte of UART2 receive data register D1:D0).
  
Функция: 0x03 - чтение значений из нескольких регистров хранения (байт b1 регистра приема сообщения UART2 b1:b0).
+
Function: 0x03 - reading values from multiple holding registers (D1 byte of  UART2 receive data register D1:D0).
  
Номер первого запрашиваемого регистра: 0x0001 (байты b2 и b3 регистра приема сообщения UART2 b3:b2).
+
Number of the first requested register: 0x0001 (D2 and D3 bytes of UART2 receive data register D3:D2).
  
Число запрашиваемых регистров: 0x0001 (байты b4 и b5 регистра приема сообщения UART2 b5:b4).
+
Number of requested registers: 0x0001 (D4 and D5 bytes of UART2 receive data register D5:D4).
  
Контрольная сумма: 0xD37B (байты b6 и b7 регистра приема сообщения UART2 b7:b6 добавляются драйвером автоматически).
+
Check sum: 0xD37B (D6 and D7 bytes of UART2 receive data register D7:D6 driver adds automatically).
  
  
Пример функциональной диаграммы работы контроллера в качестве SLAVE-узла Modbus поверх RS-232. Получая от MASTERа запрос на передачу данных, контроллер в ответ передает состояние запрошенного регистра. Контроллер передает 2 байта данных (+2 байта CRC), т.к. регистры Modbus имеют разрядность 16 бит.
+
An example of a functional diagram of controller operating in Modbus SLAVE-node mode over RS-232. Receiving a request for data transmission from MASTER, the controller sends back the requested register state. Controller transmits 2 byte of data (+2 CRC bytes), as Modbus registers are 16 bits.
  
 
[[File:6_8_5_2.png|center]]
 
[[File:6_8_5_2.png|center]]
  
Строка ответа, при обмене данными между устройствами, будет выглядеть так:
+
A response string, during data exchange between the devices will look like:
  
 
<- '''20 03 02 00 10 C6 A0'''
 
<- '''20 03 02 00 10 C6 A0'''
  
Адрес отвечающего устройства: 0x20 (байт b0 регистра сообщения передачи UART1 b1:b0).
+
Responding device address: 0x20 (D0 byte of UART1 transmit data register D1:D0).
  
Функция: 0x03 - результат чтения значений из нескольких регистров хранения (байт b1 регистра сообщения передачи UART1 b1:b0).
+
Function: 0x03 - the result of reading the values from several holding registers (D1 byte of UART1 transmit data register D1:D0).
  
Число возвращаемых байт: 0x02 (байт b2 регистра сообщения передачи UART1 b3:b2).
+
The number of returned bytes: 0x02 (D2 byte of UART1 transmit data register D3:D2).
  
Значение старшего байта запрашиваемого регистра: 0x00 (байт b3 регистра сообщения передачи UART1 b3:b2).
+
The value of the high byte of the requested register: 0x00 (D3 byte of UART1 transmit data register D3:D2).
  
Значение младшего байта запрашиваемого регистра: 0x10 (байт b4 регистра сообщения передачи UART1 b5:b4).
+
The value of the least significant bit of the requested register: 0x10 (D4 byte of UART1 transmit data register D5:D4).
  
Контрольная сумма: 0xC6A0 (байт b5 регистра приема сообщения UART1 b5:b4 и байт b6 регистра приема сообщения UART1 b7:b6 соответственно добавляются драйвером автоматически).
+
Check sum: 0xC6A0 (D5 byte of UART1 transmit data register D5:D4 and D6 byte of UART1 transmit data register D7:D6 respectively driver adds automatically).
  
== Смотри также ==
+
== See also ==
 
[[CANNY 7]]
 
[[CANNY 7]]
  
 
[[CANNY 7, LIN Driver]]
 
[[CANNY 7, LIN Driver]]

Latest revision as of 18:46, 28 August 2019

General description

Two of eleven IO channels (#9 and #10) CANNY 7 supports UART, RS-232 serial protocols data transmission/reception. It may be used to connect the controllers with each other or with external equipment supporting this communications protocols. The channels may be activated independently of each other and have individual data speed setting, protocol type and configuration, pull up line.

UART implementation in CANNY 7 controllers allows to organize serial data reception and transmission over a single wire in half-duplex mode. Thus CANNY7 may have two independent connections using the UART protocol. Monitoring of the data link status should be done from the functional diagram. If the channel is free, the device may start data transmitting , otherwise the device should wait for the line release.

RS-232 implementation by using both UART data channels , allows to exchange data with other RS-232 device in a duplex mode, i.e. one channel to perform data sending and on the other to simultaneously receive data.

Modbus protocol in CANNY7 controllers implemented as over UART as over RS-232. As ADU (Application Data Unit) used compact binary option Modbus RTU. Checking the data integrity carried out by automatically calculated checksum (CRC). Package size is limited to 32 bytes including the CRC.

Note: For correct operation of all protocols based on the UART / RS-232 requires that all GND terminals of the devices committing communication, were given to a single potential ("common ground").
Note: In UART implementation-active line is the potential GND 100mA, passive - positive potential of a given internal or external channel pull-up. In implementing RS-232 - the potentials inverse.

Driver UART/RS-232/Modbus operates using controllers' channels resources, but has a higher priority than a discrete input-output driver. Thus, upon activation of UART/RS-232/Modbus driver, for channels involved in its operation, a value changes in registers associated with discrete input-output driver, will be ignored.

Driver registers

The following describes the acceptable and returnable values of the driver control operation registers.

UART / RS-232 / Modbus Driver Configuration Registers.

Register Expected values
UARTx Mode Setup Register
1...N = set controller channel configuration, which determines current operation mode and parameters (given the special constant from the constants directory);
0 = disconnect the channel from UARTx driver, return channel control to IO channels driver and allow status changing from the functional diagram.
UARTx Receive Timeout Setup Register, bits
1...65535 = stop data reception, if during the time for which a specified number of data bits can be recd, line was not recorded any potential change and the line is in the passive state;
0 = use the default value defined in channel (13) configuration.

UART driver configuration is determined by the constants that represent the combination of parameters that determine the speed, mode, additional date transmission parameters and line potential in the passive mode.

Parameter Acceptable values
The data rate, bps 110; 150; 300; 600; 1200; 1800; 2400; 4800; 9600; 19200; 38400; 57600
Mode UART; RS-232
Pull-up in UART mode plus; air
The transfer direction in RS-232 mode receive; transmit
Data bits 8; 9
parity N (no) ; O (odd) ; E (even)
Number of stop bits 1; 2

Named constants that represent UART configuration parameters combination, available to the user in the "UART / RS-232 modes" CannyLab constants directory, which can be accessed via function block entry context menu having "constant" type.

UART / RS-232 / Modbus Diagnostic Registers.

Register Return values
UARTx Overflow Register
1 = UART buffer is full;
0 = No overflow detected.
UARTx Receive Error Register
1 = during UART data reception an error occurred;
0 = the driver is operating normally.
UARTx Ready To Send Register
1 = UART driver data transmit buffer is free;
0 = UART driver data transmit buffer is busy, data transmission not possible.

UART / RS-232 / Modbus Receive Registers.

Register Expected values
UARTx Data Set Ready Register
1 = the message is received and placed into corresponding UART channel receive buffer;
0 = in the corresponding UART driver channel receive buffer no actual data present.
UARTx RTU Received Register
1 = received a message on the appropriate channel UART is correct Modbus RTU message, the checksum is correct;
0 = received a message on the appropriate channel UART is incorrect Modbus RTU message.
UARTx Idle Register
1 = no activity on the corresponding channel UART drivers, the line is in a passive mode;
0 = fixed activity on the line of corresponding channel UART driver.
UARTx Received Data Length Register
0...32 = a value, equal to the number of data bytes in the packet received via respective UART channel..
UARTx Received Data Register D1:D0
...
UARTx Received Data Register D31:D30
0...0xFFFF = respective data byte values, UART reception buffers of each channel by two bytes to the register.

UART / RS-232 / Modbus Transmit Registers.

Register Expected values
UARTx Request To Send Register
≥ 1 = to load data from the transfer registers in the respective channel UART transmit buffer;
0 = do not load data to the respective channel UART transmit buffer.
UARTx RTU Transmit Register
≥ 1 = a command to the driver, to add to the message in the appropriate channel of UART driver's transmit buffer, the checksum in the Modbus RTU format, to form a data packet, to send in accordance with Modbus RTU protocol;
0 = transmit data from the corresponding channel driver buffer "as is".
UARTx Transmit Data Length Register
0...32 = the number of data bytes that will be transmitted to the line, when receiving a command to send on the corresponding channel of UART driver.
UARTx Transmit Data Register D1:D0
...
UARTx Transmit Data Register D31:D30
0...0xFFFF = values of the respective data bytes for transmission via respective UART driver channel, two bytes to the register.


Controller operation in UART mode

Operating in UART mode, the controller can perform half-duplex data transmission/reception on a single wire.

An example of a functional diagram for receiving data by UART.

6 8 3 1.png

An example of a functional diagram for transmitting data by UART.

6 8 3 2.png


Note: Particular attention should be paid to the fact that in order to avoid collisions while sending data, it is necessary to strictly control UART channel data ready to send buffer: if the buffer is not ready, then at the moment the driver is receiving data, sending data should be postponed.

Controller operation in RS-232 mode

Operating on the RS-232 protocol controller can use each of its data transfer channels only in simplex (unidirectional) mode. When using both UART channels, which operates independently of each other, it is possible to organize a full-duplex mode of data transmission via two wires: one channel - only reception, the second - the only transmission.

An example of a functional diagram working with RS-232. Receiving data through UART2, provided that the value of bytes D1: D0 is "0xAAAA", the controller sends, via UART1, 2 bytes of data containing the value «0xBBBB».

6 8 4 1.png

Modbus RTU implementation

UART/RS-232 driver includes functionality automatically create and verify the checksum using the Modbus RTU standard, which simplifies controller inclusion to the network operating under this protocol. Manage checksum formation for messages to be transmitted and its verification at reception is possible through the appropriate driver registers.

Note: When operating in Modbus mode, UARTx received data length register, contains the value concidering received checksum byte (CRC), those 2 bytes greater than the length of the payload of the message. When sending a Modbus packet, UARTx transmit data length register value must also be increased by 2 bytes to accommodate and transfer CRC.

An example of a functional diagram of controller operating in Modbus MASTER-node mode over RS-232. Performing the diagram, the controller periodically sends to SLAVE-node with address 0x20 a request to receive from it the value of the Modbus-data register with address 0x0001. Getting an answer to its request, the MASTER accompanies with short blinking of green LED.

6 8 5 1.png

A query string, when communicating between these devices will look like: -> 20 03 00 01 00 01 D3 7B

Polled device address: 0x20 (D0 byte of UART2 receive data register D1:D0).

Function: 0x03 - reading values from multiple holding registers (D1 byte of UART2 receive data register D1:D0).

Number of the first requested register: 0x0001 (D2 and D3 bytes of UART2 receive data register D3:D2).

Number of requested registers: 0x0001 (D4 and D5 bytes of UART2 receive data register D5:D4).

Check sum: 0xD37B (D6 and D7 bytes of UART2 receive data register D7:D6 — driver adds automatically).


An example of a functional diagram of controller operating in Modbus SLAVE-node mode over RS-232. Receiving a request for data transmission from MASTER, the controller sends back the requested register state. Controller transmits 2 byte of data (+2 CRC bytes), as Modbus registers are 16 bits.

6 8 5 2.png

A response string, during data exchange between the devices will look like:

<- 20 03 02 00 10 C6 A0

Responding device address: 0x20 (D0 byte of UART1 transmit data register D1:D0).

Function: 0x03 - the result of reading the values from several holding registers (D1 byte of UART1 transmit data register D1:D0).

The number of returned bytes: 0x02 (D2 byte of UART1 transmit data register D3:D2).

The value of the high byte of the requested register: 0x00 (D3 byte of UART1 transmit data register D3:D2).

The value of the least significant bit of the requested register: 0x10 (D4 byte of UART1 transmit data register D5:D4).

Check sum: 0xC6A0 (D5 byte of UART1 transmit data register D5:D4 and D6 byte of UART1 transmit data register D7:D6 respectively — driver adds automatically).

See also

CANNY 7

CANNY 7, LIN Driver