CAN - Controller Area Network

CAN Protocol and Bus

Intro: CAN Bus: Serial Communication - How It Works?

Another intro: Learn How The CAN Bus Works (Controller Area Network) | Embedded Systems Explained

Wikipedia: CAN bus

CAN 2.0 (Classical) vs CAN FD: Can 2.0 Vs. Can Fd: The Evolution of Controller Area Network

More details on CAN FD: CAN FD

Components

These are just examples

CAN transceiver (CANH/L to CAN TX/RX): SN65HVD230 CAN Board
CAN controller (CANH/L to SPI TX/RX): Arduino MCP2515 CAN Bus Interface Tutorial

STM32 CAN Bus

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

DroneCAN

ArduPilot DroneCAN Setup

CAN Bus: CAN Bus Setup — Copter documentation

DroneCAN: DroneCAN Setup — Copter documentation

ESCs: DroneCAN ESCs — Copter documentation

Servos: DroneCAN Servos — Plane documentation

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:
https://www.microchip.com/en-us/development-tool/apgdt002

Microchip CAN BUS Analyzer User’s Guide

2. Software Tools

PCAN-View (Peak System) - Free

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

  • https://kvaser.com/canlib-webhelp/

CANalyzer (Vector Informatik) - Paid

SocketCAN (Linux) - Free

How to decode CAN Data

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

https://www.youtube.com/watch?v=jvYkFr96Nss

https://www.csselectronics.com/pages/can-dbc-file-database-intro#:~:text=A%20CAN%20DBC%20file%20(CAN,data%20to%20

How to create DBC files:

General DBC file overview & creation: https://www.youtube.com/watch?v=Xnno4wTsi8Q

Good for sensors: https://www.youtube.com/watch?v=mAL1Xo2G9-4

Decent: https://www.youtube.com/watch?v=4USUH5chqnI

How is Pixhawk encoding the PWM Data

CAN with Pixhawk: https://docs.px4.io/main/en/can/

PX4 DroneCAN Firmware: https://docs.px4.io/main/en/dronecan/px4_cannode_fw.html
DroneCAN info & Configuration: https://docs.px4.io/main/en/dronecan/

DroneCAN Frame Format

 

DroneCAN: https://dronecan.github.io/Specification/4.1_CAN_bus_transport_layer/#:~:text=DroneCAN%20uses%20only%20CAN%202.0,(11%2Dbit%20identifiers).

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