CANNY 5.3 Pico. CAN Driver

General Description

Two dedicated external outputs of CANNY 5.3 Pico controller, contact 1 (CAN-L) and contact 7 (CAN-H), provided for connection to digital information CAN-bus.

Driver’s registers

Below is a description of valid values for registers controlling CAN-bus driver operation.

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

CAN driver configuration registers.
Register Expected values
CAN Mode Setup Register 1…N = activates the driver and sets CAN-message transmit/receive speed (defined by a named constant from the constants directory);
0 = disable the driver.
CAN Acceptance Filter
Identifier Register IDL 0

CAN 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)
CAN Acceptance Filter
Identifier Register IDH 0

CAN 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)
CAN Listen Only Mode Enable Register ≥ 1 = enable CAN message listen only reception mode;
0 = enable normal CAN message reception and transmission mode.
CAN Acceptance Filter Enable Register ≥ 1 = enable CAN filtering mode for reception;
0 = disable CAN filtering mode for reception.
CAN Transmitting Cancel On Error Register ≥ 1 = cancel CAN transmitting on error;
0 = do not CAN transmitting cancel on error.

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 transmission/reception speed, kbit/s 20; 33.3; 50; 83; 95.2; 100; 125; 250; 500; 800; 1000

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

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
CAN Idle Register 1 = CAN driver activity is absent, the bus is idle, data reception is not performed;
0 = CAN activity registered.
CAN Overflow Register 1 = error, CAN receive buffer is full;
0 = no overflow of the receive buffer.
CAN Error Register 1 = CAN reception error rate exceeds an acceptable threshold;
0 = CAN reception error rate is below an acceptable threshold.
CAN Ready To Send Register 1 = CAN driver data transmit buffer is empty and ready to send new messages;
0 = CAN driver data transmit buffer is not ready.

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

CAN driver receive registers.
Register Return values
CAN Data Set Ready Register 1 = CAN driver receive buffer received a message. This value appears in the register for one loop of diagram execution, denoting that the buffer constains new data;
0 = there is no new data in the CAN driver receive buffer.
CAN Received Data Register IDL 0…0xFFFF = value of the lower part of the identifier of the received CAN-message
CAN Received Data Register IDH 0…0x1FFF = value of the upper part of the identifier of the received CAN-message
CAN Received Data Register ERL 0…0xXX08 = value equal to the number of bytes of data in the received message, where 0хXX is: 0x00 (for standard format), 0x40 (for standard format with RTR), 0x80 (for extended format) or 0xC0 (for extended format with RTR). See note for more information.
CAN Received Data Register
CAN D1:D0

CAN D7:D6
0…0xFFFF = values of corresponding data bytes received in the CAN message, 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 transmit registers.
Register Expected values
CAN Request To Send Register ≥ 1 = load data from the transmit registers into the CAN driver transmission buffer;
0 = do not load data into the CAN driver transmission buffer.
CAN Transmit Data Register IDL 0…0xFFFF = value of the lower part of the identifier of the CAN-message being transmitted
CAN Transmit Data Register IDH 0…0x1FFF = value of the upper part of the identifier of the CAN-message being transmitted
CAN 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).
CAN Transmit Data Register
D1:D0

CAN Transmit Data Register
D7:D6
0…0xFFFF = values of the corresponding data bytes of the CAN message being transmitted, 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.

Examples

Transmit examples

Transmit example 1
Transmit example 1.

While the diagram is being executed, the transmits to the bus at a speed of 125 kbps every 100 ms. The data being transmitted is the state of its three inputs. A standard format message is used with the identifier 0x123. It contains a single byte of data.

Transmit example 2

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

Transmit example 2.
Transmit example 3

This function diagram sends a CAN message with an extended identifier: “0x1f110001: 0xDE 0xAD 0xBE 0xEF 0x12 0x34 0x56 0x78”. It does so when a signal appears on channel #8 of the controller.

Differences between sending an extended format message and sending a standard one: set bit 15 of the register [CAN Transmit Data Register ERL], the leading part of the identifier should be written into the register [CAN Transmit Data Register IDH].

Transmit example 3.
Transmit example 4

This function diagram sends a CAN message with the standard identifier: “0x001: 0xDE 0xAD 0xBE 0xEF 0x12 0x34 0x56 0x78” when a signal appears on channel 8 of the controller. It also sends a message with the same ID, but zero data when the signal on channel #8 of the controller disappears.

Transmit example 4.
Transmit example 5. Sending messages periodically.
Transmit example 5.

Receive examples

Receive example 1

Executing the diagram, the controller receives a message from the bus in standard format with ID 0x0123. The message contains one byte of data. The diagram sets the status of three of its outputs, in accordance with the received value.

Receive example 1.
Receive example 2

Executing the diagram, the controller receives a message from the bus in standard format with an ID 0x01F3. It then analyzes a value contained in one of the message bytes and sets the states of the controller’s outputs and built-in LED according to the values.

Receive example 2.

SEE ALSO