CANbeSerial

The CANbeSerial protocol was designed to allow the transportation of CAN-Bus frames on any serial stream interface. Possible interfaces include, but are not limited to, Serial Port (RS-232), TCP, and UDP.

Key Features

Motivation

While looking for a affordable CAN-FD to USB or Ethernet interface, I noticed the limitations of current solutions.

Terminology

Host The computer
Device The interface (microcontroller)
Frame Unit of data on the data link layer.
Packet Unit of data on the protocol layer.
Message Unit of data on the bus (application layer).

Requirement Levels

Requirement levels are denoted in accordance with RFC2119.

Data Link Layer

Framing

The framing is based on the "Consistent Overhead Byte Stuffing" (COBS) algorithm.

Each frame starts and ends with the NULL (0h) delimiter byte.

Data Link Layer (Frame)
Start Byte
(NULL)
Overhead Byte Payload Id Payload CRC16
(High Byte)
CRC16
(Low Byte)
End Byte
(NULL)
Protocol Layer (Packet)

CRC

The CRC16 uses an x16 + x12 + x5 + 1 polynomial (0x1021) initialized to 0xFFFF.

The CRC calculation includes the data contained in a network layer packet, namely the payload id and the payload bytes. The start-byte and stop-byte as well as the overhead-byte are not included in the CRC calculation.

Maximum Frame Lenght

The payload of a frame shall never exceed 74 bytes. In combination with the leading and trailing NULL, the COBS byte, Payload Id and CRC the maximum total frame length is 80 Bytes.

Implementation Guideline

Each message shall start with a NULL byte and end with a NULL byte.

The receiving end shall buffer incoming data and process it when NULL is received.

The receiving stack should be reinitialized after every NULL.

Timing-based framing, frame timeouts or other time-based actions are strongly discouraged.

Network Layer

Each packet contains a payload id and a payload.

Protocol Layer (Packet)
Payload Id Payload

Payload Ids

Id Name Desciption Reply
0x00 Data Bus Data Acknowledgmen or Error
0x01 Error Bus Error -
0x02 Acknowledgmen Transmit Acknowledgmen -
0x08 Protocol Version The CANbeSerial protocol version -
0x88 Protocol Version Request Request the CANbeSerial protocol version Protocol Version
0x09 Configuration State Contains the configuration of the device -
0x89 Configuration Request Request the configuration of the device Configuration State
0xC9 Configuration Command Sets configuration for the device -
0x0A Device Information Contains a string that describes the vendor and version of the device -
0x8A Device Information Request Request the device information Device Information

Payload Id 0x00 - Data

Data packets can be sent and received from anf by the device.

Data packet

Byte 0 1 2 3 4 5 6 7 8 9 n
Data Timestap (MSB) Timestap Timestap Timestap (LSB) CAN Identifier (MSB) CAN Identifier CAN Identifier CAN Identifier (LSB) CAN Control Field Reserved Data
Timestap

The timstamp is a 32 bit integer provided by the CAN-Bus pheripherel.

Note: The device will ignore the timstamp.

CAN Control Field

Bit 7 6 5 4 3 2 2 0
Discription Data Length Code Bit Rate Switching Flexible Data Rate Remote Transmission Request Extended

Payload Id 0x01 - Error

Error are reported as a single byte error code.

Error packets are either transmitted as a response to a received packet or asynchronously, based on a bus error.

Error Codes

Code Name Desciption
0x00 No Error "No Error" is reserved for internal use in the software. It sould not be used as an error code.
0x01 CRC The frame CRC was incorrect.
0x02 Not Enabled A data package was received while the device is not enabled.
0x03 Tx Buffer Full The transmit buffer of the device is full, and the data message was discarded.
0x04 Tx Frame Mal-Formatted The received data frame was was invalide.
0x05 Tx Frame DLC Length Mismatch The length of the frame does not match the data length code (DLC).
0x06 Unknown Payload Id An unknown payload id was received.
0x07 Unsupported Payload Id An unsupported, but known, payload id was received.
0x08 Data DLC The data length code (DLC) was invalide.
0x09 CAN RX The CAN interface reported a RX-Error
0x0A CAN TX The CAN interface reported a TX-Error
0x0B Configuration State Command An invalie "Configuration State Command" was received.

Payload Id 0x02 - Acknowledgmen

An acknowledgment packat is sent after a message is sucsessfully transmitted on the BUS.

Payload Id 0x08 - Protocol Version

The protocol version is reported as a single byte, denoting the numeric version of the protocol (1-255).

Payload Id 0x88 - Protocol Version Request

This command will trigger a "Protocol Version" packet from the device.

Payload Id 0x09 - Configuration State

Byte 0 1 2 3
Data Settings Byte Reserved Baudrate FD Baudrate

Settings Byte

Bit 7 6 5 4 3 2 2 0
Discription Reserved Silent Mode Automatic Retransmission Enabled Submissive
Submissive

In submissive state, the device configuration can not be changed and all "Configuration Command" packets will be ignored.

This state is applicable to application specific interfaces, where the settings are pre-configured.

Enabled

This bit is set when the CAN peripheral is enabled.

Note: While disabled, the peripheral must be completely silent on the bus, including not perform CAN-Bus acknowledgments.

Automatic Retransmission

While automatic retransmission is enabled, CAN message will be automatically retransmitted until successfully acknowledge.

Silent Mode

While in silent mode, the device will receive, but not transmit on the CAN-Bus, including CAN-Bus acknowledgments.

Baud Rate Codes

Code Baud Rate
0x00 10k
0x01 20k
0x02 50k
0x03 100k
0x04 125k
0x05 250k
0x06 500k
0x07 1M
0x08 2M
0x09 5M
0x0A 10M

Payload Id 0x89 - Configuration Request

This command will trigger a "Configuration State" packet from the device.

Payload Id 0xC9 - Configuration Command

The "Configuration Command" uses the same packet format as the "Configuration State".

Payload Id 0x0A - Device Information

The device information is reported as an ASCII-string.

Note: The string is not NULL terminated. The string lenght is definde by the packet lenght.

Payload Id 0x8A - Device Information Request

This command will trigger a "Device Information" packet from the device.

Payload Id 0x0B - Device Status

Payload Id 0x8B - Device Status Request

This command will trigger a "Device Status" packet from the device.