Skip to content
Benjamin Vernoux edited this page Mar 16, 2024 · 18 revisions

HydraFW Bus CAN (Controller Area Network)

This guide is updated towards firmware release HydraFW v0.11 and later

Bus: CAN
Connections: two pins (RX/TX) and ground.
Output types: 3.3volt normal output, or open drain
(pull-up/pull-down resistors integrated in MCU or external).
Pull-up resistors: required for open collector output mode (2K – 10K).
Maximum Voltage: 5.5volts (5volt safe).

For hardware shield supported see https://github.com/smillier/HydraLINCAN

Protocol configuration syntax description:

  • show Show CAN parameters or show pins Show pins used in this mode

  • device with parameter 1 or 2 to choose CAN device (1 or 2)

  • speed with integer bitrate value (support k, m suffix or no suffix)

    • speed up to 2Mb/s
  • id with value specifies the frame identifier to be set

  • ts1 with value specifies the Time sequence 1 value

  • ts2 with value specifies the Time sequence 2 value

  • sjw with value specifies the resynchronization jump width value

  • filter Add a filter (see below)

  • slcan switch to LAWICEL/SLCAN mode

  • exit to exit CAN mode

Note default value for device 1 or 2: 
For device 1 (CAN1):
> can device 1
Device: CAN1
Speed: 500000 bps


For device 2 (CAN2):
> can device 2
Device: CAN2
Speed: 500000 bps

Configuration options:

Filters

Since 32d53fccb5352b246aea4d71cf46990a83b7bc16, it is possible to use a mask filter.

The mask filter is a bitwise AND applied to a reference value. Every frame matching the mask will be captured by the CAN interface. All others will be dropped.

A filter can be set using the filter submenu.

  • on enables the current filter
  • off disables the current filter
  • id sets the value to be tested
  • mask sets the bitmask to be applied

The current filter values can be displayed using the show filter command.

Timing requirements

CAN bus operation depend on timing parameters which determine the accuracy of the bus sampling, but also when the node (Hydrabus) must send the ACK bit. Wrong settings in the timing parameters can lead to a bus malfunction and perturbate all other nodes on the bus.

To mitigate the impact on the bus, the CAN mode initially starts in silent mode, which allows to read frames but does not send ACK bit. As soon as the first frame must be sent, the controller is set to normal mode for the rest of the session.

To get more information about CAN bus timings, please see https://vector.com/portal/medien/cmc/application_notes/AN-AND-1-106_Basic_CAN_Bit_Timing.pdf

Hardware Informations:

can1> show pins 
TX: PB9
RX: PB8

can2> show pins 
TX: PB13
RX: PB12

Protocol interaction syntax description:

Bus interaction commands

For writing, all data is split by 8 bytes (max frame data size). for example, writing ten bytes will result in sending a frame with the first eight bytes and a second with the last two bytes.

hd command is not supported

SLCAN

Since da84d5085a6307558bb004a9232f140f6e7b05a7, it is also possible to write packets using the LAWICEL/SLCAN format :

txxxyzz... Send a standard CAN frame using xxx as ID, y as data length and zz as data

Txxxxxxxxyzz... Send a standard CAN frame using xxx as extended ID, y as data length and zz as data

rxxxyzz... Send a RTR CAN frame using xxx as ID, y as data length and zz as data

Rxxxxxxxxyzz... Send a RTR CAN frame using xxx as extended ID, y as data length and zz as data

Example :

t1230 Sends a standard CAN frame with 0x123 as ID and no data length

T12345678411223344 Sends a standard CAN frame with extended ID of 0x12345678, with 4 bytes of data of value 0x11223344

If the value cannot be interpreted as a valid LAWICEL command, the data will be sent as an ASCII string in CAN frames

Protocol interaction example usage CAN1 write:

TBD

Additional informations about CAN bus

To be used with a real CAN bus, a CAN transceiver must be used. See HydraLINCAN shield : https://github.com/smillier/HydraLINCAN

Before to select CAN Device to use (and init the CAN Bus) the CAN Bus shall be connected with the target CAN Bus else the init will returns bsp_can_init() error 3 which means HAL_TIMEOUT because no transceiver is connected or maybe there is a bus fault.

For more details on CAN bus see: https://en.wikipedia.org/wiki/CAN_bus

How to Flash/Use HydraFW

How to Build/Flash/Use HydraFW

Developer Getting-Started with HydraBus and STM32CubeIDE

Hardware

Firmware (hydrafw) performances

Firmware (hydrafw) Application guides

Firmware (hydrafw) guides

How to Help

Clone this wiki locally