can_fd_data_bit_rate_set()

can_fd_data_bit_rate_set()

Description

Sets (or overrides) the CAN FD data-phase bit rate of an already-initialized interface. Has no effect unless the interface was initialized with CAN_CTRL_MODE_FD_BRS.

Syntax

can_fd_data_bit_rate_set(can_interface, can_bit_rate);

Parameters

Parameter

Description

can_interface

CAN interface to configure – CAN1 or CAN2.

can_bit_rate

FD data-phase bit rate, in bit/s (e.g. 2000000 for 2 Mbit/s).

Returns

Return value

Return explanation

SCRIPT_OPERATION_SUCCESS

The operation completed successfully.

SCRIPT_OPERATION_FAILED

The operation could not be completed (invalid state, hardware error, etc.).

SCRIPT_NO_ACCESS

The CAN interface has not been initialized (call can_fd_init first).

SCRIPT_PARAM_INVALID

One or more passed parameters are invalid.

Function call example

#include <io> #include <read> #include <float> #include <string> #include <core> #include <write> #include <define> #include <socket> #include <can> #define CAN_BUS CAN1 new can_rx_buffer{4096}; main() { can_fd_init(CAN_BUS, CAN_CTRL_MODE_NORMAL | CAN_CTRL_MODE_ONE_SHOT | CAN_CTRL_MODE_FD_BRS, 2000, 500000, can_rx_buffer); can_fd_data_bit_rate_set(CAN_BUS, 2000000); for(;;) { Delay(1000); } }

Notes and Warnings

  • The value is in bit/s, not kbit/s – unlike the data_bit_rate parameter of can_fd_init, which is in kbit/s. Passing 2000 instead of 2000000 configures a 2 kbit/s data phase instead of the intended 2 Mbit/s.