This documentation is out of date.

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

CANNY 7.2 duo, UART Driver

From CANNY Wiki
Revision as of 13:58, 15 August 2019 by Support (Talk | contribs) (Created page with "=== General description === At the same time, up to four of the nine CANNY 7.2 duo input-output channels can be used to organize '''[https://en.wikipedia.org/wiki/Universal_...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Jump to: navigation, search

General description

At the same time, up to four of the nine CANNY 7.2 duo input-output channels can be used to organize 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. Four UART interfaces capable of working in half-duplex mode, allows, if necessary, to organize on their basis two interfaces operating in full-duplex mode.

Size of receive and transmit buffers for each of the interfaces of the UART CANNY 7.2 duo driver is 64 bytes.

UART implementation in CANNY 7.2 duo controllers allows to organize serial data reception and transmission over a single wire in half-duplex mode. Thus CANNY 7.2 duo may have four 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 using any two UART data channels allows to exchange data with another RS-232 device in duplex mode, i.e. one channel for sending data, and the other for receiving data simultaneously. Thus, using UART channels in pairs, it is possible to simultaneously organize two independent RS-232 connections operating in duplex mode.

Modbus protocol in CANNY 7.2 duo 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 64 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...255 = 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.
UARTx IO Channel Select Register
0...8 = transferring the specified input-output channel under the control of the UARTx driver; use the specified input-output channel to work with the corresponding UARTx interface.

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 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 = UARTx buffer is full;
0 = No overflow detected.
UARTx Receive Error Register
1 = during UARTx data reception an error occurred;
0 = the driver is operating normally.
UARTx Ready To Send Register
1 = UARTx driver data transmit buffer is free;
0 = UARTx 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 UARTx channel receive buffer;
0 = in the corresponding UARTx 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 Received Data Length Register
0...64 = 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 D63:D62
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 UARTx transmit buffer;
0 = do not load data to the respective channel UARTx transmit buffer.
UARTx RTU Transmit Register
≥ 1 = a command to the driver, to add to the message in the appropriate channel of UARTx 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...64 = the number of data bytes that will be transmitted to the line, when receiving a command to send on the corresponding channel of UARTx driver.
UARTx Transmit Data Register D1:D0
...
UARTx Transmit Data Register D63:D62
0...0xFFFF = values of the respective data bytes for transmission via respective UARTx 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 UART communication. The controller, having received a message of 2 bytes in length via the UART1 interface, saves them in the corresponding named network for further processing, and on the next cycle of the diagram execution sends 2 prepared bytes of data back.

17 7 3 1.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 UARTx 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».

17 7 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.

17 7 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.

17 7 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.2 duo

CANNY 7.2 duo, LIN Driver