Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 12 Current »

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: https://medium.com/@dorlecontrols/can-2-0-vs-can-fd-the-evolution-of-controller-area-network-4994c9ef0116

More details on CAN FD: https://en.wikipedia.org/wiki/CAN_FD

Components

These are just examples

CAN transceiver (CANH/L to CAN TX/RX): https://www.waveshare.com/sn65hvd230-can-board.htm
CAN controller (CANH/L to SPI TX/RX): https://www.electronicshub.org/arduino-mcp2515-can-bus-tutorial/

STM32 CAN Bus

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

DroneCAN

https://dronecan.github.io/

ArduPilot DroneCAN Setup

CAN Bus: https://ardupilot.org/copter/docs/common-canbus-setup-advanced.html#common-canbus-setup-advanced

DroneCAN: https://ardupilot.org/copter/docs/common-uavcan-setup-advanced.html

ESCs: https://ardupilot.org/copter/docs/common-uavcan-escs.html

Servos: https://ardupilot.org/plane/docs/common-dronecan-servos.html

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:

Really basic, not suppperr useful: https://www.youtube.com/watch?v=QTx1g4opXPM

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

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).

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

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

  • No labels

0 Comments

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.