CANNY 7.2 Duo. CAN Driver

General Description

CANNY 7.2 Duo controllers have two independent CAN interfaces. Two specialized external contacts, located on the 4-pin connector X1 (CAN0-H and CAN0-L of CAN0 interface) and on the 3-pin connector X3 (CAN1-H and CAN1-L of CAN1 interface), are provided for connection to digital information CAN-bus.

The CANNY 7.2 Duo controller CAN driver has 16 hardware filters for each of its CAN interfaces.

Interfaces CAN0 and CAN1 have individual settings and can operate at different data exchange rates, which allows you to connect CANNY 7.2 Duo controller to two different CAN buses simultaneously.

Driver registers

Below is a description of valid values for registers controlling CAN-bus driver operation, where x is the CAN interface number (0 or 1).

CAN driver configuration registers allow you to set the parameters of the controller for operating as a CAN bus node, on the specified CAN interface.

CAN driver configuration registers.
Register Expected values
CANx Mode Setup Register 1…N = activate the driver and set CAN-message transmit/receive speed of the specified CAN interface (defined by a named constant from the constants named constants list);
0 = disable the driver for the specified CAN interface.
CANx Acceptance Filter
Identifier Register IDL 0

CANx Acceptance Filter
Identifier Register IDL 15
0…0xFFFF = set filter value for the lower part of the CAN-message identifier(bits 0…10 for standard identifier format or bits 0…15 for expanded identifier format) on the specified interface
CANx Acceptance Filter
Identifier Register IDH 0

CANx Acceptance Filter
Identifier Register IDH 15
0…0x1FFF = set filter value for the upper part of the CAN-message identifier (bits 16…28 for expanded identifier format) on the specified interface
CANx Listen Only Mode Enable Register ≥ 1 = enable CAN message listen only reception mode for the specified CAN interface;
0 = enable normal CAN message reception and transmission mode for the specified CAN interface.
CANx Acceptance Filter Enable Register ≥ 1 = enable CAN filtering mode for reception on the specified CAN interface;
0 = disable CAN filtering mode for reception on the specified CAN interface.
CANx Transmitting Cancel On Error Register ≥ 1 = cancel CAN transmitting on error or NACK for specified CAN interface;
0 = do not cancel CAN transmitting when an error or NACK is detected for specified CAN interface.
CAN1 Transceiver Mode Setup Register 0…2 = the operation mode of the CAN1 interface transceiver is set using a named constant from the “CAN Transceiver Modes” section:
0 - “HS CAN Transceiver Mode” (high-speed CAN) - enabled by default, normal operation of the interface transceiver (>100kBaud);
1 - “FT CAN Transceiver Mode” (Fault Tolerance CAN) - hardware compatibility mode of the interface transceiver with FT CAN (usually 100kBaud);
2 - “SW CAN Transceiver Mode” (Single Wire CAN) - hardware compatibility mode of the transceiver interface with single-wire CAN, (usually it is 33kBaud).

Note: In listen-only mode, unlike normal CAN mode, the driver receives data from the CAN-bus, but does not send an acknowledgement signal when it receives data and does not put network into an error state when it detects an error. Thus, the controller remains invisible to other devices on the bus. For proper CAN network operation, at least two normal mode devices need to be present in the network.

Note: When filter mode is enabled the CAN driver only accepts those messages whose identifiers match values in the CAN message receive filter configuration registers. All other messages are ignored.

Note: When Transmitting Cancel on Error is enabled, the driver will only attempt to send a CAN message once, irrespective of whether it is received successfully or not. This prevents the CAN bus from hanging up when there is no recipient for the message. When this mode isdisabled, the driver will attempt to send the message until at is received by at least one recipient.

CAN driver configuration is defined by a constant predetermined data transmission/reception speed.

Data rate constant values.
Parameter List of permitted values
Data reception / transmission rate, kbit / s 20; 33.3; 50; 62.5; 83.3; 95.2; 100; 125; 250; 500; 666.6; 800; 1000

Named constants for CAN configuration parameters are available in the “CAN Modes” sub-folder of the CannyLab named constants list.

CAN driver diagnostic registers let you determine the status of the driver at any given moment during diagram execution.

CAN Driver Diagnostic Registers.
Register Return Values
CANx Idle Register 1 = CAN driver activity on the specified interface is absent, the bus is idle, data reception is not performed;
0 = CAN activity on the interface registered.
CANx Overflow Register 1 = error, CAN receive buffer of the specified interface is full;
0 = no overflow of the specified interface’s receive buffer.
CANx Error Register 1 = CAN reception error rate of the specified interface exceeds the acceptable threshold;
0 = CAN reception error rate of the specified interface below the acceptable threshold.
CANx Ready To Send Register 1 = CAN driver data transmit buffer of the specified interface is empty and ready to send new messages;
0 = CAN driver data transmit buffer of the specified interface is not ready.

CAN driver receive registers provide access to the values received through the CAN bus.

CAN driver receive registers.
Register Return Values
CANx Data Set Ready Register 1 = CAN driver receive buffer of the specified interface has received a message. This value appears in the register for one cycle of diagram execution and denotes that the buffer contains new data;
0 = there is no data in the CAN driver receive buffer of the specified interface.
CANx Received Data Register IDL 0…0xFFFF = value of the lower part of the identifier of the CAN message received on the specified interface
CANx Received Data Register IDH 0…0x1FFF = value of the upper part of the identifier of the CAN message received on the specified interface
CANx Received Data Register 0…0xXX08 = value equal to the number of data bytes in the received CAN message on the specified interface, where 0xXX is:
0x00 (with the standard format),
0x40 (with the standard format with RTR),
0x80 (with the extended format) or
0xС0 (with the extended format with RTR) (See note)
CANx Received Data Register
D1:D0

CANx D7:D6
0…0xFFFF = values of corresponding data bytes received in the CAN message on the interface, two bytes per register

Note: CAN Received Data Register ERL denotes the number of bytes in the received message in its least significant bits (bits 0..8). It also contains information about special message attributes in its most significant bits : bit 15 - EXT flag, bit 14 - RTR flag. EXT = 1, when a message is received in the extended format, EXT = 0 for the standard message format; RTR = 1 when a remote data request is received, RTR = 0 when a normal message is received.

CAN transmit registers are used to place data that you want to send into the transmission buffer.

CAN driver transmit registers.
Register Expected values
CANx Request To Send Register ≥ 1 = load data from the transfer registers into the CAN driver transmission buffer of the specified interface;
0 = do not load data into the CAN driver transmission buffer of the specified interface.
CANx Transmit Data Register IDL 0…0xFFFF = value of the lower part of the identifier of the CAN-message being transmitted on the specified interface
CANx Transmit Data Register IDH 0…0x1FFF = value of the upper part of the identifier of the CAN-message being transmitted on the specified interface
CANx Transmit Data Register ERL 0…0xXX08 = value equal to the number of data bytes in the transmitted CAN message on the specified interface, where 0xXX is:
0x00 (with the standard format),
0x40 (with the standard format with RTR),
0x80 (with the extended format) or
0xС0 (with the extended format with RTR) (See note)
CANx Transmit Data Register
D1:D0

CANx Transmit Data Register D7:D6
0…0xFFFF = values of the corresponding data bytes of the CAN message being transmitted on the specified interface, two bytes per register

Note: CAN Transmit Data Register ERL denotes the number of bytes in the received message in its least significant bits (bits 0..8). It also contains information about special message attributes in its most significant bits : bit 15 - EXT flag, bit 14 - RTR flag. EXT = 1, when a message is received in the extended format, EXT = 0 for the standard message format; RTR = 1 when a remote data request is received, RTR = 0 when a normal message is received.

Message transmission examples

Sending data to the CAN bus over the CAN0 interface

Function diagram for sending data to the CAN bus via interface CAN0.

The controller executes the diagram once every 100 ms. Each time it transmits ot the bus at a rate of 125 kbps. The data it transmits is the state of its three inputs. A standard format message containing a single byte of data with identifier 0x123 is used.

Sending a message with a standard identifier

This function diagram sends the CAN message “0x001: 0xDE 0xAD 0xBE 0xEF 0x12 0x34 0x56 0x78” with a standard identifier when a signal appears on IO channel 0.

An example of a function diagram for sending a CAN message with a standard identifier.

Sending a message with an extended identifier

This function diagram sends the CAN message “0x1f110001: 0xDE 0xAD 0xBE 0xEF 0x12 0x34 0x56 0x78” with an extended identifier when a signal appears on IO channel 0.

Note the differences between sending an extended message and sending a standard one. To send an extended message, set bit 15 of the register [CAN Transmit Data Register ERL], the leading part of the identifier should be written to the register [CAN Transmit Data Register IDH].

An example of a function diagram for sending a CAN message with an extended identifier.

Sending a message on signal state change

This diagram sends a CAN message “0x001: 0xDE 0xAD 0xBE 0xEF 0x12 0x34 0x56 0x78” with a standard identifier when a signal appears on IO channel 0. Additionally it sends a message with the same ID, but no data when the signal on channel 0 disappears.

Example of a function diagram for sending a CAN message on signal state change.

Sending several CAN messages periodically

An example of sending several CAN messages periodically.

Message reception examples

Receiving data from the CAN bus with indication of the state of the bits

This diagram receives a message containing one byte of data with ID 0x0123 from the CAN bus in standard format. It then sets three of its outputs in accordance with received value.

An example of a function diagram of the data receive from the CAN0.

Receiving data from the CAN bus with the analysis of one byte

This diagram receives a message with ID 0x01F3 in standard format. It then analyzes the value contained in one of the message bytes, sets on its outputs and changes the state of the built-in LED accordingly.

An example of a function diagram of the data receive from the CAN0.

Receiving data from the CAN bus with filtering mode

The controller, receiving extended format messages from the CAN bus, compares their identifiers with the values specified in the CAN message filter settings registers, and if they match, transfers their contents to the CAN receive registers for processing in the functional diagram. Messages whose identifiers do not match those specified in the filters are automatically discarded, which reduces the consumption of controller resources and increases the possibility of uninterrupted receipt of necessary messages.

An example of a function diagram of the data receive from the CAN0 with filtering mode.

SEE ALSO