CANNY 5.3 MD1A. CAN Driver
General Description
Two special external pins of the 4-pin connector of the CANNY 5.3 MD1A controller, CAN-H and CAN-L, are intended for connection to the digital information CAN-bus.
The CANNY 5.3 MD1A controller CAN driver has 16 hardware filters for each of its CAN interfaces.
Driver 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.
Register | Expected values |
---|---|
CAN Mode Setup Register | 1…N = activate the driver and set CAN-message transmit/receive speed (defined by a named constant from the constants named constants list); 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 or NACK; 0 = do not cancel CAN transmitting when an error or NACK is detected. |
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.
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.
Register | Return Values |
---|---|
CAN Idle Register | 1 = no CAN driver activity, 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 the acceptable threshold; 0 = CAN reception error rate below the 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.
Register | Return Values |
---|---|
CAN Data Set Ready Register | 1 = CAN driver receive buffer has received a message. This value appears in the register for one cycle of diagram execution and denotes that the buffer contains new actual data; 0 = there is no actual data in the CAN driver receive buffer. |
CAN Received Data Register IDL | 0…0xFFFF = value of the lower part of the identifier of the CAN message received |
CAN Received Data Register IDH | 0…0x1FFF = value of the upper part of the identifier of the CAN message received |
CAN Received Data Register ERL | 0…0xXX08 = value equal to the number of data bytes in the received CAN message, 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 Received Data Register D1:D0 … CAN Received Data Register 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.
Register | Expected values |
---|---|
CAN Request To Send Register | ≥ 1 = load data from the transfer 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, 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.
Message transmission examples
Sending data to the CAN bus
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 8.
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 8.
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].
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 8. Additionally it sends a message with the same ID, but no data when the signal on channel 0 disappears.
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.
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.
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.