CAN Adapter¶
The CAN Adapter connects the Superordinate Controller to the CAN bus over USB. It is the
USB-Serial CAN Bridge of stm32g0b1-evaluation-board, release demo-v1.1.0. This description
covers the part the Superordinate Controller uses; the
source
holds the complete specification.
Link¶
- USB CDC serial device, 115200 bps, 8N1
- CAN side: Classic CAN 2.0B at 1 Mbps; every frame is sent with a 29-bit (extended) identifier
- Automatic retransmission is disabled: a frame that fails on the bus is sent only once
Sending a Frame¶
The host writes one CAN Frame Line per frame:
msg_id: 1 to 8 hexadecimal digits, at most1FFFFFFFpayload_byte: 2 hexadecimal digits, 0 to 8 of them- At most 32 characters between
<and\n - Bytes before
<are discarded; a new<abandons an unterminated line
Example: DriveCommand (0, 0, 0) is <08200001:00 00 00 00 00 00\n.
The adapter queues up to 8 lines; when the queue is full, it rejects the new line.
Replies¶
Every reply is one line, terminated by \n.
| Starts with | Meaning | Example |
|---|---|---|
# |
Confirmation or error, as plain text | # CAN frame received via USB. Now forwarding on CAN. |
> |
CAN Frame received from the bus, zero-padded | >08200001:00 00 00 00 00 00 |
A valid line is confirmed once it is accepted for transmission. A malformed line, a full queue,
or a frame that fails on the bus is answered with an error line naming the cause, e.g.
# No other node acknowledged the CAN frame. when no other node is on the bus. The adapter sends
one frame at a time: if the outcome of a frame is not known within 50 ms, it aborts the frame,
answers # CAN transmission outcome timed out., and continues with the next line. A received
frame is announced by # CAN frame received via CAN. Now forwarding on USB. immediately before
its > line.
The adapter never blocks on the USB side: a reply the host does not take in time is dropped and counted.
Status Report¶
Every 5 s, the adapter sends a Status Report; after an error, it sends one at once, but at most once per second. Silence for longer than 5 s therefore means the adapter or its USB link has stopped.
# Status: uptime 5 s, lines 3, frames tx 3, tx errors 0, frames rx 0, rx lost 0, queue full 0, usb drops 0, last reset power-on.
| Field | Meaning |
|---|---|
uptime |
Seconds since the last start |
lines |
CAN Frame Lines taken from the queue |
frames tx |
Frames submitted for transmission |
tx errors |
Frames that failed on the bus or timed out |
frames rx |
Frames received from the bus |
rx lost |
Received frames lost on reception |
queue full |
Lines rejected because the queue was full |
usb drops |
Replies dropped because the host did not take them |
last reset |
Cause of the last start: power-on, reset pin, watchdog, or software |
The counters start at 0 on every start and wrap around at 2^32. A watchdog restarts the adapter when it stops making progress for 500 ms; the host then sees the USB device disappear and reappear.