CAN - Controller Area Network

CAN Protocol and Bus

Intro: https://www.youtube.com/watch?v=JZSCzRT9TTo

Another intro: https://www.youtube.com/watch?v=v_y65h68z3U

Wikipedia: https://en.wikipedia.org/wiki/CAN_bus

CAN 2.0 (Classical) vs CAN FD:

More details on CAN FD:

Components

These are just examples

CAN transceiver (CANH/L to CAN TX/RX):
CAN controller (CANH/L to SPI TX/RX):

STM32 CAN Bus

https://controllerstech.com/can-protocol-in-stm32/

DroneCAN

ArduPilot DroneCAN Setup

CAN Bus:

DroneCAN:

ESCs:

Servos:

Typos on ArduPilot Docs

The circled parameters should be CAN_D1_UC_SRV_BM

image-20240524-164623.png

 

How does CAN Transceiver Work? TxD/RxD

CAN Transceivers enable communication between the microcontroller and the CAN bus. They act as an interface, translating the digital data from the microcontroller into differential signals that can be sent over the CAN bus and vice versa.

TxD (Transmit Data):

  • The TxD pin is used by the microcontroller to send data to the CAN transceiver

  • The microcontroller outputs a serial data stream to the TxD pin of the transceiver

  • The transceiver then converts this data into differential signals (CAN_H and CAN_L) that are sent onto the CAN bus.

RxD (Receive Data):

  • The RxD pin is used by the CAN transceiver to send CAN bus data to the microcontroller

  • The transceiver converts the differential signals from the CAN bus into a single-ended digital signal

  • The data is then output from the RxD pin to the microcontroller

How do we get it?

How to debug CAN Data

1. Use a CAN Analyzer

A CAN analyzer or CAN bus sniffer can be used to monitor/analyze CAN traffic.

  • Connect the CAN analyzer to the CAN bus

  • Use the analyzer software to monitor the CAN messages, allowing you to see all the data being transmitted on the bus

Example:

Microchip CAN BUS Analyzer User’s Guide

2. Software Tools

PCAN-View (Peak System) - Free

  • Use Case: Monitoring and analyzing CAN traffic

  • How to Use:

    • Connect PCAN-USB adapter to CAN bus

    • Launch PCAN-View, set baud rate, and start monitoring

    • Apply filters, send messages, and log data for offline analysis

Kvaser CANlib (Kvaser) - Free SDK, but needs Kvaser hardware

  • Use Case: Developing custom CAN applications, monitoring, and analyzing traffic

  • How to Use:

    • Connect Kvaser hardware to CAN bus

    • Install CANlib SDK, use CANlib Visual for monitoring

    • Configure channels, send messages, and use scripting for automation

CANalyzer (Vector Informatik) - Paid

SocketCAN (Linux) - Free

  • Use Case: Open-source CAN interface for Linux with standard tools

  • How to Use:

    • Install can-utils and set up CAN interface

    • Use candump to monitor, cansend to send messages, and canplayer to replay logged traffic

How to decode CAN Data

Intro to using DBC files for manually decoding raw CAN data:

How to create DBC files:

General DBC file overview & creation:

Good for sensors:

Decent:

How is Pixhawk encoding the PWM Data

CAN with Pixhawk:

PX4 DroneCAN Firmware:
DroneCAN info & Configuration:

DroneCAN Frame Format

 

DroneCAN:

DroneCAN uses only CAN 2.0B frame format (29 bits)

Contents of CAN ID field depend on message type. There are three types of messages

Screen Shot 2024-05-29 at 10.29.19 PM.png

Actual data transferred is in the payload which consists of 2 parts. The transfer payload (holds the data we will convert to DShot/PWM) and the Tail Byte (contains auxiliary transport layer fields).

If the data being sent fits in a single CAN frame, then a single frame is used for payload transmission which is more efficient and thus more ideal. If the payload doesn’t fit in one data frame, a multi-frame transfer is required which introduces:

  • Transfer CRC

    • Error checking to ensure receiving payload matches original payload transmitted. Cannot verify data integrity/accuracy without the Transfer CRC

    • Computed from transfer payload, perpended with data type signature, little-endian order

  • Toggle Bit

    • Detect and avoid CAN frame duplicate errors

    • First frame toggle bit is 0, second frame toggle bit is 1, and alternates so on for each frame